Sam.Sui
Sam.Sui

Reputation: 41

Why does defining RUSTFLAGS cause rustflags in .cargo/config to be ignored?

I have this as my ./cargo/config:

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-none-linux-gnu-gcc"
rustflags = ["-C", "target-feature=+crt-static"]

I have defined RUSTFLAGS in build.sh like so:

export RUSTFLAGS='--cfg chip_type="es"'

When I do:

cargo build --target=aarch64-unknown-linux-gnu

I find that the "-C", "target-feature=+crt-static" is not included. How do I solve this problem?

Upvotes: 3

Views: 804

Answers (1)

Sam.Sui
Sam.Sui

Reputation: 41

As can be seen from Cargo Configuration on build.rustflags:

There are three mutually exclusive sources of extra flags. They are checked in order, with the first one being used:

  1. RUSTFLAGS environment variable.

  2. All matching target.<triple>.rustflags and target.<cfg>.rustflags config entries joined together.

  3. build.rustflags config value.

So this new build.sh code solves my problem:

RUSTFLAGS='--cfg chip_type="es" '$RUSTFLAGS
RUSTFLAGS='-C target-feature=+crt-static '$RUSTFLAGS
export RUSTFLAGS

Upvotes: 1

Related Questions