Skip to content

profile-rustflags are not propagated to CARGO_CFG_TARGET_FEATURE or CARGO_ENCODED_RUSTFLAGS #12437

Open
@DouglasDwyer

Description

@DouglasDwyer

Problem

When setting flags with the profile-rustflags unstable feature (tracking issue #10271), the data is not propagated to the build script environment variables CARGO_CFG_TARGET_FEATURE and CARGO_ENCODED_RUSTFLAGS.

Steps

  1. Create a new binary
  2. Create a build.rs:
fn main() {
    println!("cargo:warning=Feats: {:?} Flags: {:?}", std::env::var("CARGO_CFG_TARGET_FEATURE"), std::env::var("CARGO_ENCODED_RUSTFLAGS"));
}
  1. Set up Cargo.toml:
cargo-features = [ "profile-rustflags" ]

[package]
name = "profile_flags_script"
version = "0.1.0"
edition = "2021"

[profile.dev]
rustflags = [ "-C", "target-feature=+crt-static" ]
  1. Call cargo run - observe that crt-static is not reported by the build script.
  2. Create .cargo/Config.toml:
[build]
rustflags = [ "-C", "target-feature=+crt-static" ]
  1. Call cargo clean and cargo run - observe that the build script now sees the crt-static flag, as it should.

Possible Solution(s)

No response

Notes

This issue seems very similar to #6858.

Version

cargo 1.70.0-nightly (145219a9f 2023-03-27)
release: 1.70.0-nightly
commit-hash: 145219a9f089f8b57c09f40525374fbade1e34ae
commit-date: 2023-03-27
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 8.0.1-DEV (sys:0.4.61+curl-8.0.1 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Home) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-environment-variablesArea: environment variablesA-rustflagsArea: rustflagsC-bugCategory: bugS-needs-mentorStatus: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.Z-profile-rustflagsNightly: profile-rustflags

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions