Mastodon Icon RSS Icon GitHub Icon LinkedIn Icon RSS Icon

How to build rusqlite on Windows

Yesterday I spent way more time than needed for compiling this dependency on Windows. The problem is that the error was not informative enough and hard to google, and, mostly, that there is no standardized way to look for installed libraries in Windows. Just to be clear, there is no reliable way to use pkg-config on Windows as in Unix-like systems.

The problem

The rusqlite crate is an ergonomic binding of SQLite in Rust. To work, it needs the original library installed. Unfortunately, on Windows is relatively hard to find the path or the list of the installed development libraries. It is not impossible, but it is harder because Windows ecosystem has not a standard software or API to obtain this information. If you try to blindly add rusqlite as a dependency and compile your crate you get a cryptic error:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
error: no method named \`print\_system\_libs\` found for type \`build::pkg\_config::Config\` in the current scope
  --> C:\\Users\\davide\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\libsqlite3-sys-0.8.0\\build.rs:83:41
   |
83 |         match pkg\_config::Config::new().print\_system\_libs(false).probe("sqlite3") {
   |                                         ^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile \`libsqlite3-sys\`.
Build failed, waiting for other jobs to finish...
error: build failed

The problem is that the crate tries by default to use pkg_config; even on Windows.

The solution

Fortunately, the crate’s developers have developed an alternative solution. You need to enable the bundled feature. With this feature enabled, the library directly compile into itself SQLite from source. This works smoothly on Windows and it is the recommended way to go. Unfortunately, how to enable this feature is not well explained. If you are a seasoned Rust developer you probably know how to do, otherwise you are lost. I’m trying to add this snipped in the upstream repository. Until then, I hope this can be a good reference. To enable the bundled feature in rusqlite you have to specify this dependency in your Cargo.toml file:

1
2
3
[dependencies.rusqlite]
version = "0.11.0"
features = ["bundled"]