easy: LazyCell<RefCell<Easy>>,
/// Cache of the `SourceId` for crates.io
crates_io_source_id: LazyCell<SourceId>,
+ /// 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,
}
}
});
+ 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),
cli_flags: CliUnstable::default(),
easy: LazyCell::new(),
crates_io_source_id: LazyCell::new(),
+ cache_rustc_info,
creation_time: Instant::now(),
}
}
Rustc::new(
self.get_tool("rustc")?,
self.maybe_get_tool("rustc_wrapper")?,
- cache_location,
+ if self.cache_rustc_info {
+ cache_location
+ } else {
+ None
+ },
)
}
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]
.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"),
.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(
.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 = {
.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(
.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();
.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(
.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),
);
}