I once set the $RUSTFLAGS
to a crazy state, to achieve the fastest possible performance of Rust
-C opt-level=3 -C target-cpu=native -C codegen-units=1 -C lto
And then, my compile time blows up dramastically , it takes about 20 seconds to compile the syn crate.
I've searched for some solutions, such as "using mold
" , but that is just a no-op. To figure out what happened, I tested a lot and finally figure that, when enable mold
, the command it suggests is:
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]
That flag is rustflags
, which is replaced by the defined environment variable (even without a warning).
I had fixed the issue, remove the RUSTFLAGS environment, using a custom script calls rustc and config cargo with config.toml, but I still wonder whether I forgot something:
- What is the usage of environment variable RUSTFLAGS? Should it be set automatically?
- By what design cargo decided not to merge RUSTFLAGS with the custom one, but make RUSTFLAGS rules the current one?
- Should the be a warning or a message in the future?