I want to build 'just' and other Rust projects using -Zbuild-std=std,panic_abort --target x86_64-unknown-linux-gnu flags.
If I call 'cargo' like this it works: cargo build --release -Zbuild-std=std,panic_abort --target x86_64-unknown-linux-gnu
However, that's not what I want because I will be also building with different build systems like ninja, so I would like to set variables with these flags for a more agnostic approach and less repetition.
I know CARGO_BUILD_TARGET works for the target folder, however it's unclear where to put the first part -Zbuild-std=std,panic_abort. I tried in RUSTFLAGS but it gives me error: unknown unstable option: build-std. If I try CARGO_BUILD_RUSTFLAGS the flags are not applied.
Maybe set environment var RUSTFLAGS, seen here as:
RUSTFLAGS — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances. See build.rustflags for some more ways to set flags. This string is split by whitespace; for a more robust encoding of multiple arguments, see CARGO_ENCODED_RUSTFLAGS.
Sorry I missed that for some reason and I remember even double checking that and somehow not seeing RUSTFLAGS in there, but wouldn't matter either way because:
build-std is a cargo feature that's why it won't work with RUSTFLAGS, so it won't work with RUSTFLAGS indeed, my bad.
It would appear that this works:
Create or modify the .cargo/config.toml file in your project directory(or user directory but that's too extreme I think) with these contents:
now cargo run should pick up, at least build-std and target. I'm unclear if it picks up the std and panic_abort though, because if I remove the latter or rename it to panic_unwind, cargo run doesn't rebuild anything hmmm...
Otherwise, I think you're stuck without being able to use env. vars for this, due to, apparently being unable to pass cargo flags to cargo like you can pass rust flags to rustc via RUSTFLAGS, also:
Requirements
As a summary, a list of requirements today to use -Z build-std are:
You must install libstd’s source code through rustup component add rust-src
You must pass --target
You must use both a nightly Cargo and a nightly rustc The -Z build-std flag must be passed to all cargo invocations.
Maybe, you can set CARGO to point to your cargo shell script that just passes the extra flags to the real cargo
CARGO — Path to the cargo binary performing the build.