The translator's build script goes: nothing reads M2V_SOURCE_DIGEST

crates/metal2vulkan/build.rs only set M2V_SOURCE_DIGEST (named cache::SOURCE_DIGEST in its
comment), and no code reads it: no env!/option_env! of it in the tree, and the consumer's
checkout has 0 hits for M2V_SOURCE_DIGEST and SOURCE_DIGEST (consumer-uses.sh: development
12b87d3d6b and 64 refs). The script, its copy of build_support.rs, the sha2 build-dependency
and validation's test that held the two copies equal (the_build_support_copy_is_the_translators)
go; the manifest says build = false, as the AIR front end's does, so no build script appears
unannounced.

Validation's build_support.rs is now the only copy. Its product fingerprint hashes the
translator's manifest, a build.rs only where one lies beside it (none now), and the module tree;
the definition's tag names the change, so no fingerprint under the old definition equals one
under this. The synthetic-product tests drop the copied file from their tree. The manifests'
comments name validation's fingerprint in place of the translator's.
This commit is contained in:
Anees Iqbal committed 2026-11-20 16:08:48 -08:00
1 parent 38d67fc285
commit 33e9a6db52
7 files changed
+33 -1243

No files matched your search

+2 -2
View File
@@ -13,8 +13,8 @@ members = [
default-members = ["crates/metal2vulkan"]
resolver = "2"
# What every crate here shares. The translator's source fingerprint hashes this manifest beside its
# own, because the translator inherits from it (`build_support.rs`).
# What every crate here shares. Validation's product fingerprint hashes this manifest beside the
# translator's, because the translator inherits from it (`crates/metal2vulkan-validation/build_support.rs`).
[workspace.package]
edition = "2021"
rust-version = "1.98"
+2 -2
View File
@@ -11,8 +11,8 @@ repository.workspace = true
documentation = "https://docs.rs/metal2vulkan-air"
keywords = ["metal", "air", "llvm", "bitcode", "gpu"]
categories = ["compilers", "graphics", "parser-implementations"]
# No binaries and no build script unless declared here: the build scripts that fingerprint this
# crate's sources (the translator's build_support.rs) watch only the files its module tree reaches
# No binaries and no build script unless declared here: the build script that fingerprints this
# crate's sources (validation's build_support.rs) watches only the files its module tree reaches
# and this manifest.
autobins = false
build = false
+21 -22
View File
@@ -1,18 +1,13 @@
//! Shared source-fingerprint inputs for the runtime's shader cache and validation caches.
//! The product's source-fingerprint inputs, for validation's caches.
//!
//! [`product_hash`] is the product's source fingerprint: the runtime's source ID (the translator's
//! `build.rs`) and the validation crate's product fingerprint (its `build.rs`, the dependency of its
//! observations, census keys, and analyzer key) are this hash. It covers exactly the files that can be compiled
//! into the product or read by it, found by following the crate roots' module tree the way rustc
//! resolves it, so an edit to a test-only module, a test fixture, or a file no module declares
//! leaves it unchanged. It covers the AIR front end's crate (`metal2vulkan-air`) the same way while
//! the product names it as a path dependency (in a published build the hashed manifest's exact pin
//! names its sources). [`product_inputs`] is what a build script that takes it watches.
//!
//! Two copies of this file build: the translator's (`crates/metal2vulkan/build_support.rs`) and the
//! validation crate's (`crates/metal2vulkan-validation/build_support.rs`), because no crate includes
//! a file outside its own directory. They are one file, byte for byte: validation's test
//! `the_build_support_copy_is_the_translators` fails when they differ.
//! [`product_hash`] is the product's source fingerprint: the validation crate's product fingerprint
//! (its `build.rs`, the dependency of its observations, census keys, and analyzer key) is this
//! hash. It covers exactly the files that can be compiled into the product or read by it, found by
//! following the crate roots' module tree the way rustc resolves it, so an edit to a test-only
//! module, a test fixture, or a file no module declares leaves it unchanged. It covers the AIR
//! front end's crate (`metal2vulkan-air`) the same way while the product names it as a path
//! dependency (in a published build the hashed manifest's exact pin names its sources).
//! [`product_inputs`] is what the build script that takes it watches.
use sha2::{Digest, Sha256};
use std::collections::BTreeSet;
use std::fs;
@@ -22,9 +17,10 @@ use std::path::{Component, Path, PathBuf};
/// manifest, the build inputs, and every file under `src/`) never equals one taken under this one,
/// even for a tree where the two file sets agree.
const PRODUCT_DEFINITION: &[u8] =
b"metal2vulkan product sources: the crate roots' module trees, the AIR front end's included\0";
b"metal2vulkan product sources: the crate roots' module trees, the AIR front end's included, \
each crate's build script where one lies beside its manifest\0";
/// The product crate's source fingerprint: its manifest, `build.rs`, this file, and
/// The product crate's source fingerprint: its manifest, its `build.rs` (if any), and
/// [`product_files`], the same of the AIR front end's crate where the manifest names it by path,
/// and the workspace's manifest where the product's inherits from it, each by its path relative to
/// `root`, length, and bytes, after a tag naming this definition. It asks Cargo to rerun the build
@@ -42,7 +38,7 @@ pub fn product_hash(root: &Path) -> Sha256 {
/// What [`product_hash`] reads, and what its build script watches.
pub struct ProductInputs {
/// The files it hashes, sorted: the manifest, `build.rs`, this file, and [`product_files`];
/// The files it hashes, sorted: the manifest, `build.rs` (if any), and [`product_files`];
/// the AIR front end's manifest, `build.rs` (if any), and [`product_files`] where the
/// product's manifest names that crate by path; and the workspace's manifest where the
/// product's inherits from it ([`workspace_manifest`]).
@@ -64,11 +60,14 @@ pub struct ProductInputs {
/// [`ProductInputs`] of the product below `root`.
pub fn product_inputs(root: &Path) -> ProductInputs {
let mut files = vec![
root.join("Cargo.toml"),
root.join("build.rs"),
root.join("build_support.rs"),
];
let mut files = vec![root.join("Cargo.toml")];
// The product's manifest turns Cargo's build-script discovery off (`build = false`), as the
// front end's does, so a build script it declares is a manifest edit; one beside it is
// hashed whether it runs or not.
let build = root.join("build.rs");
if build.is_file() {
files.push(build);
}
files.extend(workspace_manifest(root));
files.extend(product_files(root));
let mut watched = if crate_roots(root).discoverable {
@@ -122,7 +122,6 @@ fn manifest(package_tail: &str) -> String {
fn product(root: &Path) {
write(root, "Cargo.toml", &manifest(""));
write(root, "build.rs", "fn main() {}\n");
write(root, "build_support.rs", "// fingerprint inputs\n");
for (path, text, _) in TREE {
write(root, path, text);
}
@@ -174,7 +173,7 @@ fn the_product_fingerprint_follows_exactly_the_product_files() {
write(root, path, "fn unreachable() {}\n");
assert_eq!(fingerprint(root), before, "{path} is reached by no module");
}
for path in ["Cargo.toml", "build.rs", "build_support.rs"] {
for path in ["Cargo.toml", "build.rs"] {
let text = std::fs::read_to_string(root.join(path)).unwrap();
write(root, path, &format!("{text}\n# edited\n"));
assert_ne!(fingerprint(root), before, "an edit to {path} is an input");
@@ -208,7 +207,7 @@ fn the_build_script_watches_exactly_what_can_change_the_product() {
for (path, _, product) in TREE {
assert_eq!(watched(root, path), *product, "{path}");
}
for path in ["Cargo.toml", "build.rs", "build_support.rs"] {
for path in ["Cargo.toml", "build.rs"] {
assert!(watched(root, path), "{path}");
}
write(root, "src/bin/undeclared.rs", "fn main() {}\n");
@@ -502,18 +501,3 @@ fn the_product_fingerprint_covers_the_workspace_manifest_it_inherits_from() {
"an edit to the workspace's manifest is an input"
);
}
/// The validation crate builds its own copy of the translator's `build_support.rs` (no crate
/// includes a file outside its own directory), and the two are one file, so the product
/// fingerprint this crate takes is the walk the translator's build script takes.
#[test]
fn the_build_support_copy_is_the_translators() {
let crate_dir = metal2vulkan_devtools::validation_dir();
let ours = std::fs::read(crate_dir.join("build_support.rs")).unwrap();
let translators = std::fs::read(crate_dir.join("../metal2vulkan/build_support.rs")).unwrap();
assert!(
ours == translators,
"crates/metal2vulkan-validation/build_support.rs differs from the translator's \
crates/metal2vulkan/build_support.rs: copy the translator's file over it"
);
}
+6 -7
View File
@@ -12,9 +12,11 @@ repository.workspace = true
documentation = "https://docs.rs/metal2vulkan"
keywords = ["metal", "air", "spir-v", "vulkan", "gpu"]
categories = ["compilers", "graphics", "encoding"]
# Every binary has its own [[bin]] table: no crate root can appear unannounced, so the build
# scripts watch only the files the product fingerprint hashes (build_support.rs).
# Every binary has its own [[bin]] table and no build script runs: no crate root can appear
# unannounced, so validation's build script watches only the files its product fingerprint hashes
# (crates/metal2vulkan-validation/build_support.rs).
autobins = false
build = false
# crates.io ships only this product crate's lib, bin, examples, and unit and integration tests
# (src/, examples/, tests/). The other workspace crates live beside it under crates/ (the AIR front
# end is published as its own crate, `metal2vulkan-air`); the private corpus, scripts and docs are
@@ -47,8 +49,8 @@ path = "src/lib.rs"
[dependencies]
# The AIR front end: the container, bitcode, typed IR, ABI, intrinsics,
# canonicalization, CFG algorithms and the per-attempt budget. Pinned exactly: the two crates move
# in lockstep, one version. Named here, not through the workspace: the build script's source
# fingerprint reads this path to hash the front end's sources (`build_support.rs`).
# in lockstep, one version. Named here, not through the workspace: validation's product
# fingerprint reads this path to hash the front end's sources (its `build_support.rs`).
metal2vulkan-air = { version = "=0.2.0", path = "../metal2vulkan-air" }
# Optional: the new API's plain-data values.
serde = { workspace = true, optional = true }
@@ -72,9 +74,6 @@ cli = ["serde"]
# `DeviceDescription::query` (DESIGN §2.2 `ash_interop`).
ash = ["dep:ash"]
[build-dependencies]
sha2.workspace = true
[dev-dependencies]
# The tests' fixture assemblers and fixture directories. Path-only, so `cargo
# publish` drops it and the published manifest names no unpublished crate.
-20
View File
@@ -1,20 +0,0 @@
mod build_support;
fn main() {
// The product's source fingerprint, `cache::SOURCE_DIGEST`: what a cache of translations across
// builds keys on beside the versions, as a runtime's shader cache does, so a build
// of other sources never reads another build's translations, even when no version moved. It
// asks Cargo to rerun this script when one of its inputs changes
// (`build_support::product_inputs`).
use sha2::Digest;
let hash = build_support::product_hash(std::path::Path::new("."));
println!(
"cargo:rustc-env=M2V_SOURCE_DIGEST={}",
hex(&hash.finalize())
);
}
/// `bytes` as lowercase hex, two digits a byte: the form of every digest string here.
fn hex(bytes: &[u8]) -> String {
bytes.iter().map(|byte| format!("{byte:02x}")).collect()
}
File diff suppressed because it is too large. Load diff