Skip to content

Commit f4da228

Browse files
authored
feat: Use profile-generate to replace outdated -Zprofile options (#2282)
1 parent e6df56d commit f4da228

6 files changed

Lines changed: 42 additions & 35 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239
env:
240240
CARGO_INCREMENTAL: "0"
241241
RUSTC_WRAPPER: ""
242-
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"
242+
RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cprofile-generate=target/debug"
243243

244244
- name: Generate coverage data (via `grcov`)
245245
id: coverage

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: integration-tests
2-
on: [push, pull_request]
2+
on: [ push, pull_request ]
33

44
env:
55
RUST_BACKTRACE: full
@@ -812,7 +812,7 @@ jobs:
812812
env:
813813
RUSTC_WRAPPER: /home/runner/.cargo/bin/sccache
814814
CARGO_INCREMENTAL: "0"
815-
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
815+
RUSTFLAGS: "-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
816816
RUSTDOCFLAGS: "-Cpanic=abort"
817817

818818
steps:

src/compiler/c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl pkg::ToolchainPackager for CToolchainPackager {
12631263
// files by path.
12641264
let named_file = |kind: &str, name: &str| -> Option<PathBuf> {
12651265
let mut output = process::Command::new(&self.executable)
1266-
.arg(&format!("-print-{}-name={}", kind, name))
1266+
.arg(format!("-print-{}-name={}", kind, name))
12671267
.output()
12681268
.ok()?;
12691269
debug!(

src/compiler/rust.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub struct ParsedArguments {
159159
crate_types: CrateTypes,
160160
/// If dependency info is being emitted, the name of the dep info file.
161161
dep_info: Option<PathBuf>,
162-
/// If gcno info is being emitted, the name of the gcno file.
163-
gcno: Option<PathBuf>,
162+
/// If profile info is being emitted, the name of the profile file.
163+
profile: Option<PathBuf>,
164164
/// rustc says that emits .rlib for --emit=metadata
165165
/// https://github.com/rust-lang/rust/issues/54852
166166
emit: HashSet<String>,
@@ -994,7 +994,6 @@ ArgData! {
994994
CodeGen(ArgCodegen),
995995
PassThrough(OsString),
996996
Target(ArgTarget),
997-
Unstable(ArgUnstable),
998997
}
999998

1000999
use self::ArgData::*;
@@ -1036,7 +1035,6 @@ counted_array!(static ARGS: [ArgInfo<ArgData>; _] = [
10361035
take_arg!("-L", ArgLinkPath, CanBeSeparated, LinkPath),
10371036
flag!("-V", NotCompilationFlag),
10381037
take_arg!("-W", OsString, CanBeSeparated, PassThrough),
1039-
take_arg!("-Z", ArgUnstable, CanBeSeparated, Unstable),
10401038
take_arg!("-l", ArgLinkLibrary, CanBeSeparated, LinkLibrary),
10411039
take_arg!("-o", PathBuf, CanBeSeparated, TooHardPath),
10421040
]);
@@ -1114,6 +1112,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
11141112
match (opt.as_ref(), value) {
11151113
("extra-filename", Some(value)) => extra_filename = Some(value.to_owned()),
11161114
("extra-filename", None) => cannot_cache!("extra-filename"),
1115+
("profile-generate", Some(_)) => profile = true,
11171116
// Incremental compilation makes a mess of sccache's entire world
11181117
// view. It produces additional compiler outputs that we don't cache,
11191118
// and just letting rustc do its work in incremental mode is likely
@@ -1126,12 +1125,6 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
11261125
(_, _) => (),
11271126
}
11281127
}
1129-
Some(Unstable(ArgUnstable { opt, value })) => match value.as_deref() {
1130-
Some("y") | Some("yes") | Some("on") | None if opt == "profile" => {
1131-
profile = true;
1132-
}
1133-
_ => (),
1134-
},
11351128
Some(Color(value)) => {
11361129
// We'll just assume the last specified value wins.
11371130
color_mode = match value.as_ref() {
@@ -1220,14 +1213,15 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
12201213
None
12211214
};
12221215

1223-
// Figure out the gcno filename, if producing gcno files with `-Zprofile`.
1224-
let gcno = if profile && emit.contains("link") {
1225-
let mut gcno = crate_name.clone();
1216+
// Figure out the profile filename, if producing profile files with `-C profile-generate`.
1217+
let profile = if profile && emit.contains("link") {
1218+
let mut profile = crate_name.clone();
12261219
if let Some(extra_filename) = extra_filename {
1227-
gcno.push_str(&extra_filename[..]);
1220+
profile.push_str(&extra_filename[..]);
12281221
}
1229-
gcno.push_str(".gcno");
1230-
Some(gcno)
1222+
// LLVM will append ".profraw" to the filename.
1223+
profile.push_str(".profraw");
1224+
Some(profile)
12311225
} else {
12321226
None
12331227
};
@@ -1267,7 +1261,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
12671261
staticlibs,
12681262
crate_name,
12691263
dep_info: dep_info.map(|s| s.into()),
1270-
gcno: gcno.map(|s| s.into()),
1264+
profile: profile.map(|s| s.into()),
12711265
emit,
12721266
color_mode,
12731267
has_json,
@@ -1311,7 +1305,7 @@ where
13111305
dep_info,
13121306
emit,
13131307
has_json,
1314-
gcno,
1308+
profile,
13151309
..
13161310
},
13171311
} = *self;
@@ -1535,10 +1529,10 @@ where
15351529
} else {
15361530
None
15371531
};
1538-
if let Some(gcno) = gcno {
1539-
let p = output_dir.join(&gcno);
1532+
if let Some(profile) = profile {
1533+
let p = output_dir.join(&profile);
15401534
outputs.insert(
1541-
gcno.to_string_lossy().into_owned(),
1535+
profile.to_string_lossy().into_owned(),
15421536
ArtifactDescriptor {
15431537
path: p,
15441538
optional: true,
@@ -3213,7 +3207,7 @@ proc_macro false
32133207
emit,
32143208
color_mode: ColorMode::Auto,
32153209
has_json: false,
3216-
gcno: None,
3210+
profile: None,
32173211
},
32183212
});
32193213
let creator = new_creator();
@@ -3561,10 +3555,11 @@ proc_macro false
35613555
"--emit=dep-info,link",
35623556
"--out-dir",
35633557
"/out",
3564-
"-Zprofile"
3558+
"-C",
3559+
"profile-generate=."
35653560
);
35663561

3567-
assert_eq!(h.gcno, Some("foo.gcno".into()));
3562+
assert_eq!(h.profile, Some("foo.profraw".into()));
35683563

35693564
let h = parses!(
35703565
"--crate-name",
@@ -3577,9 +3572,10 @@ proc_macro false
35773572
"extra-filename=-a1b6419f8321841f",
35783573
"--out-dir",
35793574
"/out",
3580-
"-Zprofile"
3575+
"-C",
3576+
"profile-generate=."
35813577
);
35823578

3583-
assert_eq!(h.gcno, Some("foo-a1b6419f8321841f.gcno".into()));
3579+
assert_eq!(h.profile, Some("foo-a1b6419f8321841f.profraw".into()));
35843580
}
35853581
}

src/server.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use std::task::{Context, Poll, Waker};
5656
use std::time::Duration;
5757
#[cfg(feature = "dist-client")]
5858
use std::time::Instant;
59-
use std::u64;
6059
use tokio::sync::Mutex;
6160
use tokio::sync::RwLock;
6261
use tokio::{

tests/sccache_cargo.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ fn test_rust_cargo_check_nightly() -> Result<()> {
9898

9999
test_rust_cargo_cmd(
100100
"check",
101-
SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?,
101+
SccacheTest::new(Some(&[(
102+
"RUSTFLAGS",
103+
OsString::from("-Cprofile-generate=."),
104+
)]))?,
102105
)
103106
}
104107

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

111114
test_rust_cargo_cmd_readonly(
112115
"check",
113-
SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?,
116+
SccacheTest::new(Some(&[(
117+
"RUSTFLAGS",
118+
OsString::from("-Cprofile-generate=."),
119+
)]))?,
114120
)
115121
}
116122

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

123129
test_rust_cargo_cmd(
124130
"build",
125-
SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?,
131+
SccacheTest::new(Some(&[(
132+
"RUSTFLAGS",
133+
OsString::from("-Cprofile-generate=."),
134+
)]))?,
126135
)
127136
}
128137

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

135144
test_rust_cargo_cmd_readonly(
136145
"build",
137-
SccacheTest::new(Some(&[("RUSTFLAGS", OsString::from("-Zprofile"))]))?,
146+
SccacheTest::new(Some(&[(
147+
"RUSTFLAGS",
148+
OsString::from("-Cprofile-generate=."),
149+
)]))?,
138150
)
139151
}
140152

0 commit comments

Comments
 (0)