Skip to content

Commit 089cbb8

Browse files
committed
Auto merge of #8359 - ehuss:doctest-xcompile-linker, r=alexcrichton
Support linker with -Zdoctest-xcompile. This adds support for `-Clinker` with `-Zdoctest-xcompile`. I'm not entirely sure how `-Zdoctest-xcompile` was supposed to work without setting the linker. I tested this with std on arm-unknown-linux-gnueabihf with qemu. It seems to work (although it was quite slow). Closes #7529.
2 parents 4e14cc1 + b4476d7 commit 089cbb8

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
@@ -144,6 +144,7 @@ fn run_doc_tests(
144144
args,
145145
unstable_opts,
146146
unit,
147+
linker,
147148
} = doctest_info;
148149

149150
if !doctest_xcompile {
@@ -178,6 +179,11 @@ fn run_doc_tests(
178179
p.arg("--runtool-arg").arg(arg);
179180
}
180181
}
182+
if let Some(linker) = linker {
183+
let mut joined = OsString::from("linker=");
184+
joined.push(linker);
185+
p.arg("-C").arg(joined);
186+
}
181187
}
182188

183189
for &rust_dep in &[

tests/testsuite/cross_compile.rs

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

0 commit comments

Comments
 (0)