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

Do not let cc-rs trigger a rebuild any time the env changes #413

Merged

Conversation

hintron
Copy link
Contributor

@hintron hintron commented Jul 11, 2024

No description provided.

@hintron
Copy link
Contributor Author

hintron commented Jul 11, 2024

My main goal with this PR is to fix the annoying re-compile/re-check times for Bevy 0.14 on Windows. Bevy 0.14 uses BLAKE3 under the hood (since 0.12, I believe).

cc-rs (which BLAKE3 uses) I think started getting more aggressive at detecting env changes in v1.1.0 to the point where even PATH changes caused cc-rs to want to rebuild, and so that's probably why I started noticing the issue after upgrading to Bevy 0.14.

Luckily, there is a setting to turn off env change rebuilds in cc-rs (emit_rerun_if_env_changed). This should leave it up to BLAKE3 to determine in build.rs what envs are important enough to trigger a rebuild for.

For more analysis of what is going on and what I found when digging through the code, see #324 (comment).

@hintron
Copy link
Contributor Author

hintron commented Jul 11, 2024

Testing this PR results in just the following rerun-if-env-changed commands being emitted for me on x64 WIndows 11:

cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=HOST_CFLAGS
cargo:rerun-if-env-changed=CFLAGS
cargo:rerun-if-env-changed=CARGO_FEATURE_PREFER_INTRINSICS
cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
cargo:rerun-if-env-changed=CARGO_FEATURE_PREFER_INTRINSICS
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:rerun-if-env-changed=CARGO_FEATURE_NEON
cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
cargo:rerun-if-env-changed=CC
cargo:rerun-if-env-changed=CFLAGS

(the duplicate emissions are a benign issue, but maybe we can clean that up later)

That contains 4 of the 5 envs explicitly checked for in BLAKE's build.rs:

  • CARGO_FEATURE_PURE
  • CARGO_FEATURE_PREFER_INTRINSICS
  • CARGO_FEATURE_NEON
  • CARGO_FEATURE_NO_NEON

All the other env check commands (CC, CFLAGS, etc.) are still coming from cc-rs, I think, but that's a much better situation than before, where PATH and LIB and all sorts of envs were emitted.

Now, when I make a change to my Bevy game in VSCode with Rust Analyzer (causing cargo check to run in the background), I can subsequently run cargo check in my terminal without triggering a recompile!

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 this pull request may close these issues.

2 participants