Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl CommandLineStep for CrateBootstrap {
// By default, it will test all of them, but requesting specific tools on the command-line
// (e.g. `./x test src/tools/coverage-dump`) will test only the specified tools.
run.path("src/tools/jsondoclint")
.path("src/tools/opt-dist")
.path("src/tools/replace-version-placeholder")
.path("src/tools/coverage-dump")
// We want `./x test tidy` to _run_ the tidy tool, not its tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ expression: test
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ expression: test --skip=coverage
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ expression: test --skip=coverage-map
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ expression: test --skip=coverage-run
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ expression: test --skip=tests
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ expression: test --skip=tests/coverage
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
- Set({tidyselftest})
[Test] test::RemoteTestClientTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ expression: test --skip=tests --skip=library --skip=tidyselftest
targets: [x86_64-unknown-linux-gnu]
- Set({src/tools/coverage-dump})
- Set({src/tools/jsondoclint})
- Set({src/tools/opt-dist})
- Set({src/tools/replace-version-placeholder})
[Test] test::RemoteTestClientTests
targets: [x86_64-unknown-linux-gnu]
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,7 @@ mod snapshot {
[build] rustc 1 <host> -> rustc 2 <host>
[test] crate-bootstrap <host> src/tools/coverage-dump
[test] crate-bootstrap <host> src/tools/jsondoclint
[test] crate-bootstrap <host> src/tools/opt-dist
[test] crate-bootstrap <host> src/tools/replace-version-placeholder
[test] crate-bootstrap <host> tidyselftest
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
Expand Down Expand Up @@ -1936,6 +1937,7 @@ mod snapshot {
[test] rustc 1 <host> -> CrateLibrustc 2 <host>
[test] crate-bootstrap <host> src/tools/coverage-dump
[test] crate-bootstrap <host> src/tools/jsondoclint
[test] crate-bootstrap <host> src/tools/opt-dist
[test] crate-bootstrap <host> src/tools/replace-version-placeholder
[test] crate-bootstrap <host> tidyselftest
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
Expand Down
22 changes: 20 additions & 2 deletions src/tools/opt-dist/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use std::fs::File;
use std::process::{Command, Stdio};

use anyhow::Context;
use camino::{Utf8Path, Utf8PathBuf};

use crate::environment::Environment;
Expand Down Expand Up @@ -163,14 +164,28 @@ impl Bootstrap {
self
}

pub fn llvm_pgo_optimize(mut self, profile: Option<&LlvmPGOProfile>) -> Self {
pub fn llvm_pgo_optimize(mut self, profile: Option<&LlvmPGOProfile>) -> anyhow::Result<Self> {
if let Some(prof) = profile {
self.cmd = self
.cmd
.arg("--set")
.arg(format!(r#"pgo.llvm.use="{}""#, normalize_path(&prof.0).as_str()));
// Allow passthrough of the profdata content to the cache extra files to mitigate sccache issue with msvc profile flags
// This can be removed when sccache https://github.com/mozilla/sccache/issues/2964 is resolved and in use by Rust build.
if cfg!(windows) {
let mut paths = std::env::var_os("SCCACHE_EXTRAFILES")
.map(|value| std::env::split_paths(&value).collect::<Vec<_>>())
.unwrap_or_default();
paths.push(prof.0.clone().into_std_path_buf());
let extra_files = std::env::join_paths(paths)
.context("SCCACHE_EXTRAFILES")?
.into_string()
.map_err(std::env::VarError::NotUnicode)
.context("SCCACHE_EXTRAFILES")?;
self.cmd = self.cmd.env("SCCACHE_EXTRAFILES", &extra_files);
}
}
self
Ok(self)
}

pub fn without_llvm_lto(mut self) -> Self {
Expand Down Expand Up @@ -316,3 +331,6 @@ fn add_shared_x_flags(env: &Environment, cmd: CmdBuilder) -> CmdBuilder {
cmd
}
}

#[cfg(all(test, windows))]
mod tests;
22 changes: 22 additions & 0 deletions src/tools/opt-dist/src/exec/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use super::*;

#[test]
fn llvm_profile_cache_input() {
let build = || Bootstrap { cmd: CmdBuilder::default(), metrics_path: Utf8PathBuf::new() };
let inherited = std::env::var_os("SCCACHE_EXTRAFILES");
let profile = LlvmPGOProfile(Utf8PathBuf::from("profile dir;cache/llvm.profdata"));
let optimized = build().llvm_pgo_optimize(Some(&profile)).unwrap();
let mut paths =
std::env::split_paths(&optimized.cmd.env["SCCACHE_EXTRAFILES"]).collect::<Vec<_>>();
assert_eq!(paths.pop(), Some(profile.0.into_std_path_buf()));
assert_eq!(
paths,
inherited.as_ref().map(std::env::split_paths).into_iter().flatten().collect::<Vec<_>>()
);
assert!(build().llvm_pgo_optimize(None).unwrap().cmd.env.is_empty());

let invalid_profile = LlvmPGOProfile(Utf8PathBuf::from("invalid\"profile"));
let error = build().llvm_pgo_optimize(Some(&invalid_profile)).err().unwrap();
assert_eq!(error.to_string(), "SCCACHE_EXTRAFILES");
assert!(error.downcast_ref::<std::env::JoinPathsError>().is_some());
}
4 changes: 2 additions & 2 deletions src/tools/opt-dist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ fn execute_pipeline(
stage.section("Build PGO optimized LLVM", |stage| {
Bootstrap::build(env)
.with_llvm_bolt_ldflags()
.llvm_pgo_optimize(llvm_pgo_profile.as_ref())
.llvm_pgo_optimize(llvm_pgo_profile.as_ref())?
.avoid_rustc_rebuild()
.run(stage)
})?;
Expand Down Expand Up @@ -449,7 +449,7 @@ fn execute_pipeline(
};

let mut dist = Bootstrap::dist(env, &dist_args)
.llvm_pgo_optimize(llvm_pgo_profile.as_ref())
.llvm_pgo_optimize(llvm_pgo_profile.as_ref())?
.rustc_pgo_optimize(&rustc_pgo_profile)
.cargo_pgo_optimize(&rustc_pgo_profile)
.rustdoc_pgo_optimize(&rustdoc_pgo_profile);
Expand Down
Loading