From 4e9224895914a5a0119c0c1b4556e3a87de0b02f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 6 Nov 2024 18:43:04 +0800 Subject: [PATCH] feat: Use profile-generate to replace outdated -Zprofile options (#2282) --- .github/workflows/ci.yml | 2 +- .github/workflows/integration-tests.yml | 4 +-- src/compiler/c.rs | 2 +- src/compiler/rust.rs | 48 ++++++++++++------------- tests/sccache_cargo.rs | 20 ++++++++--- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5702aee9a..80cc237f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -302,7 +302,7 @@ jobs: env: CARGO_INCREMENTAL: "0" RUSTC_WRAPPER: "" - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off" + RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cprofile-generate=target/debug" - name: Generate coverage data (via `grcov`) id: coverage diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b71adc13f..d57794f12 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -1,5 +1,5 @@ name: integration-tests -on: [push, pull_request] +on: [ push, pull_request ] env: RUST_BACKTRACE: full @@ -812,7 +812,7 @@ jobs: env: RUSTC_WRAPPER: /home/runner/.cargo/bin/sccache CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" steps: diff --git a/src/compiler/c.rs b/src/compiler/c.rs index 8e390216c..43478490a 100644 --- a/src/compiler/c.rs +++ b/src/compiler/c.rs @@ -1325,7 +1325,7 @@ impl pkg::ToolchainPackager for CToolchainPackager { // files by path. let named_file = |kind: &str, name: &str| -> Option { let mut output = process::Command::new(&self.executable) - .arg(&format!("-print-{}-name={}", kind, name)) + .arg(format!("-print-{}-name={}", kind, name)) .output() .ok()?; debug!( diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index b9869c944..46aa227dd 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -159,8 +159,8 @@ pub struct ParsedArguments { crate_types: CrateTypes, /// If dependency info is being emitted, the name of the dep info file. dep_info: Option, - /// If gcno info is being emitted, the name of the gcno file. - gcno: Option, + /// If profile info is being emitted, the name of the profile file. + profile: Option, /// rustc says that emits .rlib for --emit=metadata /// https://github.com/rust-lang/rust/issues/54852 emit: HashSet, @@ -994,7 +994,6 @@ ArgData! { CodeGen(ArgCodegen), PassThrough(OsString), Target(ArgTarget), - Unstable(ArgUnstable), } use self::ArgData::*; @@ -1036,7 +1035,6 @@ counted_array!(static ARGS: [ArgInfo; _] = [ take_arg!("-L", ArgLinkPath, CanBeSeparated, LinkPath), flag!("-V", NotCompilationFlag), take_arg!("-W", OsString, CanBeSeparated, PassThrough), - take_arg!("-Z", ArgUnstable, CanBeSeparated, Unstable), take_arg!("-l", ArgLinkLibrary, CanBeSeparated, LinkLibrary), take_arg!("-o", PathBuf, CanBeSeparated, TooHardPath), ]); @@ -1114,6 +1112,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments extra_filename = Some(value.to_owned()), ("extra-filename", None) => cannot_cache!("extra-filename"), + ("profile-generate", Some(_)) => profile = true, // Incremental compilation makes a mess of sccache's entire world // view. It produces additional compiler outputs that we don't cache, // and just letting rustc do its work in incremental mode is likely @@ -1126,12 +1125,6 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments (), } } - Some(Unstable(ArgUnstable { opt, value })) => match value.as_deref() { - Some("y") | Some("yes") | Some("on") | None if opt == "profile" => { - profile = true; - } - _ => (), - }, Some(Color(value)) => { // We'll just assume the last specified value wins. color_mode = match value.as_ref() { @@ -1220,14 +1213,15 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments CompilerArguments Result<()> { test_rust_cargo_cmd( "check", - SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?, + SccacheTest::new(Some(&[( + "RUSTFLAGS", + OsString::from("-Cprofile-generate=."), + )]))?, ) } @@ -110,7 +113,10 @@ fn test_rust_cargo_check_nightly_readonly() -> Result<()> { test_rust_cargo_cmd_readonly( "check", - SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?, + SccacheTest::new(Some(&[( + "RUSTFLAGS", + OsString::from("-Cprofile-generate=."), + )]))?, ) } @@ -122,7 +128,10 @@ fn test_rust_cargo_build_nightly() -> Result<()> { test_rust_cargo_cmd( "build", - SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?, + SccacheTest::new(Some(&[( + "RUSTFLAGS", + OsString::from("-Cprofile-generate=."), + )]))?, ) } @@ -134,7 +143,10 @@ fn test_rust_cargo_build_nightly_readonly() -> Result<()> { test_rust_cargo_cmd_readonly( "build", - SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?, + SccacheTest::new(Some(&[( + "RUSTFLAGS", + OsString::from("-Cprofile-generate=."), + )]))?, ) }