Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/platform/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down
18 changes: 18 additions & 0 deletions tests/process_target.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Loading