Skip to content

Commit e4baac0

Browse files
committed
Recompile when RUSTFLAGS changes
1 parent e17933e commit e4baac0

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/cargo/ops/cargo_rustc/fingerprint.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub struct Fingerprint {
111111
deps: Vec<(String, Arc<Fingerprint>)>,
112112
local: LocalFingerprint,
113113
memoized_hash: Mutex<Option<u64>>,
114+
rustflags: Vec<String>,
114115
}
115116

116117
#[derive(RustcEncodable, RustcDecodable, Hash)]
@@ -160,6 +161,9 @@ impl Fingerprint {
160161
if self.profile != old.profile {
161162
bail!("profile configuration has changed")
162163
}
164+
if self.rustflags != old.rustflags {
165+
return Err(internal("RUSTFLAGS has changed"))
166+
}
163167
match (&self.local, &old.local) {
164168
(&LocalFingerprint::Precalculated(ref a),
165169
&LocalFingerprint::Precalculated(ref b)) => {
@@ -202,8 +206,9 @@ impl hash::Hash for Fingerprint {
202206
ref deps,
203207
ref local,
204208
memoized_hash: _,
209+
ref rustflags,
205210
} = *self;
206-
(rustc, features, target, profile, deps, local).hash(h)
211+
(rustc, features, target, profile, deps, local, rustflags).hash(h)
207212
}
208213
}
209214

@@ -222,6 +227,7 @@ impl Encodable for Fingerprint {
222227
(a, b.hash())
223228
}).collect::<Vec<_>>().encode(e)
224229
}));
230+
try!(e.emit_struct_field("rustflags", 6, |e| self.rustflags.encode(e)));
225231
Ok(())
226232
})
227233
}
@@ -252,9 +258,11 @@ impl Decodable for Fingerprint {
252258
features: String::new(),
253259
deps: Vec::new(),
254260
memoized_hash: Mutex::new(Some(hash)),
261+
rustflags: Vec::new(),
255262
}))
256263
}).collect()
257-
}
264+
},
265+
rustflags: try!(d.read_struct_field("rustflags", 6, decode)),
258266
})
259267
})
260268
}
@@ -346,6 +354,7 @@ fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
346354
deps: deps,
347355
local: local,
348356
memoized_hash: Mutex::new(None),
357+
rustflags: cx.rustflags_args(unit),
349358
});
350359
cx.fingerprints.insert(*unit, fingerprint.clone());
351360
Ok(fingerprint)
@@ -425,6 +434,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
425434
deps: Vec::new(),
426435
local: local,
427436
memoized_hash: Mutex::new(None),
437+
rustflags: Vec::new(),
428438
};
429439
let compare = compare_old_fingerprint(&loc, &fingerprint);
430440
log_compare(unit, &compare);

tests/test_cargo_compile.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,3 +2396,53 @@ test!(rustflags_plugin_dep_with_target {
23962396
.arg("--target").arg(host),
23972397
execs().with_status(0));
23982398
});
2399+
2400+
test!(rustflags_recompile {
2401+
let p = project("foo")
2402+
.file("Cargo.toml", r#"
2403+
[package]
2404+
name = "foo"
2405+
version = "0.0.1"
2406+
"#)
2407+
.file("src/lib.rs", "");
2408+
p.build();
2409+
2410+
assert_that(p.cargo("build"),
2411+
execs().with_status(0));
2412+
// Setting RUSTFLAGS forces a recompile
2413+
assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
2414+
execs().with_status(101));
2415+
});
2416+
2417+
test!(rustflags_recompile2 {
2418+
let p = project("foo")
2419+
.file("Cargo.toml", r#"
2420+
[package]
2421+
name = "foo"
2422+
version = "0.0.1"
2423+
"#)
2424+
.file("src/lib.rs", "");
2425+
p.build();
2426+
2427+
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
2428+
execs().with_status(0));
2429+
// Setting RUSTFLAGS forces a recompile
2430+
assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
2431+
execs().with_status(101));
2432+
});
2433+
2434+
test!(rustflags_no_recompile {
2435+
let p = project("foo")
2436+
.file("Cargo.toml", r#"
2437+
[package]
2438+
name = "foo"
2439+
version = "0.0.1"
2440+
"#)
2441+
.file("src/lib.rs", "");
2442+
p.build();
2443+
2444+
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
2445+
execs().with_status(0));
2446+
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
2447+
execs().with_stdout("").with_status(0));
2448+
});

0 commit comments

Comments
 (0)