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

RUSTFLAGS in .cargo/config.toml or environment variable is not respected when compiling build scripts #62

Open
funnsam opened this issue Dec 15, 2024 · 2 comments · May be fixed by #63

Comments

@funnsam
Copy link

funnsam commented Dec 15, 2024

The changes in #50 does not apply to build scripts. For example, when compiling the chess crate with [build] rustflags = ["-C", "target-cpu=native"] in .cargo/config.toml and running cargo pgo build -- --verbose, it produces several compiler error due to some code not generated in the build script due to missing CPU features when compiling the build script. There are probably more crates that are affected by this.

Edit: was doing RUSTFLAGS="-C target-cpu=native" cargo pgo build -- --verbose, but both are not working

   Compiling chess v4.0.0 (/home/funnsam/Projects/personal/chessbot2/chess)
     Running `/home/funnsam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name build_script_build --edition=2021 chess/src/build.rs --error-format=json --json=diagnostic-rendered-ans
i,artifacts,future-incompat --diagnostic-width=206 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=6d17c18
f1e2910a5 -C extra-filename=-6d17c18f1e2910a5 --out-dir /home/funnsam/Projects/personal/chessbot2/target/release/build/chess-6d17c18f1e2910a5 -C strip=debuginfo -L dependency=/home/funnsam/Projects/personal
/chessbot2/target/release/deps --extern const_for=/home/funnsam/Projects/personal/chessbot2/target/release/deps/libconst_for-1ca5b06aeec5f8b6.rlib --extern rand=/home/funnsam/Projects/personal/chessbot2/tar
get/release/deps/librand-1f61f4d4dde8b834.rlib --extern thiserror=/home/funnsam/Projects/personal/chessbot2/target/release/deps/libthiserror-b2960b6fa067cfe0.rlib` (no -C target-cpu=native here!)
     Running `/home/funnsam/Projects/personal/chessbot2/target/release/build/chess-6d17c18f1e2910a5/build-script-build`
     Running `/home/funnsam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name chess --edition=2021 chess/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,fut
ure-incompat --diagnostic-width=206 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C codegen-units=1 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C me
tadata=7dc5e06409290ebf -C extra-filename=-7dc5e06409290ebf --out-dir /home/funnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C strip=debugi
nfo -L dependency=/home/funnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/funnsam/Projects/personal/chessbot2/target/release/deps --extern arrayvec=/home/f
unnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gnu/release/deps/libarrayvec-dbffae55b3fbc857.rmeta --extern const_for=/home/funnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gn
u/release/deps/libconst_for-5f58c96a18b272b2.rmeta --extern nodrop=/home/funnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gnu/release/deps/libnodrop-375fbaee2b52f7f1.rmeta --extern thiserror=
/home/funnsam/Projects/personal/chessbot2/target/x86_64-unknown-linux-gnu/release/deps/libthiserror-16130579d7cde1cd.rmeta -C target-cpu=native -Cprofile-generate=/home/funnsam/Projects/personal/chessbot2/t
arget/pgo-profiles`
error[E0425]: cannot find value `ROOK_BMI_MASK` in this scope                                                                                                                                               
  --> chess/src/magic.rs:43:27
   |
43 |         let bmi2_magic = *ROOK_BMI_MASK.get_unchecked(sq.to_int() as usize);
   |                           ^^^^^^^^^^^^^ not found in this scope

...
@funnsam funnsam changed the title RUSTFLAGS in .cargo/config.toml is not respected when compiling build scripts RUSTFLAGS in .cargo/config.toml or environment variable is not respected when compiling build scripts Dec 15, 2024
@Kobzol
Copy link
Owner

Kobzol commented Dec 19, 2024

Hi! Sorry for the delay, was swamped this week.

The situation with RUSTFLAGS is... complicated, to say the least. cargo-pgo uses [target.'cfg(all())'] instead of [build], because it has a higher precedence.

Could you try replacing [build] rustflags with [target.'cfg(all())'] rustflags? Then the flags should be properly combined.

@Kobzol Kobzol linked a pull request Dec 19, 2024 that will close this issue
@Kobzol
Copy link
Owner

Kobzol commented Dec 19, 2024

Posted #63 to document this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants