How can I globally configure a Cargo profile optio

2019-06-21 06:33发布

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?

2条回答
Ridiculous、
2楼-- · 2019-06-21 06:40

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
查看更多
Anthone
3楼-- · 2019-06-21 07:00

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.

查看更多
登录 后发表回答