mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
Add rustc-link-args to doctest build
This commit is contained in:
parent
4a166de89f
commit
2fabe52ccd
|
@ -2,15 +2,14 @@ use std::collections::{BTreeSet, HashMap, HashSet};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use anyhow::{bail, Context as _};
|
||||
use filetime::FileTime;
|
||||
use jobserver::Client;
|
||||
|
||||
use crate::core::compiler::compilation::{self, UnitOutput};
|
||||
use crate::core::compiler::{self, Unit};
|
||||
use crate::core::PackageId;
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::profile;
|
||||
use anyhow::{bail, Context as _};
|
||||
use filetime::FileTime;
|
||||
use jobserver::Client;
|
||||
|
||||
use super::build_plan::BuildPlan;
|
||||
use super::custom_build::{self, BuildDeps, BuildScriptOutputs, BuildScripts};
|
||||
|
@ -241,6 +240,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
|
|||
args.push("--cfg".into());
|
||||
args.push(cfg.into());
|
||||
}
|
||||
|
||||
for (lt, arg) in &output.linker_args {
|
||||
if lt.applies_to(&unit.target) {
|
||||
args.push("-C".into());
|
||||
args.push(format!("link-arg={}", arg).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
args.extend(self.bcx.rustdocflags_args(unit).iter().map(Into::into));
|
||||
|
|
|
@ -279,3 +279,34 @@ fn link_arg_transitive_not_allowed() {
|
|||
.with_stderr_does_not_contain("--bogus")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn link_arg_with_doctest() {
|
||||
let p = project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
//! ```
|
||||
//! let x = 5;
|
||||
//! assert_eq!(x, 5);
|
||||
//! ```
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"build.rs",
|
||||
r#"
|
||||
fn main() {
|
||||
println!("cargo:rustc-link-arg=--this-is-a-bogus-flag");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("test --doc -v")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.without_status()
|
||||
.with_stderr_contains(
|
||||
"[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue