Skip to content

Commit

Permalink
feat: Use profile-generate to replace outdated -Zprofile options (moz…
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored and trxcllnt committed Nov 14, 2024
1 parent 0e268bd commit 4e92248
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: integration-tests
on: [push, pull_request]
on: [ push, pull_request ]

env:
RUST_BACKTRACE: full
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ impl pkg::ToolchainPackager for CToolchainPackager {
// files by path.
let named_file = |kind: &str, name: &str| -> Option<PathBuf> {
let mut output = process::Command::new(&self.executable)
.arg(&format!("-print-{}-name={}", kind, name))
.arg(format!("-print-{}-name={}", kind, name))
.output()
.ok()?;
debug!(
Expand Down
48 changes: 22 additions & 26 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// If gcno info is being emitted, the name of the gcno file.
gcno: Option<PathBuf>,
/// If profile info is being emitted, the name of the profile file.
profile: Option<PathBuf>,
/// rustc says that emits .rlib for --emit=metadata
/// https://github.com/rust-lang/rust/issues/54852
emit: HashSet<String>,
Expand Down Expand Up @@ -994,7 +994,6 @@ ArgData! {
CodeGen(ArgCodegen),
PassThrough(OsString),
Target(ArgTarget),
Unstable(ArgUnstable),
}

use self::ArgData::*;
Expand Down Expand Up @@ -1036,7 +1035,6 @@ counted_array!(static ARGS: [ArgInfo<ArgData>; _] = [
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),
]);
Expand Down Expand Up @@ -1114,6 +1112,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
match (opt.as_ref(), value) {
("extra-filename", Some(value)) => 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
Expand All @@ -1126,12 +1125,6 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
(_, _) => (),
}
}
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() {
Expand Down Expand Up @@ -1220,14 +1213,15 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
None
};

// Figure out the gcno filename, if producing gcno files with `-Zprofile`.
let gcno = if profile && emit.contains("link") {
let mut gcno = crate_name.clone();
// Figure out the profile filename, if producing profile files with `-C profile-generate`.
let profile = if profile && emit.contains("link") {
let mut profile = crate_name.clone();
if let Some(extra_filename) = extra_filename {
gcno.push_str(&extra_filename[..]);
profile.push_str(&extra_filename[..]);
}
gcno.push_str(".gcno");
Some(gcno)
// LLVM will append ".profraw" to the filename.
profile.push_str(".profraw");
Some(profile)
} else {
None
};
Expand Down Expand Up @@ -1267,7 +1261,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
staticlibs,
crate_name,
dep_info: dep_info.map(|s| s.into()),
gcno: gcno.map(|s| s.into()),
profile: profile.map(|s| s.into()),
emit,
color_mode,
has_json,
Expand Down Expand Up @@ -1311,7 +1305,7 @@ where
dep_info,
emit,
has_json,
gcno,
profile,
..
},
} = *self;
Expand Down Expand Up @@ -1535,10 +1529,10 @@ where
} else {
None
};
if let Some(gcno) = gcno {
let p = output_dir.join(&gcno);
if let Some(profile) = profile {
let p = output_dir.join(&profile);
outputs.insert(
gcno.to_string_lossy().into_owned(),
profile.to_string_lossy().into_owned(),
ArtifactDescriptor {
path: p,
optional: true,
Expand Down Expand Up @@ -3224,7 +3218,7 @@ proc_macro false
emit,
color_mode: ColorMode::Auto,
has_json: false,
gcno: None,
profile: None,
},
});
let creator = new_creator();
Expand Down Expand Up @@ -3572,10 +3566,11 @@ proc_macro false
"--emit=dep-info,link",
"--out-dir",
"/out",
"-Zprofile"
"-C",
"profile-generate=."
);

assert_eq!(h.gcno, Some("foo.gcno".into()));
assert_eq!(h.profile, Some("foo.profraw".into()));

let h = parses!(
"--crate-name",
Expand All @@ -3588,9 +3583,10 @@ proc_macro false
"extra-filename=-a1b6419f8321841f",
"--out-dir",
"/out",
"-Zprofile"
"-C",
"profile-generate=."
);

assert_eq!(h.gcno, Some("foo-a1b6419f8321841f.gcno".into()));
assert_eq!(h.profile, Some("foo-a1b6419f8321841f.profraw".into()));
}
}
20 changes: 16 additions & 4 deletions tests/sccache_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ fn test_rust_cargo_check_nightly() -> Result<()> {

test_rust_cargo_cmd(
"check",
SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?,
SccacheTest::new(Some(&[(
"RUSTFLAGS",
OsString::from("-Cprofile-generate=."),
)]))?,
)
}

Expand All @@ -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=."),
)]))?,
)
}

Expand All @@ -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=."),
)]))?,
)
}

Expand All @@ -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=."),
)]))?,
)
}

Expand Down

0 comments on commit 4e92248

Please sign in to comment.