Skip to content

Commit

Permalink
experiment with just storing raw str at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
j-lanson committed Sep 20, 2024
1 parent 30c56ce commit 7ecabff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions hipcheck/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ fn main() -> Result<()> {
let root = env!("CARGO_MANIFEST_DIR");
let path = pathbuf![root, "proto", "hipcheck", "v1", "hipcheck.proto"];
compile_protos(path)?;

println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);
println!("cargo:rerun-if-changed-env=TARGET");

Ok(())
}
5 changes: 4 additions & 1 deletion hipcheck/src/plugin/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum Arch {
Unknown(String),
}

pub const DETECTED_ARCH_STR: &str = env!("TARGET");

pub const DETECTED_ARCH: Option<KnownArch> = {
if cfg!(target_arch = "x86_64") {
if cfg!(target_os = "macos") {
Expand Down Expand Up @@ -58,12 +60,13 @@ pub static USER_PROVIDED_ARCH: OnceLock<Arch> = OnceLock::new();
/// return that. Otherwise, if the `hc` binary was compiled for a supported
/// architecture, return that. Otherwise return None.
pub fn get_current_arch() -> Option<Arch> {
// @Note - I'm aware this never returns None right now, just trying things out
if let Some(arch) = USER_PROVIDED_ARCH.get() {
Some(arch.clone())
} else if let Some(known_arch) = DETECTED_ARCH {
Some(Arch::Known(known_arch))
} else {
None
Some(Arch::Unknown(DETECTED_ARCH_STR.to_owned()))
}
}

Expand Down

0 comments on commit 7ecabff

Please sign in to comment.