Skip to content

build.rs should ignore RUSTFLAGS  #6375

@polachok

Description

@polachok

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 (a1a4ad3 2018-11-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-configurationArea: cargo config files and env varsA-environment-variablesArea: environment variablesA-rustflagsArea: rustflagsS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions