How can I configure Cargo profile settings globally?

With Cargo, I can set project development parameters to use parallel code generation:

[profile.dev] codegen-units = 8 

According to the documentation , this can be placed in ~/.cargo/config to apply this parameter to all projects. This does not work for me: it seems that the .cargo/config file is not used at all. Is there a way to apply this configuration to every compiled project?

+5
source share
2 answers

You can set rusty flags for all collections or for each purpose in your .cargo/config file.

 [build] # or [target.$triple] rustflags = ["-Ccodegen-units=4"] 

To be clear, this will set the code units for all of your projects (covered by this .cargo / config) regardless of profile.

To make sure that it is actually installed, you can also set verbose output in the same file. This will show each rustc command with flags that cause loads.

 [term] verbose = true 
+3
source

The workaround is to create a script to call 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 in the script, you can create an alias

 alias cargo=/path/to/script 

and just call cargo .

+2
source

All Articles