-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Cargo and many sys creates depend on environmental variables for configuration, but there's no standard way to configure default env vars for a project.
Most of this configuration (such as target-cpu, crt-static and whether libraries should be linked statically) is absolutely critical for making high quality redistributable executables.
For example, forgetting about set RUSTFLAGS="-C target-feature=+crt-static" on Windows makes executables that don't work without the latest Visual Studio runtime, which is not available on Windows by default. Users get a scary warning about missing DLL, and googling DLL's name finds lots of shady sites trying serve adware/malware.
Similarly, forgetting to set all dependencies static on macOS with Homebrew means sys creates will use pkg-config, which will hardcode Homebrew-specific paths in the executable, and the executable won't run on other people's computers. "Works only on developers' machines" problem is not easy to spot before getting complaints from users for shipping a broken executable.
Env vars are also shared global mutable state, so even if you remember to set them, they make switching between projects harder and more error-prone.
-
Cargo should use
Cargo.tomlfor all configuration, so thatgit clone; cargo buildcan be made to do the right thing, instead of having to wrap cargo in another build process and remember to use it every time instead of the usual, simplest — but invalid —cargo buildby mistake. -
The features mechanism should be extended, or another mechanism added, to correctly support selection of static vs dynamic linking of libraries. (e.g. you use
foo-rscrate, but want to configurefoo-systo use static linking). -
If "Cargo-native" changes to
Cargo.tomlare undesirable and env vars are here to stay, thenCargo.tomlshould at least have a section for specifying env vars for the project, when it's build as the top-level project (i.e. not as a dependency. Dependencies setting global variables would be bad).