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

Pass --instrprof-atomic-counter-update-all only on old rustc #296

Merged
merged 1 commit into from
Aug 6, 2023
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
34 changes: 25 additions & 9 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) struct Workspace {
rustc: ProcessBuilder,
pub(crate) target_for_config: cargo_config2::TargetTriple,
pub(crate) target_for_cli: Option<String>,
pub(crate) nightly: bool,
pub(crate) rustc_version: RustcVersion,
/// Whether `-C instrument-coverage` is available.
pub(crate) stable_coverage: bool,
/// Whether `-Z doctest-in-workspace` is needed.
Expand All @@ -50,14 +50,14 @@ impl Workspace {
let target_for_config = target_for_config.pop().unwrap();
let target_for_cli = config.build_target_for_cli(target)?.pop();
let rustc = ProcessBuilder::from(config.rustc().clone());
let nightly = rustc_version(&rustc)?;
let rustc_version = rustc_version(&rustc)?;

if doctests && !nightly {
if doctests && !rustc_version.nightly {
bail!("--doctests flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`")
}
let stable_coverage =
rustc.clone().args(["-C", "help"]).read()?.contains("instrument-coverage");
if !stable_coverage && !nightly {
if !stable_coverage && !rustc_version.nightly {
bail!(
"cargo-llvm-cov requires rustc 1.60+; consider updating toolchain (`rustup update`)
or using nightly toolchain (`cargo +nightly llvm-cov`)"
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Workspace {
rustc,
target_for_config,
target_for_cli,
nightly,
rustc_version,
stable_coverage,
need_doctest_in_workspace,
})
Expand Down Expand Up @@ -146,17 +146,33 @@ impl Workspace {
}
}

fn rustc_version(rustc: &ProcessBuilder) -> Result<bool> {
pub(crate) struct RustcVersion {
pub(crate) minor: u32,
pub(crate) nightly: bool,
}

fn rustc_version(rustc: &ProcessBuilder) -> Result<RustcVersion> {
let mut cmd = rustc.clone();
cmd.args(["--version", "--verbose"]);
let verbose_version = cmd.read()?;
let version = verbose_version
let release = verbose_version
.lines()
.find_map(|line| line.strip_prefix("release: "))
.ok_or_else(|| format_err!("unexpected version output from `{cmd}`: {verbose_version}"))?;
let (_version, channel) = version.split_once('-').unwrap_or_default();
let (version, channel) = release.split_once('-').unwrap_or_default();
let mut digits = version.splitn(3, '.');
let minor = (|| {
let major = digits.next()?.parse::<u32>().ok()?;
if major != 1 {
return None;
}
let minor = digits.next()?.parse::<u32>().ok()?;
let _patch = digits.next().unwrap_or("0").parse::<u32>().ok()?;
Some(minor)
})()
.ok_or_else(|| format_err!("unable to determine rustc version"))?;
let nightly = channel == "nightly" || channel == "dev";
Ok(nightly)
Ok(RustcVersion { minor, nightly })
}

fn package_root(cargo: &OsStr, manifest_path: Option<&Utf8Path>) -> Result<Utf8PathBuf> {
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,18 @@ fn set_env(cx: &Context, env: &mut dyn EnvTarget, IsNextest(is_nextest): IsNexte
flags.push("codegen-units=1");
}
}
// Workaround for https://github.com/rust-lang/rust/issues/91092
// TODO: skip passing this on newer nightly that includes https://github.com/rust-lang/rust/pull/111469.
flags.push("-C");
flags.push("llvm-args=--instrprof-atomic-counter-update-all");
// Workaround for https://github.com/rust-lang/rust/issues/91092.
// Unnecessary since https://github.com/rust-lang/rust/pull/111469.
if cx.ws.rustc_version.nightly && cx.ws.rustc_version.minor <= 71
|| !cx.ws.rustc_version.nightly && cx.ws.rustc_version.minor < 71
{
flags.push("-C");
flags.push("llvm-args=--instrprof-atomic-counter-update-all");
}
if !cx.args.cov.no_cfg_coverage {
flags.push("--cfg=coverage");
}
if cx.ws.nightly && !cx.args.cov.no_cfg_coverage_nightly {
if cx.ws.rustc_version.nightly && !cx.args.cov.no_cfg_coverage_nightly {
flags.push("--cfg=coverage_nightly");
}
}
Expand Down