diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 4596f07c1..1dfefb8c8 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -66,6 +66,9 @@ pub struct Config { easy: LazyCell>, /// Cache of the `SourceId` for crates.io crates_io_source_id: LazyCell, + /// If false, don't cache `rustc --version --verbose` invocations + cache_rustc_info: bool, + /// Creation time of this config, used to output the total build time creation_time: Instant, } @@ -82,6 +85,11 @@ impl Config { } }); + let cache_rustc_info = match env::var("CARGO_CACHE_RUSTC_INFO") { + Ok(cache) => cache != "0", + _ => true, + }; + Config { home_path: Filesystem::new(homedir), shell: RefCell::new(shell), @@ -103,6 +111,7 @@ impl Config { cli_flags: CliUnstable::default(), easy: LazyCell::new(), crates_io_source_id: LazyCell::new(), + cache_rustc_info, creation_time: Instant::now(), } } @@ -162,7 +171,11 @@ impl Config { Rustc::new( self.get_tool("rustc")?, self.maybe_get_tool("rustc_wrapper")?, - cache_location, + if self.cache_rustc_info { + cache_location + } else { + None + }, ) } diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index b5f81e2d2..3b505faa2 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -9,29 +9,31 @@ with them: You can override these environment variables to change Cargo's behavior on your system: -* `CARGO_HOME` - Cargo maintains a local cache of the registry index and of git +* `CARGO_HOME` — Cargo maintains a local cache of the registry index and of git checkouts of crates. By default these are stored under `$HOME/.cargo`, but this variable overrides the location of this directory. Once a crate is cached it is not removed by the clean command. -* `CARGO_TARGET_DIR` - Location of where to place all generated artifacts, +* `CARGO_TARGET_DIR` — Location of where to place all generated artifacts, relative to the current working directory. -* `RUSTC` - Instead of running `rustc`, Cargo will execute this specified +* `RUSTC` — Instead of running `rustc`, Cargo will execute this specified compiler instead. -* `RUSTC_WRAPPER` - Instead of simply running `rustc`, Cargo will execute this +* `RUSTC_WRAPPER` — Instead of simply running `rustc`, Cargo will execute this specified wrapper instead, passing as its commandline arguments the rustc invocation, with the first argument being rustc. -* `RUSTDOC` - Instead of running `rustdoc`, Cargo will execute this specified +* `RUSTDOC` — Instead of running `rustdoc`, Cargo will execute this specified `rustdoc` instance instead. -* `RUSTDOCFLAGS` - A space-separated list of custom flags to pass to all `rustdoc` +* `RUSTDOCFLAGS` — A space-separated list of custom flags to pass to all `rustdoc` invocations that Cargo performs. In contrast with `cargo rustdoc`, this is useful for passing a flag to *all* `rustdoc` instances. -* `RUSTFLAGS` - A space-separated list of custom flags to pass to all compiler +* `RUSTFLAGS` — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with `cargo rustc`, this is useful for passing a flag to *all* compiler instances. -* `CARGO_INCREMENTAL` - If this is set to 1 then Cargo will force incremental +* `CARGO_INCREMENTAL` — If this is set to 1 then Cargo will force incremental compilation to be enabled for the current compilation, and when set to 0 it will force disabling it. If this env var isn't present then cargo's defaults will otherwise be used. +* `CARGO_CACHE_RUSTC_INFO` — If this is set to 0 then Cargo will not try to cache + compiler version information. Note that Cargo will also read environment variables for `.cargo/config` configuration values, as described in [that documentation][config-env] diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index 7d3bcb5e1..28d2c5dc6 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -19,7 +19,9 @@ fn rustc_info_cache() { .build(); let miss = "[..] rustc info cache miss[..]"; - let hit = "[..] rustc info cache hit[..]"; + let hit = "[..]rustc info cache hit[..]"; + let uncached = "[..]rustc info uncached[..]"; + let update = "[..]updated rustc info cache[..]"; assert_that( p.cargo("build").env("RUST_LOG", "cargo::util::rustc=info"), @@ -27,7 +29,8 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]failed to read rustc info cache[..]") .with_stderr_contains(miss) - .with_stderr_does_not_contain(hit), + .with_stderr_does_not_contain(hit) + .with_stderr_contains(update), ); assert_that( @@ -36,7 +39,19 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]reusing existing rustc info cache[..]") .with_stderr_contains(hit) - .with_stderr_does_not_contain(miss), + .with_stderr_does_not_contain(miss) + .with_stderr_does_not_contain(update), + ); + + assert_that( + p.cargo("build") + .env("RUST_LOG", "cargo::util::rustc=info") + .env("CARGO_CACHE_RUSTC_INFO", "0"), + execs() + .with_status(0) + .with_stderr_contains("[..]rustc info cache disabled[..]") + .with_stderr_contains(uncached) + .with_stderr_does_not_contain(update), ); let other_rustc = { @@ -80,7 +95,8 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]different compiler, creating new rustc info cache[..]") .with_stderr_contains(miss) - .with_stderr_does_not_contain(hit), + .with_stderr_does_not_contain(hit) + .with_stderr_contains(update), ); assert_that( @@ -91,7 +107,8 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]reusing existing rustc info cache[..]") .with_stderr_contains(hit) - .with_stderr_does_not_contain(miss), + .with_stderr_does_not_contain(miss) + .with_stderr_does_not_contain(update), ); other_rustc.move_into_the_future(); @@ -104,7 +121,8 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]different compiler, creating new rustc info cache[..]") .with_stderr_contains(miss) - .with_stderr_does_not_contain(hit), + .with_stderr_does_not_contain(hit) + .with_stderr_contains(update), ); assert_that( @@ -115,6 +133,7 @@ fn rustc_info_cache() { .with_status(0) .with_stderr_contains("[..]reusing existing rustc info cache[..]") .with_stderr_contains(hit) - .with_stderr_does_not_contain(miss), + .with_stderr_does_not_contain(miss) + .with_stderr_does_not_contain(update), ); }