Skip to content

Commit

Permalink
Support linker with -Zdoctest-xcompile.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 14, 2020
1 parent 79c769c commit b4476d7
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 @@ -143,6 +143,7 @@ fn run_doc_tests(
args,
unstable_opts,
unit,
linker,
} = doctest_info;

// Skip any `--target` tests unless `doctest-xcompile` is specified.
Expand Down Expand Up @@ -170,6 +171,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 @@ -1066,3 +1066,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 b4476d7

Please sign in to comment.