Skip to content

Commit b4476d7

Browse files
committed
Support linker with -Zdoctest-xcompile.
1 parent 79c769c commit b4476d7

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct Doctest {
2020
pub args: Vec<OsString>,
2121
/// Whether or not -Zunstable-options is needed.
2222
pub unstable_opts: bool,
23+
/// The -Clinker value to use.
24+
pub linker: Option<PathBuf>,
2325
}
2426

2527
/// A structure returning the result of a compilation.

src/cargo/core/compiler/context/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
209209
unit: unit.clone(),
210210
args,
211211
unstable_opts,
212+
linker: self.bcx.linker(unit.kind),
212213
});
213214
}
214215

src/cargo/ops/cargo_test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fn run_doc_tests(
143143
args,
144144
unstable_opts,
145145
unit,
146+
linker,
146147
} = doctest_info;
147148

148149
// Skip any `--target` tests unless `doctest-xcompile` is specified.
@@ -170,6 +171,11 @@ fn run_doc_tests(
170171
p.arg("--runtool-arg").arg(arg);
171172
}
172173
}
174+
if let Some(linker) = linker {
175+
let mut joined = OsString::from("linker=");
176+
joined.push(linker);
177+
p.arg("-C").arg(joined);
178+
}
173179
}
174180

175181
for &rust_dep in &[

tests/testsuite/cross_compile.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,3 +1066,52 @@ fn cross_test_dylib() {
10661066
.with_stdout_contains_n("test foo ... ok", 2)
10671067
.run();
10681068
}
1069+
1070+
#[cargo_test]
1071+
fn doctest_xcompile_linker() {
1072+
if cross_compile::disabled() {
1073+
return;
1074+
}
1075+
if !is_nightly() {
1076+
// -Zdoctest-xcompile is unstable
1077+
return;
1078+
}
1079+
1080+
let target = cross_compile::alternate();
1081+
let p = project()
1082+
.file(
1083+
".cargo/config",
1084+
&format!(
1085+
r#"
1086+
[target.{}]
1087+
linker = "my-linker-tool"
1088+
"#,
1089+
target
1090+
),
1091+
)
1092+
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
1093+
.file(
1094+
"src/lib.rs",
1095+
r#"
1096+
/// ```
1097+
/// assert_eq!(1, 1);
1098+
/// ```
1099+
pub fn foo() {}
1100+
"#,
1101+
)
1102+
.build();
1103+
1104+
// Fails because `my-linker-tool` doesn't actually exist.
1105+
p.cargo("test --doc -v -Zdoctest-xcompile --target")
1106+
.arg(&target)
1107+
.with_status(101)
1108+
.masquerade_as_nightly_cargo()
1109+
.with_stderr_contains(&format!(
1110+
"\
1111+
[RUNNING] `rustdoc --crate-type lib --test [..]\
1112+
--target {target} [..] -C linker=my-linker-tool[..]
1113+
",
1114+
target = target,
1115+
))
1116+
.run();
1117+
}

0 commit comments

Comments
 (0)