为什么定义 RUSTFLAGS 会导致 .cargo/config 中的 rustflags 被忽略?

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

我有这个作为我的。/cargo/config:

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

我在 build.sh 中定义了 RUSTFLAGS,如下所示:

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

当我这样做时:

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

我发现 "-C", "target-feature=+crt-static" 不包括在内。我该如何解决这个问题?

build.rustflags上的Cargo Configuration可以看出:

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.

所以这个新的 build.sh 代码解决了我的问题:

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