mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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:
commit
089cbb80b7
@ -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.
|
||||
|
@ -209,6 +209,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
|
||||
unit: unit.clone(),
|
||||
args,
|
||||
unstable_opts,
|
||||
linker: self.bcx.linker(unit.kind),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 &[
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user