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

Build scripts receive wrong OPT_LEVEL when manually using -C opt-level #9358

Closed
glandium opened this issue Apr 14, 2021 · 1 comment · Fixed by #9524
Closed

Build scripts receive wrong OPT_LEVEL when manually using -C opt-level #9358

glandium opened this issue Apr 14, 2021 · 1 comment · Fixed by #9524
Labels
C-bug Category: bug

Comments

@glandium
Copy link
Contributor

Problem
When building with RUSTFLAGS="-C opt-level=1" cargo build --release or cargo rustc --release -- -C opt-level=1, while the compilation will happen with opt-level 1 instead of the default 3 for the release profile, the build script will still get OPT_LEVEL set to 3, not 1.

Steps

  1. cargo new foo
  2. cd foo
  3. echo 'fn main() { panic!("{:?}", std::env::var("OPT_LEVEL")); }' > build.rs
  4. RUSTFLAGS="-C opt-level=1" cargo build --release or cargo rustc --release -- -C opt-level=1 output:
  thread 'main' panicked at 'Ok("3")', build.rs:1:13

Output of cargo version:
cargo 1.51.0 (43b129a20 2021-03-16)

@glandium glandium added the C-bug Category: bug label Apr 14, 2021
@ehuss
Copy link
Contributor

ehuss commented Apr 14, 2021

Generally flags driven by cargo (such as profile settings) shouldn't be passed in manually. That could maybe be documented more clearly, though it may be difficult because there are a large number of flags that shouldn't be used.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 20, 2021
…EL. r=firefox-build-system-reviewers,mhentges

Setting it via -C opt-level makes us hit
rust-lang/cargo#9358 so use an alternative
way, that works since rust version 1.43.0.

Differential Revision: https://phabricator.services.mozilla.com/D112158
@bors bors closed this as completed in 51eac9c Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants