Skip to content

Commit

Permalink
Auto merge of #9916 - chansuke:issue-9895, r=ehuss
Browse files Browse the repository at this point in the history
Add rustc-link-args to doctest build

Fix #9895
  • Loading branch information
bors committed Oct 14, 2021
2 parents c8b38af + 2fabe52 commit bd6a512
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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));
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/build_script_extra_link_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit bd6a512

Please sign in to comment.