Skip to content

Commit 784ea96

Browse files
committed
Filter env vars to check against
1 parent f666b19 commit 784ea96

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/cargo/core/compiler/fingerprint.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ use crate::core::{InternedString, Package};
328328
use crate::util;
329329
use crate::util::errors::{CargoResult, CargoResultExt};
330330
use crate::util::paths;
331-
use crate::util::{internal, profile};
331+
use crate::util::{internal, profile, ProcessBuilder};
332332

333333
use super::custom_build::BuildDeps;
334334
use super::job::{
@@ -1759,6 +1759,7 @@ pub fn translate_dep_info(
17591759
rustc_cwd: &Path,
17601760
pkg_root: &Path,
17611761
target_root: &Path,
1762+
rustc_cmd: &ProcessBuilder,
17621763
allow_package: bool,
17631764
) -> CargoResult<()> {
17641765
let depinfo = parse_rustc_dep_info(rustc_dep_info)?;
@@ -1768,6 +1769,34 @@ pub fn translate_dep_info(
17681769
let mut on_disk_info = OnDiskDepInfo::default();
17691770
on_disk_info.env = depinfo.env;
17701771

1772+
// This is a bit of a tricky statement, but here we're *removing* the
1773+
// dependency on environment variables that were defined specifically for
1774+
// the command itself. Environment variables returend by `get_envs` includes
1775+
// environment variables like:
1776+
//
1777+
// * `OUT_DIR` if applicable
1778+
// * env vars added by a build script, if any
1779+
//
1780+
// The general idea here is that the dep info file tells us what, when
1781+
// changed, should cause us to rebuild the crate. These environment
1782+
// variables are synthesized by Cargo and/or the build script, and the
1783+
// intention is that their values are tracked elsewhere for whether the
1784+
// crate needs to be rebuilt.
1785+
//
1786+
// For example a build script says when it needs to be rerun and otherwise
1787+
// it's assumed to produce the same output, so we're guaranteed that env
1788+
// vars defined by the build script will always be the same unless the build
1789+
// script itself reruns, in which case the crate will rerun anyway.
1790+
//
1791+
// For things like `OUT_DIR` it's a bit sketchy for now. Most of the time
1792+
// that's used for code generation but this is technically buggy where if
1793+
// you write a binary that does `println!("{}", env!("OUT_DIR"))` we won't
1794+
// recompile that if you move the target directory. Hopefully that's not too
1795+
// bad of an issue for now...
1796+
on_disk_info
1797+
.env
1798+
.retain(|(key, _)| !rustc_cmd.get_envs().contains_key(key));
1799+
17711800
for file in depinfo.files {
17721801
// The path may be absolute or relative, canonical or not. Make sure
17731802
// it is canonicalized so we are comparing the same kinds of paths.

src/cargo/core/compiler/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub trait Executor: Send + Sync + 'static {
7070
/// this package.
7171
fn exec(
7272
&self,
73-
cmd: ProcessBuilder,
73+
cmd: &ProcessBuilder,
7474
id: PackageId,
7575
target: &Target,
7676
mode: CompileMode,
@@ -93,7 +93,7 @@ pub struct DefaultExecutor;
9393
impl Executor for DefaultExecutor {
9494
fn exec(
9595
&self,
96-
cmd: ProcessBuilder,
96+
cmd: &ProcessBuilder,
9797
_id: PackageId,
9898
_target: &Target,
9999
_mode: CompileMode,
@@ -281,7 +281,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
281281
state.build_plan(buildkey, rustc.clone(), outputs.clone());
282282
} else {
283283
exec.exec(
284-
rustc,
284+
&rustc,
285285
package_id,
286286
&target,
287287
mode,
@@ -299,6 +299,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
299299
&cwd,
300300
&pkg_root,
301301
&target_dir,
302+
&rustc,
302303
// Do not track source files in the fingerprint for registry dependencies.
303304
is_local,
304305
)

0 commit comments

Comments
 (0)