1pub const ANN_PLATFORM: &str = "eu.pulseengine.platform";
14
15pub fn host_platform() -> String {
17 let arch = std::env::consts::ARCH;
18 match std::env::consts::OS {
19 "macos" => format!("{arch}-apple-darwin"),
20 "linux" => format!("{arch}-unknown-linux-gnu"),
21 "windows" => format!("{arch}-pc-windows-msvc"),
22 other => format!("{arch}-{other}"),
23 }
24}
25
26pub fn entry_matches(entry_platform: Option<&str>, platform: &str) -> bool {
28 match entry_platform {
29 None => true,
30 Some(p) if p.starts_with("wasm32") => true,
33 Some(p) => p == platform,
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
43 fn unstamped_entries_are_platform_independent_and_stamped_ones_are_exact() {
44 assert!(entry_matches(None, "aarch64-apple-darwin"));
45 assert!(entry_matches(
46 Some("aarch64-apple-darwin"),
47 "aarch64-apple-darwin"
48 ));
49 assert!(!entry_matches(
50 Some("x86_64-unknown-linux-gnu"),
51 "aarch64-apple-darwin"
52 ));
53 }
54
55 #[test]
57 fn wasm32_entries_are_portable_to_every_host() {
58 assert!(entry_matches(Some("wasm32-wasip2"), "aarch64-apple-darwin"));
59 assert!(entry_matches(
60 Some("wasm32-wasip2"),
61 "x86_64-unknown-linux-gnu"
62 ));
63 assert!(entry_matches(Some("wasm32-unknown-unknown"), "anything"));
64 }
65
66 #[test]
68 fn the_host_platform_is_a_target_triple() {
69 let host = host_platform();
70 assert!(
71 host.split('-').count() >= 2 && host.contains(std::env::consts::ARCH),
72 "host platform should be triple-shaped: {host}"
73 );
74 }
75}