I've been playing around with Rust recently, and I've been making a small todo list app (which is pretty much the 'Hello World' of the web world by now) based on this article.
Building on the tutorial, I decided to add persistance to the todo list by using an Sqlite database to save todo items between runs of the app. However, I ran into a few problems while getting Sqlite running with Rust on Windows, so this is a brief overview of the bug I ran into, along with how to work around the issue.
Adding Sqlite dependency
I downloaded Sqlite to C:/Program Files/sqlite3
and added that folder to my Path variable, so Sqlite was working on my machine and could run from the terminal.
Adding Sqlite to my project was simple enough - I googled 'rust sqlite' and a number of crates, the equivalent of NPM modules, came up; I chose to use 'rusqlite' since it seemed well-documented and had been around for a while. I updated my Cargo.toml
to add rusqlite
:
[dependencies]
rusqlite = "0.7.3"```
Simple enough! To install the dependencies, I ran cargo run
, which is where things started to break.
Usually cargo run
will download any dependencies missing from your project, compile everything and run the project. However, this time I got the following error:
```bash
Compiling libsqlite3-sys v0.5.0
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: JoinPathsError { inner: JoinPathsError }', ../src/libcore\result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `libsqlite3-sys`
```
Bugger.
Compiler bug
This problem looked like I wouldn't be able to use Sqlite in my project - I'd either have to wait until the compiler bug was fixed or switch to a full-blown database like Postgres. There was a link in the error message asking me to report the bug, so I opened the Contributing page, which in turn led me to the issues section of the repo.
Before filing a new bug, I had a quick search for the error message in the existing issues, and found an open bug with the same issue! I read through the bug report, hoping that it would contain an answer or work-around for my problem. While it didn't directly have an answer, it did reference another bug which mentioned that there was a problem when library paths contain quotes. Quotes in paths are common in Windows, since many folders have spaces in their names, for instance 'Program Files', where I had installed Sqlite. This was starting to suggest a way I could get around my problem.
To get more information about my bug, I ran cargo run --verbose
:
```bash
cargo run --verbose
Fresh winapi v0.2.7
Fresh libc v0.2.11
Fresh rustc-serialize v0.3.19
Fresh bitflags v0.7.0
Fresh winapi-build v0.1.1
Fresh pkg-config v0.3.8
Fresh linked-hash-map v0.0.9
Fresh lru-cache v0.0.7
Fresh kernel32-sys v0.2.2
Compiling libsqlite3-sys v0.5.0
Running `rustc C:\Users\james.tease\.cargo\registry\src\github.com-88ac128001ac3a9a\libsqlite3-sys-0.5.0\src\lib.rs --crate-name libsqlite3_sys --crate-type lib -g -C metadata=b72bcb022ad64b13 -C extra-filename=-b72bcb022ad64b13 --out-dir C:\Users\james.tease\Documents\todo\target\debug\deps --emit=dep-info,link -L dependency=C:\Users\james.tease\Documents\todo\target\debug\deps -L dependency=C:\Users\james.tease\Documents\todo\target\debug\deps --extern libc=C:\Users\james.tease\Documents\todo\target\debug\deps\liblibc-38919d24e617a235.rlib --cap-lints allow -L "\"C:\Program Files\sqlite3\"" -l sqlite3`
Fresh time v0.1.35
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: JoinPathsError { inner: JoinPathsError }', ../src/libcore\result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `libsqlite3-sys`.
Caused by:
Process didn't exit successfully: `rustc C:\Users\james.tease\.cargo\registry\src\github.com-88ac128001ac3a9a\libsqlite3-sys-0.5.0\src\lib.rs [...snip...] "C:\Program Files\sqlite3" -l sqlite3` (exit code: 101)
```
The final line, 'Caused by', was interesting - it seemed to point to my Sqlite installation folder as the problem. Combined with the bug report about Rust not liking quotes in path names, this seemed to point to this folder causing the problem. If I installed Sqlite in a folder which didn't have any spaces in it, the the path name wouldn't need to be wrapped in quotes, so shouldn't run into this problem. Aha! My project could carry on after all!
Change of folder
I moved my Sqlite folder to C:/sqlite
, updated my Path variable and ran cargo run
, confident that everything would work just as expected.
```bash
Compiling libsqlite3-sys v0.5.0
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: JoinPathsError { inner: JoinPathsError }', ../src/libcore\result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `libsqlite3-sys`
```
Balls.
The same error as before, which didn't make sense - I'd just moved and updated everything, so I shouldn't get exactly the same error! Maybe there was another folder in my Path which was causing a similar problem. To get more information, I ran cargo run --verbose
again:
```bash
cargo run --verbose
Fresh winapi v0.2.7
Fresh libc v0.2.11
Fresh rustc-serialize v0.3.19
Fresh bitflags v0.7.0
Fresh winapi-build v0.1.1
Fresh pkg-config v0.3.8
Fresh linked-hash-map v0.0.9
Fresh lru-cache v0.0.7
Fresh kernel32-sys v0.2.2
Compiling libsqlite3-sys v0.5.0
Running `rustc C:\Users\james.tease\.cargo\registry\src\github.com-88ac128001ac3a9a\libsqlite3-sys-0.5.0\src\lib.rs --crate-name libsqlite3_sys --crate-type lib -g -C metadata=b72bcb022ad64b13 -C extra-filename=-b72bcb022ad64b13 --out-dir C:\Users\james.tease\Documents\todo\target\debug\deps --emit=dep-info,link -L dependency=C:\Users\james.tease\Documents\todo\target\debug\deps -L dependency=C:\Users\james.tease\Documents\todo\target\debug\deps --extern libc=C:\Users\james.tease\Documents\todo\target\debug\deps\liblibc-38919d24e617a235.rlib --cap-lints allow -L "\"C:\Program Files\sqlite3\"" -l sqlite3`
Fresh time v0.1.35
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: JoinPathsError { inner: JoinPathsError }', ../src/libcore\result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `libsqlite3-sys`.
Caused by:
Process didn't exit successfully: `rustc C:\Users\james.tease\.cargo\registry\src\github.com-88ac128001ac3a9a\libsqlite3-sys-0.5.0\src\lib.rs [...snip...] "C:\Program Files\sqlite3" -l sqlite3` (exit code: 101)
```
That's exactly the same error, and even included C:\Program Files\sqlite3
, which wasn't on my Path any more - where was the compiler getting this from? Maybe it had a cached version somewhere.
Delete everything
I deleted the target
folder in my project, which is where the Rust compiler outputs the compiled project, and ran cargo run
again. This time it worked! The compiler did have a saved version or some sort of cache, and had been using the problematic version rather than my working Path. Finally, my code could compile, and I could carry on writing my todo list. Success.