Skip to content

Commit

Permalink
Revert "feat: Use profile-generate to replace outdated -Zprofile opti…
Browse files Browse the repository at this point in the history
…ons (#2282)"

This reverts commit f4da228.
  • Loading branch information
sylvestre authored Dec 19, 2024
1 parent f3cf79a commit 7d126f8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ jobs:
env:
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: ""
RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cprofile-generate=target/debug"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"

- 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: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
RUSTFLAGS: "-Zprofile -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 @@ -1311,7 +1311,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: 26 additions & 22 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,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 profile info is being emitted, the name of the profile file.
profile: Option<PathBuf>,
/// If gcno info is being emitted, the name of the gcno file.
gcno: 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 @@ -996,6 +996,7 @@ ArgData! {
CodeGen(ArgCodegen),
PassThrough(OsString),
Target(ArgTarget),
Unstable(ArgUnstable),
}

use self::ArgData::*;
Expand Down Expand Up @@ -1037,6 +1038,7 @@ 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,7 +1116,6 @@ 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 @@ -1127,6 +1128,12 @@ 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 @@ -1215,15 +1222,14 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
None
};

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

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

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

assert_eq!(h.profile, Some("foo-a1b6419f8321841f.profraw".into()));
assert_eq!(h.gcno, Some("foo-a1b6419f8321841f.gcno".into()));
}
}
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use std::task::{Context, Poll, Waker};
use std::time::Duration;
#[cfg(feature = "dist-client")]
use std::time::Instant;
use std::u64;
use tokio::sync::Mutex;
use tokio::sync::RwLock;
use tokio::{
Expand Down
20 changes: 4 additions & 16 deletions tests/sccache_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ fn test_rust_cargo_check_nightly() -> Result<()> {

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

Expand All @@ -113,10 +110,7 @@ fn test_rust_cargo_check_nightly_readonly() -> Result<()> {

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

Expand All @@ -128,10 +122,7 @@ fn test_rust_cargo_build_nightly() -> Result<()> {

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

Expand All @@ -143,10 +134,7 @@ fn test_rust_cargo_build_nightly_readonly() -> Result<()> {

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

Expand Down

0 comments on commit 7d126f8

Please sign in to comment.