Giter Site home page Giter Site logo

Comments (2)

dtolnay avatar dtolnay commented on June 30, 2024

RUSTFLAGS is applied to the compilation of both target code and build scripts when Cargo is not in cross-compile mode.

Your command makes build.rs crash on this line:

let nightly = version.contains("nightly") || version.contains("dev");

If I add return None; above that line, it does not crash. If I add it on the next line, it crashes.

Based on RUSTFLAGS="-C target-feature=+avx512bw" cargo build --verbose, the build script itself is compiled with +avx512bw by Cargo, so a crash makes sense as soon as it hits an instruction that is not available in the host CPU.

Running `~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name build_scrip
  t_build --edition=2021 ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.7
  0/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diag
    ^^^^^^^^
  nostic-width=118 --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature="defa
  ult"' --cfg 'feature="proc-macro"' -C metadata=5c68bf8a9ae873e5 -C extra-filename=-5c68bf8a9ae8
  73e5 --out-dir target/debug/build/proc-macro2-5c68bf8a9ae873e5 -C incremental=target/debug/incr
  emental -L dependency=target/debug/deps -C target-feature=+avx512bw`
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^

You need to put Cargo in cross-compiling mode in order for it to pass different rustflags to host vs target builds, by passing --target. The correct syntax is:

$ cargo build --target x86_64-unknown-linux-gnu --config 'target.x86_64-unknown-linux-gnu.rustflags=["-C", "target_feature=+avx512bw"]'

or:

$ RUSTFLAGS='-C target-feature=+avx512bw' cargo build --target x86_64-unknown-linux-gnu

This is effective even if the host and target happen to be the same target triple.

from proc-macro2.

tuzz avatar tuzz commented on June 30, 2024

Ahh, thank you.

In my particular case, I had misunderstood how to do runtime detection of SIMD features. I needed to add #[target_feature(enable = "...")] to regions of code that used SIMD features. This guide was very helpful.

Closing now. Thanks again.

from proc-macro2.

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.