Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I globally configure a Cargo profile option?

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?

like image 673
George Hilliard Avatar asked Aug 15 '15 21:08

George Hilliard


People also ask

Where is cargo config?

Windows: %USERPROFILE%\. cargo\config. toml.

What is opt level?

opt-level. The opt-level setting controls the -C opt-level flag which controls the level of optimization. Higher optimization levels may produce faster runtime code at the expense of longer compiler times. Higher levels may also change and rearrange the compiled code which may make it harder to use with a debugger.


2 Answers

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
like image 52
Zoomulator Avatar answered Nov 15 '22 08:11

Zoomulator


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.

like image 21
malbarbo Avatar answered Nov 15 '22 08:11

malbarbo