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.
This commit is contained in:
bors 2020-06-15 14:38:34 +00:00
commit 089cbb80b7
4 changed files with 58 additions and 0 deletions

View File

@ -20,6 +20,8 @@ pub struct Doctest {
pub args: Vec<OsString>,
/// Whether or not -Zunstable-options is needed.
pub unstable_opts: bool,
/// The -Clinker value to use.
pub linker: Option<PathBuf>,
}
/// A structure returning the result of a compilation.

View File

@ -209,6 +209,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
unit: unit.clone(),
args,
unstable_opts,
linker: self.bcx.linker(unit.kind),
});
}

View File

@ -144,6 +144,7 @@ fn run_doc_tests(
args,
unstable_opts,
unit,
linker,
} = doctest_info;
if !doctest_xcompile {
@ -178,6 +179,11 @@ fn run_doc_tests(
p.arg("--runtool-arg").arg(arg);
}
}
if let Some(linker) = linker {
let mut joined = OsString::from("linker=");
joined.push(linker);
p.arg("-C").arg(joined);
}
}
for &rust_dep in &[

View File

@ -1067,3 +1067,52 @@ fn cross_test_dylib() {
.with_stdout_contains_n("test foo ... ok", 2)
.run();
}
#[cargo_test]
fn doctest_xcompile_linker() {
if cross_compile::disabled() {
return;
}
if !is_nightly() {
// -Zdoctest-xcompile is unstable
return;
}
let target = cross_compile::alternate();
let p = project()
.file(
".cargo/config",
&format!(
r#"
[target.{}]
linker = "my-linker-tool"
"#,
target
),
)
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file(
"src/lib.rs",
r#"
/// ```
/// assert_eq!(1, 1);
/// ```
pub fn foo() {}
"#,
)
.build();
// Fails because `my-linker-tool` doesn't actually exist.
p.cargo("test --doc -v -Zdoctest-xcompile --target")
.arg(&target)
.with_status(101)
.masquerade_as_nightly_cargo()
.with_stderr_contains(&format!(
"\
[RUNNING] `rustdoc --crate-type lib --test [..]\
--target {target} [..] -C linker=my-linker-tool[..]
",
target = target,
))
.run();
}