Skip to content

Commit 2fabe52

Browse files
committed
Add rustc-link-args to doctest build
1 parent 4a166de commit 2fabe52

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

Diff for: src/cargo/core/compiler/context/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ use std::collections::{BTreeSet, HashMap, HashSet};
22
use std::path::{Path, PathBuf};
33
use std::sync::{Arc, Mutex};
44

5-
use anyhow::{bail, Context as _};
6-
use filetime::FileTime;
7-
use jobserver::Client;
8-
95
use crate::core::compiler::compilation::{self, UnitOutput};
106
use crate::core::compiler::{self, Unit};
117
use crate::core::PackageId;
128
use crate::util::errors::CargoResult;
139
use crate::util::profile;
10+
use anyhow::{bail, Context as _};
11+
use filetime::FileTime;
12+
use jobserver::Client;
1413

1514
use super::build_plan::BuildPlan;
1615
use super::custom_build::{self, BuildDeps, BuildScriptOutputs, BuildScripts};
@@ -241,6 +240,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
241240
args.push("--cfg".into());
242241
args.push(cfg.into());
243242
}
243+
244+
for (lt, arg) in &output.linker_args {
245+
if lt.applies_to(&unit.target) {
246+
args.push("-C".into());
247+
args.push(format!("link-arg={}", arg).into());
248+
}
249+
}
244250
}
245251
}
246252
args.extend(self.bcx.rustdocflags_args(unit).iter().map(Into::into));

Diff for: tests/testsuite/build_script_extra_link_arg.rs

+31
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,34 @@ fn link_arg_transitive_not_allowed() {
279279
.with_stderr_does_not_contain("--bogus")
280280
.run();
281281
}
282+
283+
#[cargo_test]
284+
fn link_arg_with_doctest() {
285+
let p = project()
286+
.file(
287+
"src/lib.rs",
288+
r#"
289+
//! ```
290+
//! let x = 5;
291+
//! assert_eq!(x, 5);
292+
//! ```
293+
"#,
294+
)
295+
.file(
296+
"build.rs",
297+
r#"
298+
fn main() {
299+
println!("cargo:rustc-link-arg=--this-is-a-bogus-flag");
300+
}
301+
"#,
302+
)
303+
.build();
304+
305+
p.cargo("test --doc -v")
306+
.masquerade_as_nightly_cargo()
307+
.without_status()
308+
.with_stderr_contains(
309+
"[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
310+
)
311+
.run();
312+
}

0 commit comments

Comments
 (0)