Skip to content

Commit

Permalink
Auto merge of #8359 - ehuss:doctest-xcompile-linker, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jun 15, 2020
2 parents 4e14cc1 + b4476d7 commit 089cbb8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
unit: unit.clone(),
args,
unstable_opts,
linker: self.bcx.linker(unit.kind),
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn run_doc_tests(
args,
unstable_opts,
unit,
linker,
} = doctest_info;

if !doctest_xcompile {
Expand Down Expand Up @@ -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 &[
Expand Down
49 changes: 49 additions & 0 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 089cbb8

Please sign in to comment.