Skip to content

Add rustc-link-args to doctest build #9916

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

Merged
merged 1 commit into from
Oct 14, 2021
Merged
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
14 changes: 10 additions & 4 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
@@ -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));
31 changes: 31 additions & 0 deletions tests/testsuite/build_script_extra_link_arg.rs
Original file line number Diff line number Diff line change
@@ -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();
}