How to build “rusqlite” on Windows

Rusqlite Compilation

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:

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: