From fc627faf5eb7971d90449eb094f280e3410b250a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sun, 13 Sep 2026 03:19:01 -0700 Subject: [PATCH] feat: expose binary compile-target identity (refs #190) --- src/platform/host.rs | 25 +++++++++++++++++++++++++ tests/process_target.rs | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/process_target.rs diff --git a/src/platform/host.rs b/src/platform/host.rs index b53b4450..8b8b3c3d 100644 --- a/src/platform/host.rs +++ b/src/platform/host.rs @@ -20,6 +20,31 @@ pub use crate::{ pub use crate::host_login_environment_block as login_environment_block; +/// Compile target of this executing binary, not the physical host hardware. +/// +/// Names follow Rust's target vocabulary (for example `windows`, `macos`, +/// `linux`, `x86_64`, and `aarch64`). Package registry aliases and supported +/// artifact selection are caller policy. +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub struct ProcessTarget { + /// Operating system the binary was compiled for. + pub os: &'static str, + /// Architecture the binary was compiled for. + pub architecture: &'static str, +} + +/// Report the executing binary's compile target without probing the host. +/// +/// An x86-64 binary running under emulation on ARM64 still reports `x86_64`. +/// This does not detect Rosetta, CPU features, the host's native architecture, +/// or ABI details such as libc. No subprocess or environment lookup is used. +pub const fn process_target() -> ProcessTarget { + ProcessTarget { + os: std::env::consts::OS, + architecture: std::env::consts::ARCH, + } +} + /// Logical concurrency this host exposes to this process. /// /// A thin, host-neutral restatement of [`std::thread::available_parallelism`] diff --git a/tests/process_target.rs b/tests/process_target.rs new file mode 100644 index 00000000..e38cd4c9 --- /dev/null +++ b/tests/process_target.rs @@ -0,0 +1,18 @@ +use kernal_api::platform::host::{process_target, ProcessTarget}; + +#[test] +fn process_target_reports_binary_target_without_host_probing() { + const TARGET: ProcessTarget = process_target(); + assert_eq!(TARGET.os, std::env::consts::OS); + assert_eq!(TARGET.architecture, std::env::consts::ARCH); + #[cfg(target_os = "windows")] + assert_eq!(TARGET.os, "windows"); + #[cfg(target_os = "macos")] + assert_eq!(TARGET.os, "macos"); + #[cfg(target_os = "linux")] + assert_eq!(TARGET.os, "linux"); + #[cfg(target_arch = "x86_64")] + assert_eq!(TARGET.architecture, "x86_64"); + #[cfg(target_arch = "aarch64")] + assert_eq!(TARGET.architecture, "aarch64"); +}