With Cargo, I can set a project's development settings to use parallel code generation:
[profile.dev]
codegen-units = 8
According to the documentation, it should be possible to put this into ~/.cargo/config
to apply this setting to all projects. This doesn't work for me: it seems that the .cargo/config
file isn't used at all. Is there any way to apply such configuration to every project I compile?
You can set rustflags for all builds or per target in your .cargo/config
file.
[build] # or [target.$triple]
rustflags = ["-Ccodegen-units=4"]
To be clear, this will set the codegen-units for all your projects (covered by this .cargo/config) regardless of profile.
To make sure it's actually set, you can also set verbose output in the same file. This will show each rustc command with flags that cargo invokes.
[term]
verbose = true
A workaround is to create a script to be called instead of cargo
#!/bin/bash
if [[ $* != *--release* ]]; then
# dev build
export RUSTFLAGS="-C codegen-units=8"
fi
cargo "$@"
If you use the full path to cargo
on the script, you can create a alias
alias cargo=/path/to/script
and just call cargo
.