Skip to content

Commit 11f9283

Browse files
committed
Add a Local environment to opt-dist
This makes it easier to build a PGO/BOLT optimized `rustc` locally, outside of CI.
1 parent a2ed508 commit 11f9283

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

src/tools/opt-dist/src/environment.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ pub struct Environment {
77
python_binary: String,
88
/// The rustc checkout, where the compiler source is located.
99
checkout_dir: Utf8PathBuf,
10-
/// The main directory where the build occurs.
10+
/// The main directory where the build occurs. Stage0 rustc and cargo have to be available in
11+
/// this directory before `opt-dist` is started.
1112
build_dir: Utf8PathBuf,
1213
/// Directory where the optimization artifacts (PGO/BOLT profiles, etc.)
1314
/// will be stored.
1415
artifact_dir: Utf8PathBuf,
1516
/// Path to the host LLVM used to compile LLVM in `src/llvm-project`.
1617
host_llvm_dir: Utf8PathBuf,
1718
/// List of test paths that should be skipped when testing the optimized artifacts.
18-
skipped_tests: Vec<&'static str>,
19+
skipped_tests: Vec<String>,
1920
use_bolt: bool,
2021
shared_llvm: bool,
2122
}
@@ -83,7 +84,7 @@ impl Environment {
8384
self.shared_llvm
8485
}
8586

86-
pub fn skipped_tests(&self) -> &[&'static str] {
87+
pub fn skipped_tests(&self) -> &[String] {
8788
&self.skipped_tests
8889
}
8990
}

src/tools/opt-dist/src/main.rs

+73-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,51 @@ struct SharedArgs {
4242

4343
#[derive(clap::Parser, Clone, Debug)]
4444
enum EnvironmentCmd {
45+
/// Perform a custom local PGO/BOLT optimized build.
46+
Local {
47+
/// Target triple of the host.
48+
#[arg(long)]
49+
target_triple: String,
50+
51+
/// Checkout directory of `rustc`.
52+
#[arg(long)]
53+
checkout_dir: Utf8PathBuf,
54+
55+
/// Host LLVM installation directory.
56+
#[arg(long)]
57+
llvm_dir: Utf8PathBuf,
58+
59+
/// Python binary to use in bootstrap invocations.
60+
#[arg(long, default_value = "python3")]
61+
python: String,
62+
63+
/// Directory where artifacts (like PGO profiles or rustc-perf) of this workflow
64+
/// will be stored.
65+
#[arg(long, default_value = "opt-artifacts")]
66+
artifact_dir: Utf8PathBuf,
67+
68+
/// Is LLVM for `rustc` built in shared library mode?
69+
#[arg(long, default_value_t = true)]
70+
llvm_shared: bool,
71+
72+
/// Should BOLT optimization be used? If yes, host LLVM must have BOLT binaries
73+
/// (`llvm-bolt` and `merge-fdata`) available.
74+
#[arg(long, default_value_t = false)]
75+
use_bolt: bool,
76+
77+
/// Tests that should be skipped when testing the optimized compiler.
78+
#[arg(long)]
79+
skipped_tests: Vec<String>,
80+
81+
#[clap(flatten)]
82+
shared: SharedArgs,
83+
},
84+
/// Perform an optimized build on Linux CI, from inside Docker.
4585
LinuxCi {
4686
#[clap(flatten)]
4787
shared: SharedArgs,
4888
},
89+
/// Perform an optimized build on Windows CI, directly inside Github Actions.
4990
WindowsCi {
5091
#[clap(flatten)]
5192
shared: SharedArgs,
@@ -58,6 +99,34 @@ fn is_try_build() -> bool {
5899

59100
fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)> {
60101
let (env, args) = match args.env {
102+
EnvironmentCmd::Local {
103+
target_triple,
104+
checkout_dir,
105+
llvm_dir,
106+
python,
107+
artifact_dir,
108+
llvm_shared,
109+
use_bolt,
110+
skipped_tests,
111+
shared,
112+
} => {
113+
let env = EnvironmentBuilder::default()
114+
.host_triple(target_triple)
115+
.python_binary(python)
116+
.checkout_dir(checkout_dir.clone())
117+
.host_llvm_dir(llvm_dir)
118+
.artifact_dir(artifact_dir)
119+
.build_dir(checkout_dir)
120+
.shared_llvm(llvm_shared)
121+
.use_bolt(use_bolt)
122+
.skipped_tests(skipped_tests)
123+
.build()?;
124+
with_log_group("Building rustc-perf", || {
125+
Ok::<(), anyhow::Error>(download_rustc_perf(&env)?)
126+
})?;
127+
128+
(env, shared.build_args)
129+
}
61130
EnvironmentCmd::LinuxCi { shared } => {
62131
let target_triple =
63132
std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing");
@@ -74,7 +143,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
74143
.use_bolt(true)
75144
.skipped_tests(vec![
76145
// Fails because of linker errors, as of June 2023.
77-
"tests/ui/process/nofile-limit.rs",
146+
"tests/ui/process/nofile-limit.rs".to_string(),
78147
])
79148
.build()?;
80149
// /tmp/rustc-perf comes from the x64 dist Dockerfile
@@ -100,7 +169,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
100169
.use_bolt(false)
101170
.skipped_tests(vec![
102171
// Fails as of June 2023.
103-
"tests\\codegen\\vec-shrink-panik.rs",
172+
"tests\\codegen\\vec-shrink-panik.rs".to_string(),
104173
])
105174
.build()?;
106175

@@ -309,6 +378,8 @@ fn copy_rustc_perf(env: &Environment, dir: &Utf8Path) -> anyhow::Result<()> {
309378

310379
// Download and build rustc-perf into the given environment.
311380
fn download_rustc_perf(env: &Environment) -> anyhow::Result<()> {
381+
reset_directory(&env.rustc_perf_dir())?;
382+
312383
// FIXME: add some mechanism for synchronization of this commit SHA with
313384
// Linux (which builds rustc-perf in a Dockerfile)
314385
// rustc-perf version from 2023-05-30

0 commit comments

Comments
 (0)