1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! The platform dimension (REQ-PLATFORM-001, DD-001).
//!
//! A layer is one manifest for N platforms — the OCI index's own mechanism,
//! not a substitution language. Deposit stamps every entry with a target
//! triple; install selects only entries for the host (or an explicit
//! override). Entries WITHOUT a platform annotation are platform-independent
//! — layers deposited before this dimension existed keep working, and a
//! depositor that makes no platform claim gets no platform filtering.
//! A fully-stamped layer with nothing for the host fails closed: a
//! wrong-architecture binary never reaches the core.
/// Annotation carrying an entry's target triple.
pub const ANN_PLATFORM: &str = "eu.pulseengine.platform";
/// The host's target triple, in the same vocabulary deposits use.
pub fn host_platform() -> String {
let arch = std::env::consts::ARCH;
match std::env::consts::OS {
"macos" => format!("{arch}-apple-darwin"),
"linux" => format!("{arch}-unknown-linux-gnu"),
"windows" => format!("{arch}-pc-windows-msvc"),
other => format!("{arch}-{other}"),
}
}
/// Does an entry's (optional) platform annotation admit this platform?
pub fn entry_matches(entry_platform: Option<&str>, platform: &str) -> bool {
match entry_platform {
None => true,
// wasm32 targets are PORTABLE: the bytes run wherever a runner
// exists (REQ-RUNNER-001) — no per-platform gaps by construction.
Some(p) if p.starts_with("wasm32") => true,
Some(p) => p == platform,
}
}
#[cfg(test)]
mod tests {
use super::*;
// rivet: verifies REQ-PLATFORM-001
#[test]
fn unstamped_entries_are_platform_independent_and_stamped_ones_are_exact() {
assert!(entry_matches(None, "aarch64-apple-darwin"));
assert!(entry_matches(
Some("aarch64-apple-darwin"),
"aarch64-apple-darwin"
));
assert!(!entry_matches(
Some("x86_64-unknown-linux-gnu"),
"aarch64-apple-darwin"
));
}
// rivet: verifies REQ-RUNNER-001
#[test]
fn wasm32_entries_are_portable_to_every_host() {
assert!(entry_matches(Some("wasm32-wasip2"), "aarch64-apple-darwin"));
assert!(entry_matches(
Some("wasm32-wasip2"),
"x86_64-unknown-linux-gnu"
));
assert!(entry_matches(Some("wasm32-unknown-unknown"), "anything"));
}
// rivet: verifies REQ-PLATFORM-001
#[test]
fn the_host_platform_is_a_target_triple() {
let host = host_platform();
assert!(
host.split('-').count() >= 2 && host.contains(std::env::consts::ARCH),
"host platform should be triple-shaped: {host}"
);
}
}