Skip to content

Commit 652a841

Browse files
committed
feat: support target.triple.rustdocflags officially
`CARGO_TARGET_<TRIPLE>_RUSTDOCFLAGS` was accidentally accepted somehow, so support both config and env officially, given that removing env support would be a breaking change.
1 parent 44c69d8 commit 652a841

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,6 @@ fn rustflags_from_target(
800800
.as_ref()
801801
.map(|rustflags| (key, &rustflags.val)),
802802
// `target.cfg(…).rustdocflags` is currently not supported.
803-
// In fact, neither is `target.<triple>.rustdocflags`.
804803
Flags::Rustdoc => None,
805804
}
806805
})

src/cargo/util/config/target.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub struct TargetConfig {
2727
pub runner: OptValue<PathAndArgs>,
2828
/// Additional rustc flags to pass.
2929
pub rustflags: OptValue<StringList>,
30+
/// Additional rustdoc flags to pass.
31+
pub rustdocflags: OptValue<StringList>,
3032
/// The path of the linker for this target.
3133
pub linker: OptValue<ConfigRelativePath>,
3234
/// Build script override for the given library name.
@@ -98,6 +100,7 @@ pub(super) fn load_host_triple(gctx: &GlobalContext, triple: &str) -> CargoResul
98100
Ok(TargetConfig {
99101
runner: None,
100102
rustflags: None,
103+
rustdocflags: None,
101104
linker: None,
102105
links_overrides: BTreeMap::new(),
103106
})
@@ -118,6 +121,7 @@ fn load_config_table(gctx: &GlobalContext, prefix: &str) -> CargoResult<TargetCo
118121
// environment variables would not work.
119122
let runner: OptValue<PathAndArgs> = gctx.get(&format!("{}.runner", prefix))?;
120123
let rustflags: OptValue<StringList> = gctx.get(&format!("{}.rustflags", prefix))?;
124+
let rustdocflags: OptValue<StringList> = gctx.get(&format!("{}.rustdocflags", prefix))?;
121125
let linker: OptValue<ConfigRelativePath> = gctx.get(&format!("{}.linker", prefix))?;
122126
// Links do not support environment variables.
123127
let target_key = ConfigKey::from_str(prefix);
@@ -128,6 +132,7 @@ fn load_config_table(gctx: &GlobalContext, prefix: &str) -> CargoResult<TargetCo
128132
Ok(TargetConfig {
129133
runner,
130134
rustflags,
135+
rustdocflags,
131136
linker,
132137
links_overrides,
133138
})
@@ -144,7 +149,7 @@ fn parse_links_overrides(
144149
// Skip these keys, it shares the namespace with `TargetConfig`.
145150
match lib_name.as_str() {
146151
// `ar` is a historical thing.
147-
"ar" | "linker" | "runner" | "rustflags" => continue,
152+
"ar" | "linker" | "runner" | "rustflags" | "rustdocflags" => continue,
148153
_ => {}
149154
}
150155
let mut output = BuildOutput::default();

tests/testsuite/rustdocflags.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,10 @@ fn target_triple_rustdocflags_works() {
177177
.with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`")
178178
.run();
179179

180-
// target.triple.rustdocflags in config is not supported.
180+
// target.triple.rustdocflags in config works
181181
p.cargo("doc -v")
182182
.arg("--config")
183183
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
184-
.with_status(101)
185-
.with_stderr(format!(
186-
"[ERROR] expected a table, but found a array for `target.{host}.rustdocflags` in --config cli option"
187-
))
184+
.with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`")
188185
.run();
189186
}

0 commit comments

Comments
 (0)