Store target triple in environment

This commit is contained in:
Jakub Beránek 2023-09-12 18:02:45 +02:00
parent 5f6ee65f59
commit 074fb2c6b7
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
4 changed files with 27 additions and 10 deletions

View File

@ -3,9 +3,21 @@ use crate::exec::cmd;
use crate::utils::io::copy_directory;
use camino::{Utf8Path, Utf8PathBuf};
pub(super) struct LinuxEnvironment;
pub(super) struct LinuxEnvironment {
target_triple: String,
}
impl LinuxEnvironment {
pub fn new(target_triple: String) -> Self {
Self { target_triple }
}
}
impl Environment for LinuxEnvironment {
fn host_triple(&self) -> &str {
&self.target_triple
}
fn python_binary(&self) -> &'static str {
"python3"
}

View File

@ -6,9 +6,7 @@ mod linux;
mod windows;
pub trait Environment {
fn host_triple(&self) -> String {
std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing")
}
fn host_triple(&self) -> &str;
fn python_binary(&self) -> &'static str;
@ -69,9 +67,9 @@ pub trait Environment {
fn skipped_tests(&self) -> &'static [&'static str];
}
pub fn create_environment() -> Box<dyn Environment> {
pub fn create_environment(target_triple: String) -> Box<dyn Environment> {
#[cfg(target_family = "unix")]
return Box::new(linux::LinuxEnvironment);
return Box::new(linux::LinuxEnvironment::new(target_triple));
#[cfg(target_family = "windows")]
return Box::new(windows::WindowsEnvironment::new());
return Box::new(windows::WindowsEnvironment::new(target_triple));
}

View File

@ -9,15 +9,20 @@ use zip::ZipArchive;
pub(super) struct WindowsEnvironment {
checkout_dir: Utf8PathBuf,
target_triple: String,
}
impl WindowsEnvironment {
pub fn new() -> Self {
Self { checkout_dir: std::env::current_dir().unwrap().try_into().unwrap() }
pub fn new(target_triple: String) -> Self {
Self { checkout_dir: std::env::current_dir().unwrap().try_into().unwrap(), target_triple }
}
}
impl Environment for WindowsEnvironment {
fn host_triple(&self) -> &str {
&self.target_triple
}
fn python_binary(&self) -> &'static str {
"python"
}

View File

@ -171,6 +171,8 @@ fn main() -> anyhow::Result<()> {
.parse_default_env()
.init();
let target_triple = std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing");
let mut build_args: Vec<String> = std::env::args().skip(1).collect();
println!("Running optimized build pipeline with args `{}`", build_args.join(" "));
@ -202,7 +204,7 @@ fn main() -> anyhow::Result<()> {
}
let mut timer = Timer::new();
let env = create_environment();
let env = create_environment(target_triple);
let result = execute_pipeline(env.as_ref(), &mut timer, build_args);
log::info!("Timer results\n{}", timer.format_stats());