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"]
Header Image
How to use Rust in Python (Part 3)

You can follow the links to read the first part and the second part of this series. In the previous part we have seen how to pass not trivial data to Rust functions such as a Python list. It is still …

Read
Header Image
How to use Rust in Python (Part 1)

Rust is an amazing language. It is one of the best potential alternatives to C and has been elected two times in a row as the most promising language of the year (by me, :P). However, because its …

Read
Header Image
Most Promising Programming Languages of 2017

Another year, another 5 promising programming languages you should keep an eye on in 2017. As usual, I’d like to write the warning I put here every year: in this list, you will not find programming …

Read
comments powered by Disqus