Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support linker with -Zdoctest-xcompile. #8359

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}