Files
smarm/build.rs
T
Claude 112d6b2e65 feat(cluster): RFC 010 c6d — build_hash derivation
cluster::BUILD_HASH, the derived value for LocalNode::build_hash: a
compile-time const, FNV-1a 64 over the build script's input string
(rustc -V + sorted enabled CARGO_FEATURE_* set) with PROTO_VERSION folded
in as a continuation of the same state — a proto bump moves the hash even
on an identical toolchain. build.rs emits only the raw inputs
(SMARM_BUILD_HASH_INPUTS); the hashing lives in src/cluster.rs next to
PROTO_VERSION rather than build.rs parsing it out of a source file. The
env var is emitted unconditionally — one string costs the default build
nothing, and the const itself is behind the cluster feature with the rest
of the module.

Domain is the flagged lean (one-viable-answer, veto at diff review):
toolchain + declared features + proto version. Tightenable later without a
wire change — it is just a u64 on the Hello.

Unit tests: FNV-1a 64 published vectors (empty/'a'/'foobar'); the proto
fold is a continuation of the same FNV state and moves the hash;
BUILD_HASH is const-evaluable and nonzero. All cluster suites
regression-clean (7 files); clippy --lib green both configs; fmt clean;
default build compiles.
2026-08-15 06:37:57 +00:00

37 lines
1.6 KiB
Rust

fn main() {
// RFC 019 §7 test canary (agreed Q3): compiled without stack-clash
// protection so its 96 KiB local is a genuine one-displacement guard
// jumper; distro-hardened compilers would otherwise probe it page-wise
// and defeat the test's purpose.
cc::Build::new()
.file("canary/canary.c")
.flag_if_supported("-fno-stack-clash-protection")
.compile("smarm_canary");
println!("cargo:rerun-if-changed=canary/canary.c");
// RFC 010 c6d — build_hash inputs. The compile-time facts a peer must
// share for a mesh link: the exact toolchain and the declared (enabled)
// feature set. Emitted as a plain string; the hashing (FNV-1a folded
// with PROTO_VERSION) happens in src/cluster.rs where the protocol
// version actually lives — parsing it out of a source file here would
// be a second, fragile copy. Always emitted, even for non-cluster
// builds: one env var costs the default build nothing.
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let version = std::process::Command::new(&rustc)
.arg("-V")
.output()
.ok()
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.filter(|v| !v.is_empty())
.unwrap_or_else(|| "rustc-unknown".to_string());
let mut feats: Vec<String> = std::env::vars()
.filter_map(|(k, _)| k.strip_prefix("CARGO_FEATURE_").map(str::to_string))
.collect();
feats.sort();
println!(
"cargo:rustc-env=SMARM_BUILD_HASH_INPUTS={version};features={}",
feats.join(",")
);
println!("cargo:rerun-if-env-changed=RUSTC");
}