Git Product home page Git Product logo

Comments (5)

ehuss avatar ehuss commented on September 28, 2024

Thanks for the report! If you removed -Z build-std, did you also remove the --target flag? Also, when you say whether or not build.rs is recompiled, is it important to you that the build script itself is recompiled, or just that it runs again and picks up the new CARGO_ENCODED_RUSTFLAGS? It's unclear what C libraries you are referring to, or how they are being built, or how this relates to the build script and RUSTFLAGS. If you can provide a complete and minimal reproduction, it can be helpful to see exactly what you are doing and trying to accomplish.

Assuming that you removed --target, and that you only care about running the script again, then this unrelated to -Z build-std and is a duplicate of #13003.

from cargo.

nazar-pc avatar nazar-pc commented on September 28, 2024

Thanks for the report! If you removed -Z build-std, did you also remove the --target flag?

No, just -Z build-std to minimize changes. --target on its own doesn't cause any issues for me.

Also, when you say whether or not build.rs is recompiled, is it important to you that the build script itself is recompiled, or just that it runs again and picks up the new CARGO_ENCODED_RUSTFLAGS?

Apologies, I meant that whatever build.rs compiles to doesn't re-run on CPU change.

It's unclear what C libraries you are referring to, or how they are being built, or how this relates to the build script and RUSTFLAGS.

build.rs calls https://github.com/rust-lang/cc-rs when run. So the first time it compiled libraries for Skylake with certain newer instructions and later when I recompiled for different CPU without clearing target I discovered that it crashes on older processors due to newer instructions being still in the library. I later reduced and reported the issue.

from cargo.

ehuss avatar ehuss commented on September 28, 2024

Hm, I'm not aware of cc looking at the target-cpu. Can you please post a complete, minimal reproduction, along with exactly what appears to not be being picked up in the build script? Here's exactly what I'm seeing:

[package]
name = "foo"

[build-dependencies]
cc = "1.0.90"
// src/main.rs
fn main() {}
// build.rs
fn main() {
    cc::Build::new().file("foo.c").compile("foo");
}
/* foo.c */
RUSTFLAGS="-C target-cpu=skylake" CC_ENABLE_DEBUG_OUTPUT=1 cargo build -vv -Zbuild-std --target x86_64-unknown-linux-gnu

The exact compiler command this displays as running:

[foo 0.0.0] running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/home/eric/Temp/foo/target/x86_64-unknown-linux-gnu/debug/build/foo-dcda6d277b285a73/out/d1fba762150c532c-foo.o" "-c" "foo.c"

Notice that it does not mention -mcpu or anything like that. Running with a different CPU:

cargo clean
RUSTFLAGS="-C target-cpu=x86-64-v2" CC_ENABLE_DEBUG_OUTPUT=1 cargo build -vv -Zbuild-std --target x86_64-unknown-linux-gnu

doesn't change the output. cc is building it identically.

from cargo.

nazar-pc avatar nazar-pc commented on September 28, 2024
// build.rs
fn main() {
    std::fs::write(
        format!("{}/rustflags.rs", std::env::var("OUT_DIR").unwrap()),
        std::env::var("CARGO_ENCODED_RUSTFLAGS").unwrap_or_default(),
    )
    .unwrap();
}
// src/main.rs
fn main() {
    println!(
        "{}",
        include_str!(concat!(env!("OUT_DIR"), "/rustflags.rs"))
    );
}

Now do:

RUSTFLAGS="-C target-cpu=skylake" cargo +nightly run -Z build-std --target x86_64-unknown-linux-gnu
RUSTFLAGS="-C target-cpu=x86-64-v2" cargo +nightly run -Z build-std --target x86_64-unknown-linux-gnu

You will get:

-Ctarget-cpu=skylake
-Ctarget-cpu=skylake

But should have gotten:

-Ctarget-cpu=skylake
-Ctarget-cpu=x86-64-v2

from cargo.

ehuss avatar ehuss commented on September 28, 2024

Thanks! That looks to be a duplicate of #13003, so closing in favor of that.

from cargo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.