Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable RUSTFLAGS not set inside build.rs script since Rust 1.55.0 #10111

Closed
Tirka opened this issue Nov 22, 2021 · 4 comments
Closed
Labels
A-build-scripts Area: build.rs scripts A-rustflags Area: rustflags C-bug Category: bug

Comments

@Tirka
Copy link

Tirka commented Nov 22, 2021

Problem

Environment variable RUSTFLAGS not set inside build.rs script since Rust 1.55.0

Steps

Install Rust Stable 1.54 and 1.55

rustup install 1.54.0
rustup install 1.55.0

Clone Minimal Reproducible Example

git clone https://github.com/Tirka/rustflags-buildrs.git
cd ./rustflags-buildrs

Build with Cargo and Rust Stable 1.54.0

RUSTFLAGS="-C target-cpu=skylake" FOO="bar" cargo +1.54.0 build -vv

Output:

[rustflags-buildrs 0.1.0] RUSTFLAGS=Some("-C target-cpu=skylake")
[rustflags-buildrs 0.1.0] FOO=Some("bar")

Cargo clean

cargo clean

Build with Cargo and Rust Stable 1.55.0

RUSTFLAGS="-C target-cpu=skylake" FOO="bar" cargo +1.55.0 build -vv

Output:

[rustflags-buildrs 0.1.0] RUSTFLAGS=None
[rustflags-buildrs 0.1.0] FOO=Some("bar")

It looks like RUSTFLAGS environment variable is not available within build.rs script since 1.55.0 and I can't find any info related to this new behavior in the changelog.

Possible Solution(s)

No response

Notes

No response

Version

No response

@Tirka Tirka added the C-bug Category: bug label Nov 22, 2021
@Tirka Tirka changed the title Environment variable RUSTFLAGS not set inside build.rs srcipt since Rust 1.55.0 Environment variable RUSTFLAGS not set inside build.rs script since Rust 1.55.0 Nov 22, 2021
@ehuss
Copy link
Contributor

ehuss commented Nov 23, 2021

Thanks for the report, and sorry about the problem you've run into. This was changed in #9601, and I asked for clarification over there. But I'm also wondering, is it feasible for you to use CARGO_ENCODED_RUSTFLAGS? I'm not sure if your project has strict requirements for supporting older versions of cargo.

@Tirka
Copy link
Author

Tirka commented Nov 23, 2021

Unfortunately, this change of the Cargo behavior affects 3rd party crates, which rely on RUSTFLAGS in their build.rs. (e.g., https://github.com/darrenldl/reed-solomon-erasure/blob/5fe2d8a7786ac7891cca6c1e20371a0be0c9ce82/build.rs#L164)

So, this is not a bug? Is this behavior expected?

@alexcrichton
Copy link
Member

Following up from #9601 (comment) I'll echo what jonhoo said and otherwise add that other methods of configuring flags, e.g. build.rustflags and such, were never reflected with RUSTFLAGS and are now all reflected via the replacement. While this was a breaking change I figured it was ok since it was only "half" working before when the outer cargo invocation already happened to set the environment variable and it would be best for a guaranteed source of information instead of one that only may happen to be set.

@Eh2406
Copy link
Contributor

Eh2406 commented Dec 10, 2021

We added it to the Changelog, both in the release where the change happened and in the release where you noticed it.
Sorry for not documenting this change when it happened. #10141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-rustflags Area: rustflags C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants