build.rs should ignore RUSTFLAGS
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Problem
build.rs is compiled with RUSTFLAGS if target is not specified.
$ RUSTFLAGS="-C target-cpu=nehalem" cargo build -vv
Compiling test-build v0.1.0 (/Users/plhk/Documents/src/test-build)
Running `rustc --crate-name build_script_build build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8a72131a02621b95 -C extra-filename=-8a72131a02621b95
--out-dir /Users/plhk/Documents/src/test-build/target/debug/build/test-build-8a72131a02621b95
-C incremental=/Users/plhk/Documents/src/test-build/target/debug/incremental
-L dependency=/Users/plhk/Documents/src/test-build/target/debug/deps -C target-cpu=nehalem`
The problem here is that if a user compiles for a newer CPU than they have, build script can potentially use newer instructions and fail with SIGILL.
Steps
1.cargo new test-build
2.cd test-build
3.touch build.rs
4.cargo build -vv
Possible Solution(s)
I don't have a solution, but it seems like env_args() is the problem.
Notes
Output of cargo version:
cargo 1.30.0 (a1a4ad372 2018-11-02)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the reported cargo build -vv command and inspect env_args() in src/cargo/core/compiler/build_context/mod.rs. Trace how RUSTFLAGS reaches build.rs, then verify the build-script rustc invocation no longer receives the unsafe target-specific flags while the reported build still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100