Skip to content
Closed
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
20 changes: 15 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
# --- APR-MONO Phase 2b: was provable-contracts ---
"crates/aprender-contracts",
"crates/aprender-contracts-macros",
"crates/aprender-contracts-key",
"crates/aprender-contracts-cli",
# EPIC #4232: shared update check + `<bin> update` for every sovereign binary.
"crates/aprender-update",
Expand Down Expand Up @@ -321,6 +322,7 @@ aprender-train-common = { path = "crates/aprender-train-common", version = "0.71
aprender-train-distill = { path = "crates/aprender-train-distill", version = "0.71.3" }
aprender-orchestrate = { path = "crates/aprender-orchestrate", version = "0.71.3" }
aprender-contracts = { path = "crates/aprender-contracts", version = "0.71.3" }
aprender-contracts-key = { path = "crates/aprender-contracts-key", version = "0.71.3" }
aprender-build-sha = { path = "crates/aprender-build-sha", version = "0.71.3" }
aprender-rollup = { path = "crates/aprender-rollup", version = "0.71.3" }
aprender-profile = { path = "crates/aprender-profile", version = "0.71.3" }
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-compute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ web-sys = { version = "0.3", optional = true, features = ["console"] }
hostname = "0.4"

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-compute/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Binding {

/// Convert a contract filename + equation into a canonical env var name.
fn env_var_name(contract: &str, equation: &str) -> String {
provable_contracts::build_helper::env_key(
aprender_contracts_key::env_key(
contract.trim_end_matches(".yaml").trim_end_matches(".yml"),
equation,
)
Expand Down
14 changes: 14 additions & 0 deletions crates/aprender-contracts-key/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "aprender-contracts-key"
description = "The one CONTRACT_* env-var key builder shared by build.rs scripts and aprender-contracts (no dependencies, so build-depending on it does not mark the contract engine affected)"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
keywords = ["verification", "contracts"]
categories = ["development-tools::build-utils"]

[lints]
workspace = true
14 changes: 14 additions & 0 deletions crates/aprender-contracts-key/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# aprender-contracts-key

The one `CONTRACT_*` env-var key builder shared by `build.rs` scripts and `aprender-contracts`.

Part of the [Aprender](https://github.com/paiml/aprender) monorepo (`paiml/aprender`). It has no dependencies on purpose: a crate that build-depends on it does not mark the contract engine affected.

```rust
let key = aprender_contracts_key::env_key("my-contract", "eq.1");
assert_eq!(key, "CONTRACT_MY_CONTRACT_EQ_1");
```

## License

MIT
15 changes: 15 additions & 0 deletions crates/aprender-contracts-key/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! The `CONTRACT_*` env-var key builder (#4369, #5909). Dependency-free on purpose.

/// The env var key `#[contract(contract, equation = equation)]` reads.
///
/// A producer (a consuming crate's `build.rs`) must emit its
/// `cargo:rustc-env` vars under exactly this key, plus `_PRE_COUNT`,
/// `_PRE_<i>`, `_POST_COUNT` and `_POST_<i>`. Call this instead of
/// re-deriving the format: a hand-rolled copy that drifts makes every
/// condition land under a name the macro never reads (#2699 §4). It is
/// tested equal to the macro's own `contract_env_key!`.
pub fn env_key(contract: &str, equation: &str) -> String {
let contract_part = contract.to_uppercase().replace(['-', '.'], "_");
let equation_part = equation.to_uppercase().replace(['-', '.'], "_");
format!("CONTRACT_{contract_part}_{equation_part}")
}
2 changes: 2 additions & 0 deletions crates/aprender-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ criterion = { version = "0.5", features = ["html_reports"] }
# Oracle for f16-conversion falsifiers (PMAT-905). `half` is a workspace leaf crate
# (no aprender dependency) → dev-dep introduces no cycle. Used only in tests.
half = { workspace = true }
# The shared key builder, dev-only: a normal or build dependency would add a unit to the pv build (12-unit budget, ci/sections.yml m5). #5909
aprender-contracts-key = { workspace = true }

[[bench]]
name = "benchmarks"
Expand Down
22 changes: 22 additions & 0 deletions crates/aprender-contracts/src/build_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,28 @@ bindings:
}
}

/// The shared `aprender-contracts-key` copy (used by other crates' build.rs) must give
/// the same key as this crate's own `env_key` and as the macro (#5909).
#[test]
fn shared_key_crate_agrees_with_env_key_and_the_macro() {
use provable_contracts_macros::contract_env_key;
for (c, e) in [
("rmsnorm-kernel-v1", "rmsnorm"),
("v1.0", "eq.1"),
("mixed-Case.v2", "Eq-x.y"),
] {
assert_eq!(aprender_contracts_key::env_key(c, e), env_key(c, e));
}
assert_eq!(
aprender_contracts_key::env_key("v1.0", "eq.1"),
contract_env_key!("v1.0", "eq.1")
);
assert_eq!(
aprender_contracts_key::env_key("mixed-Case.v2", "Eq-x.y"),
contract_env_key!("mixed-Case.v2", "Eq-x.y")
);
}

#[test]
fn test_make_env_key_matches_macro_convention() {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ provable-contracts-macros = { workspace = true }
# realizar = { version = "0.6", default-features = false, optional = true } # BLOCKED

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct Binding {
///
/// "softmax-kernel-v1.yaml" + "softmax" -> "CONTRACT_SOFTMAX_KERNEL_V1_SOFTMAX"
fn binding_env_var_name(contract: &str, equation: &str) -> String {
provable_contracts::build_helper::env_key(
aprender_contracts_key::env_key(
contract.trim_end_matches(".yaml").trim_end_matches(".yml"),
equation,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
aprender-build-sha = { workspace = true } # #4219: APR_GIT_SHA for --version
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }
Expand Down
6 changes: 2 additions & 4 deletions crates/aprender-db/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ fn main() {
let total = bindings.bindings.len() as u32;

for b in &bindings.bindings {
let var = provable_contracts::build_helper::env_key(
b.contract.trim_end_matches(".yaml"),
&b.equation,
);
let var =
aprender_contracts_key::env_key(b.contract.trim_end_matches(".yaml"), &b.equation);
println!("cargo:rustc-env={var}={}", b.status);
if b.status == "implemented" {
implemented += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-orchestrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ sovereign-stack = [
]

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
aprender-build-sha = { workspace = true } # #4219: APR_GIT_SHA for --version
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }
Expand Down
8 changes: 3 additions & 5 deletions crates/aprender-orchestrate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ fn emit_bindings(bindings: &BindingFile) {
let total = bindings.bindings.len() as u32;

for b in &bindings.bindings {
let var = provable_contracts::build_helper::env_key(
b.contract.trim_end_matches(".yaml"),
&b.equation,
);
let var =
aprender_contracts_key::env_key(b.contract.trim_end_matches(".yaml"), &b.equation);
println!("cargo:rustc-env={var}={}", b.status);
if b.status == "implemented" {
implemented += 1;
Expand Down Expand Up @@ -117,7 +115,7 @@ fn emit_contract_assertions(cdir: &Path) {
continue;
};
for (n, eq) in &y.equations {
let k = provable_contracts::build_helper::env_key(&s, n);
let k = aprender_contracts_key::env_key(&s, n);
tp += emit_conditions(&k, "PRE", &eq.preconditions);
tq += emit_conditions(&k, "POST", &eq.postconditions);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-present-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tiny_http = "0.12"
tungstenite = { version = "0.26", optional = true }

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
aprender-build-sha = { workspace = true } # #4219: APR_GIT_SHA for --version
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }
Expand Down
6 changes: 2 additions & 4 deletions crates/aprender-present-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ fn main() {
let total = bindings.bindings.len() as u32;

for b in &bindings.bindings {
let var = provable_contracts::build_helper::env_key(
b.contract.trim_end_matches(".yaml"),
&b.equation,
);
let var =
aprender_contracts_key::env_key(b.contract.trim_end_matches(".yaml"), &b.equation);
println!("cargo:rustc-env={var}={}", b.status);
if b.status == "implemented" {
implemented += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-present-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde_json = { workspace = true }
provable-contracts-macros = { workspace = true }

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
serde = { workspace = true }
serde-saphyr = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions crates/aprender-present-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn emit_contract_file_pre_post(path: &PathBuf, total_pre: &mut usize, total_post
return;
};
for (eq_name, eq) in &parsed.equations {
let key = provable_contracts::build_helper::env_key(&stem, eq_name);
let key = aprender_contracts_key::env_key(&stem, eq_name);
emit_pre_post_lists(&key, eq, total_pre, total_post);
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ fn emit_binding_counts_and_vars(bf: &BindingFile) {
}

fn env_var_name(contract: &str, equation: &str) -> String {
provable_contracts::build_helper::env_key(
aprender_contracts_key::env_key(
contract.trim_end_matches(".yaml").trim_end_matches(".yml"),
equation,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-rag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sha2 = { version = "0.10", optional = true }
rand = { version = "0.9", optional = true }

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }

Expand Down
6 changes: 2 additions & 4 deletions crates/aprender-rag/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ fn main() {
let total = bindings.bindings.len() as u32;

for b in &bindings.bindings {
let var = provable_contracts::build_helper::env_key(
b.contract.trim_end_matches(".yaml"),
&b.equation,
);
let var =
aprender_contracts_key::env_key(b.contract.trim_end_matches(".yaml"), &b.equation);
println!("cargo:rustc-env={var}={}", b.status);
if b.status == "implemented" {
implemented += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ libc = "0.2"
uuid = { version = "1", features = ["v4", "serde", "js"] }

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
# Parsing provable-contracts binding.yaml for CONTRACT_* env vars (build.rs)
serde = { version = "1", features = ["derive"] }
serde-saphyr = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/aprender-serve/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct Binding {
///
/// `"softmax-kernel-v1.yaml"` + `"softmax"` → `"CONTRACT_SOFTMAX_KERNEL_V1_SOFTMAX"`
fn env_var_name(contract: &str, equation: &str) -> String {
provable_contracts::build_helper::env_key(
aprender_contracts_key::env_key(
contract.trim_end_matches(".yaml").trim_end_matches(".yml"),
equation,
)
Expand Down Expand Up @@ -884,7 +884,7 @@ fn emit_contract_assertions() {
continue;
};
for (eq, e) in &y.equations {
let k = provable_contracts::build_helper::env_key(stem, eq);
let k = aprender_contracts_key::env_key(stem, eq);
if !e.preconditions.is_empty() {
println!("cargo:rustc-env={k}_PRE_COUNT={}", e.preconditions.len());
for (i, v) in e.preconditions.iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion crates/aprender-simulate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ provable-contracts-macros = { workspace = true }
# Code gated behind #[cfg(feature = "z3-proofs")]

[build-dependencies]
provable-contracts = { workspace = true } # #4369: build_helper::env_key, the one CONTRACT_* key builder
aprender-contracts-key = { workspace = true } # #4369, #5909: the one CONTRACT_* key builder (no engine dependency)
aprender-build-sha = { workspace = true } # #4219: APR_GIT_SHA for --version
serde = { version = "1.0", features = ["derive"] }
serde-saphyr = { workspace = true } # #5208: build.rs reads contract YAML through saphyr, not unsafe-libyaml
Expand Down
Loading
Loading