Search code examples
linuxsqliterustarmrust-diesel

Rust Compilation dieselrs sqlite3 Generated-Colums


Background

I need to run a binary in an arm based computer(Jetson Nano) and i was compiling and running it without any problems until my team decided to use Generated Columns in sqlite3 a feature that was implemented in version 3.31.0 but the Ubuntu Image ran by said computer has a previous dev-version and results in the following crash using Dieselrs library

thread 'main' panicked at 'called `Result::unwrap()` on an 
`Err` value: DatabaseError(__Unknown, "malformed database schema 
(group) - near \"as\": syntax error")', src/common_queries.rs:182:35

(we handle the unwrap but i removed it in order to see the real message)

I know its a version problem since the message shown is similar to what its stated in the sqlite3 documentation

.... If an earlier version of SQLite attempts to read a 
database file that contains a generated column in its schema, 
then that earlier version will perceive the generated column syntax 
as an error and will report that the database schema is corrupt. 

and because in an x86 computer with sqlite3 version 3.34 works without a problem.

What has been tried

update libraries

I already tried downloading version 3.36 of SQLite from the official webpage and ran sudo make install but that didn't create the library in /usr/include but somehow it still compiles it and it still shows the same error. (maybe it knows where the new library is but its weird that despite that it still doesn't work).

Change db-schema

the simplest solution that i could come up with was to change the schema and store the generated column as a new column that would be generated with an after update trigger but that would mean that the database would no longer be in a Normal form.

Cross compilation

Since it works in an x86 machine I tried targeting the architecture, following different approaches that resulted in the following message

linking with `aarch64-linux-gnu-ld` failed: exit status: 1

....
....
....

aarch64-linux-gnu-ld: cannot find -lsqlite3
aarch64-linux-gnu-ld: cannot find -lgcc_s


which i guess comes from the fact that neither of them show up in /usr/aarch64-linux-gnu/include/ but installing libsqlite3-dev doesn't fix the issue.

Any ideas on how to fix this problem?


Solution

  • Try adding libsqlite3-sys = { version = "0.22.0", features = ["bundled"]} to your Cargo.toml. This forces libsqlite3 to be build from source for the correct target. This uses the latest version of sqlite. See the documentation of libsqlite3-sys for details.