Skip to content

Commit 074fb2c

Browse files
committed
Store target triple in environment
1 parent 5f6ee65 commit 074fb2c

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ use crate::exec::cmd;
33
use crate::utils::io::copy_directory;
44
use camino::{Utf8Path, Utf8PathBuf};
55

6-
pub(super) struct LinuxEnvironment;
6+
pub(super) struct LinuxEnvironment {
7+
target_triple: String,
8+
}
9+
10+
impl LinuxEnvironment {
11+
pub fn new(target_triple: String) -> Self {
12+
Self { target_triple }
13+
}
14+
}
715

816
impl Environment for LinuxEnvironment {
17+
fn host_triple(&self) -> &str {
18+
&self.target_triple
19+
}
20+
921
fn python_binary(&self) -> &'static str {
1022
"python3"
1123
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ mod linux;
66
mod windows;
77

88
pub trait Environment {
9-
fn host_triple(&self) -> String {
10-
std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing")
11-
}
9+
fn host_triple(&self) -> &str;
1210

1311
fn python_binary(&self) -> &'static str;
1412

@@ -69,9 +67,9 @@ pub trait Environment {
6967
fn skipped_tests(&self) -> &'static [&'static str];
7068
}
7169

72-
pub fn create_environment() -> Box<dyn Environment> {
70+
pub fn create_environment(target_triple: String) -> Box<dyn Environment> {
7371
#[cfg(target_family = "unix")]
74-
return Box::new(linux::LinuxEnvironment);
72+
return Box::new(linux::LinuxEnvironment::new(target_triple));
7573
#[cfg(target_family = "windows")]
76-
return Box::new(windows::WindowsEnvironment::new());
74+
return Box::new(windows::WindowsEnvironment::new(target_triple));
7775
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ use zip::ZipArchive;
99

1010
pub(super) struct WindowsEnvironment {
1111
checkout_dir: Utf8PathBuf,
12+
target_triple: String,
1213
}
1314

1415
impl WindowsEnvironment {
15-
pub fn new() -> Self {
16-
Self { checkout_dir: std::env::current_dir().unwrap().try_into().unwrap() }
16+
pub fn new(target_triple: String) -> Self {
17+
Self { checkout_dir: std::env::current_dir().unwrap().try_into().unwrap(), target_triple }
1718
}
1819
}
1920

2021
impl Environment for WindowsEnvironment {
22+
fn host_triple(&self) -> &str {
23+
&self.target_triple
24+
}
25+
2126
fn python_binary(&self) -> &'static str {
2227
"python"
2328
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ fn main() -> anyhow::Result<()> {
171171
.parse_default_env()
172172
.init();
173173

174+
let target_triple = std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing");
175+
174176
let mut build_args: Vec<String> = std::env::args().skip(1).collect();
175177
println!("Running optimized build pipeline with args `{}`", build_args.join(" "));
176178

@@ -202,7 +204,7 @@ fn main() -> anyhow::Result<()> {
202204
}
203205

204206
let mut timer = Timer::new();
205-
let env = create_environment();
207+
let env = create_environment(target_triple);
206208

207209
let result = execute_pipeline(env.as_ref(), &mut timer, build_args);
208210
log::info!("Timer results\n{}", timer.format_stats());

0 commit comments

Comments
 (0)