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

标签 rust build rust-cargo

我把它作为我的 ./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" 不包括在内。我该如何解决这个问题?

最佳答案

Cargo Configuration可以看出在 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.

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

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

关于rust - 为什么定义 RUSTFLAGS 会导致 .cargo/config 中的 rustflags 被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70360722/

相关文章:

rust - 线程 'main' 在 'called ` Result::unwrap( )` on an ` Err` 值:UrlRequest(Error(Url(RelativeUrlWithoutBase)))', src\libcore\result.rs:1165:5

rust - 如何异步读取文件?

build - Gradle:如何在打包中排除编译范围文件依赖项?

rust - Rust 的 clippy 可以自动更正/自动修复吗?

rust - `flat_map` 如何影响我的代码?

casting - 非标量转换 : `Box<FnMut<&Any>>`

ios - 我在哪里更改 xcode 中的版本号

c++ - 我怎样才能让 CMake 用两种不同的语言编译同一个输入文件?

rust - 每晚在 Rust 上构建 maciejhirsz/logos-2020-06-13

rust - 如何处理 Rust/Cargo 中的 3rd 方静态 C 库依赖项?