【问题标题】:Why does defining RUSTFLAGS cause rustflags in .cargo/config to be ignored?为什么定义 RUSTFLAGS 会导致 .cargo/config 中的 rustflags 被忽略?
【发布时间】:2023-03-25 15:15:01
【问题描述】:

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

【问题讨论】:

    标签: rust build rust-cargo


    【解决方案1】:

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

    有三个相互排斥的额外标志来源。它们按顺序检查,使用第一个:

    1. RUSTFLAGS 环境变量。

    2. 所有匹配的 target.<triple>.rustflagstarget.<cfg>.rustflags 配置条目连接在一起。

    3. build.rustflags 配置值。

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

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

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多