Skip to content

Commit 208a7ad

Browse files
Add a general mechanism for setting rustflags in Cargo that only applies to the current crate. Add tests to ensure --rustflags options are only set for the current crate and not any dependencies.
1 parent 646e9a0 commit 208a7ad

File tree

18 files changed

+459
-4
lines changed

18 files changed

+459
-4
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub fn cli() -> App {
4848
))
4949
.arg_unit_graph()
5050
.arg_timings()
51+
.arg_rustflags()
5152
.after_help("Run `cargo help bench` for more detailed information.\n")
5253
}
5354

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn cli() -> App {
4545
.arg_unit_graph()
4646
.arg_future_incompat_report()
4747
.arg_timings()
48+
.arg_rustflags()
4849
.after_help("Run `cargo help build` for more detailed information.\n")
4950
}
5051

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn cli() -> App {
3737
.arg_unit_graph()
3838
.arg_future_incompat_report()
3939
.arg_timings()
40+
.arg_rustflags()
4041
.after_help("Run `cargo help check` for more detailed information.\n")
4142
}
4243

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn cli() -> App {
4040
.arg_ignore_rust_version()
4141
.arg_unit_graph()
4242
.arg_timings()
43+
.arg_rustflags()
4344
.after_help("Run `cargo help doc` for more detailed information.\n")
4445
}
4546

src/bin/cargo/commands/fix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn cli() -> App {
5454
))
5555
.arg_ignore_rust_version()
5656
.arg_timings()
57+
.arg_rustflags()
5758
.after_help("Run `cargo help fix` for more detailed information.\n")
5859
}
5960

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn cli() -> App {
8282
)
8383
.arg_message_format()
8484
.arg_timings()
85+
.arg_rustflags()
8586
.after_help("Run `cargo help install` for more detailed information.\n")
8687
}
8788

src/bin/cargo/commands/package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn cli() -> App {
3535
)
3636
.arg_manifest_path()
3737
.arg_jobs()
38+
.arg_rustflags()
3839
.after_help("Run `cargo help package` for more detailed information.\n")
3940
}
4041

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn cli() -> App {
3232
.arg_unit_graph()
3333
.arg_ignore_rust_version()
3434
.arg_timings()
35+
.arg_rustflags()
3536
.after_help("Run `cargo help run` for more detailed information.\n")
3637
}
3738

src/bin/cargo/commands/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub fn cli() -> App {
5656
.arg_unit_graph()
5757
.arg_future_incompat_report()
5858
.arg_timings()
59+
.arg_rustflags()
5960
.after_help(
6061
"Run `cargo help test` for more detailed information.\n\
6162
Run `cargo test -- --help` for test binary options.\n",

src/cargo/core/compiler/fingerprint.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,13 +1302,16 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
13021302
// Fill out a bunch more information that we'll be tracking typically
13031303
// hashed to take up less space on disk as we just need to know when things
13041304
// change.
1305-
let extra_flags = if unit.mode.is_doc() {
1305+
let mut rustflags = if unit.mode.is_doc() {
13061306
cx.bcx.rustdocflags_args(unit)
13071307
} else {
13081308
cx.bcx.rustflags_args(unit)
13091309
}
13101310
.to_vec();
13111311

1312+
// Append the command line user specified RUSTFLAGS to the env var or config RUSTFLAGS.
1313+
rustflags.extend(unit.rustflags.iter().map(InternedString::to_string));
1314+
13121315
let profile_hash = util::hash_u64((
13131316
&unit.profile,
13141317
unit.mode,
@@ -1345,7 +1348,7 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
13451348
metadata,
13461349
config: config.finish(),
13471350
compile_kind,
1348-
rustflags: extra_flags,
1351+
rustflags,
13491352
fs_status: FsStatus::Stale,
13501353
outputs,
13511354
})

0 commit comments

Comments
 (0)