Skip to content

Commit 1941dfe

Browse files
Merge pull request #20804 from itsjunetime/run_correct_pgo_r-a
Build rust-analyzer with `--target` for install/pgo xtask
2 parents 11e29a4 + 359a91e commit 1941dfe

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

xtask/src/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> {
145145
);
146146

147147
if let Some(train_crate) = opts.pgo {
148+
let target = detect_target(sh);
148149
let build_cmd = cmd!(
149150
sh,
150-
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --profile={profile} --locked --features force-always-assert {features...}"
151+
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --profile={profile} --locked --features force-always-assert {features...}"
151152
);
152153

153-
let target = detect_target(sh);
154154
let profile = crate::pgo::gather_pgo_profile(sh, build_cmd, &target, train_crate)?;
155155
install_cmd = crate::pgo::apply_pgo_to_cmd(install_cmd, &profile);
156156
}

xtask/src/pgo.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ pub(crate) fn gather_pgo_profile<'a>(
5353

5454
// Merge profiles into a single file
5555
let merged_profile = pgo_dir.join("merged.profdata");
56-
let profile_files = std::fs::read_dir(pgo_dir)?.filter_map(|entry| {
57-
let entry = entry.ok()?;
58-
if entry.path().extension() == Some(OsStr::new("profraw")) {
59-
Some(entry.path().to_str().unwrap().to_owned())
60-
} else {
61-
None
62-
}
63-
});
56+
let profile_files = std::fs::read_dir(pgo_dir)?
57+
.filter_map(|entry| {
58+
let entry = entry.ok()?;
59+
if entry.path().extension() == Some(OsStr::new("profraw")) {
60+
Some(entry.path().to_str().unwrap().to_owned())
61+
} else {
62+
None
63+
}
64+
})
65+
.collect::<Vec<_>>();
66+
67+
if profile_files.is_empty() {
68+
anyhow::bail!(
69+
"rust-analyzer analysis-stats produced no pgo files. This is a bug in rust-analyzer; please file an issue."
70+
);
71+
}
72+
6473
cmd!(sh, "{llvm_profdata} merge {profile_files...} -o {merged_profile}").run().context(
6574
"cannot merge PGO profiles. Do you have the rustup `llvm-tools` component installed?",
6675
)?;

0 commit comments

Comments
 (0)