External Dependencies in crates and cross-platform development

Case Study:

My current development environment is VSCode on Windows, using rust-analyzer for code analysis, running tests and debug builds on Windows, and running release builds on WSL.

I want to begin using blessed crate https://diesel.rs with a MySQL backend. The 'Getting Started' page has reasonable instructions for Linux, given that I mainly need to install libmysqlclient on top of other dependencies usually present for compiling programs (after installing mysql and setting it up), and then I can include diesel in my Cargo.toml file. I can isolate the dependency using a feature, but I don't want to exclude the feature on Windows targets, because rust-analyzer builds for Windows to see if I have compilation errors.

I have not yet gotten it to work on Windows at all. Installation is more complicated: the dependency mysqlclient-sys has a build script dependent on environment variables, which were not set by the MySQL installer on Windows, and it isn't clear from the script's error message which are not set correctly. Diesel's instructions recommend a bundled mysqlclient-sys but this fails in building openssl-sys because perl is not installed in the Windows environment. I had to search for answers to these problems because the documentation didn't address it, and some threads were years old and out of date. And finally, getting diesel_cli to build via cargo install in PowerShell does not imply that building will succeed in VSCode, as that's the current status of my Windows setup.

Discussion:

I really like the crate ecosystem and ease-of-use in adding dependencies to my project. This is really the first time I can think of that a crate has a dependency on something I haven't already installed, and it's been a uniquely frustrating experience that I can't spend my time focusing on writing code and testing out the new dependency.

Is there a way we can allow this dependency management to occur within the cargo files, such as:

  • specifying config values in an environment file, similar to how dotenvy reads from a .env file? (and having cargo build request them if they're missing)
  • specifying and checking requirements that cannot be installed by cargo or build scripts, such as perl

Ideally I also don't have to provide in-depth installation instructions for diesel stuff beyond MySQL, just as diesel shouldn't have to for mysqlclient-sys, and just as mysqlclient-sys shouldn't have to for openssl-sys. (MySQL table setup can easily be scripted.)

My project has no reason to be platform-specific, so it would feel bad to ditch Windows as an allowed target platform. But on the other hand, having a streamlined build process is such a core feature of cargo that it also feels bad to have these issues trying to add a popular crate as a dependency for multiple popular platforms.