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

Changes to RUSTC_BOOTSTRAP causes unwanted recompilations #467

Open
weiznich opened this issue Jul 16, 2024 · 1 comment
Open

Changes to RUSTC_BOOTSTRAP causes unwanted recompilations #467

weiznich opened this issue Jul 16, 2024 · 1 comment

Comments

@weiznich
Copy link

I have a rather large project and I need to sometimes change RUSTC_BOOTSTRAP for some reasons. This causes proc_macro2 to recompile, which in turn recompile a large portion of our dependency tree. I personally find it quite surprising that this happens as this behavior is not documented anywhere.

Cargo verbose log:

      Dirty proc-macro2 v1.0.86: the env variable RUSTC_BOOTSTRAP changed
     Compiling proc-macro2 v1.0.86

Offending source code:

println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");

@dtolnay
Copy link
Owner

dtolnay commented Feb 3, 2025

I think the only way to solve this would be for Cargo to expose a way that crates can ask for a particular environment variable to be hashed into the crate's metadata. Similar to what was done in rust-lang/cargo#14830 for RUSTFLAGS. Either dynamically from a build script (cargo:rerun-if-env-changed-hashed=…) or statically from a manifest entry.

For rustc 1.85+ (current beta), one workaround is to use different RUSTFLAGS between your RUSTC_BOOTSTRAP builds and non-RUSTC_BOOTSTRAP builds.

Without RUSTFLAGS:

$ cargo +beta check
   Compiling proc-macro2 v1.0.93
   Compiling unicode-ident v1.0.16
   Compiling quote v1.0.38
   Compiling syn v2.0.98
   Compiling serde_derive v1.0.217
    Checking repro v0.0.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.01s
$ RUSTC_BOOTSTRAP=1 cargo +beta check
   Compiling proc-macro2 v1.0.93
   Compiling quote v1.0.38
   Compiling syn v2.0.98
   Compiling serde_derive v1.0.217
    Checking repro v0.0.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.54s
$ cargo +beta check
   Compiling proc-macro2 v1.0.93
   Compiling quote v1.0.38
   Compiling syn v2.0.98
   Compiling serde_derive v1.0.217
    Checking repro v0.0.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.57s

With RUSTFLAGS:

$ cargo +beta check
   Compiling proc-macro2 v1.0.93
   Compiling unicode-ident v1.0.16
   Compiling quote v1.0.38
   Compiling syn v2.0.98
   Compiling serde_derive v1.0.217
    Checking repro v0.0.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.92s
$ RUSTC_BOOTSTRAP=1 RUSTFLAGS=--cfg=__anything cargo +beta check
   Compiling proc-macro2 v1.0.93
   Compiling unicode-ident v1.0.16
   Compiling quote v1.0.38
   Compiling syn v2.0.98
   Compiling serde_derive v1.0.217
    Checking repro v0.0.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.92s
$ cargo +beta check
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
$ RUSTC_BOOTSTRAP=1 RUSTFLAGS=--cfg=__anything cargo +beta check
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s

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

No branches or pull requests

2 participants