Exemple
cc 1.4.3: cc::Build
Échantillon vérifié pour cargo cc 1.4.3: cc::Build. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a réussi.
sha256:e7e069184b8cd5edc5e826c53ae5723f4db1524e13f5d0de4045fd59fcd3f484
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux · alpine · musl x64 cargo
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-09-19 |
Cas
HOW- Objectif
- verify cc::Build in pkg:cargo/cc@1.4.3
- Paquets
- Symboles
-
- cc::Build
- Créé
- 2026-09-17T22:20:31Z
Contrat
- Build::new initializes a C compiler configuration with target and optimization level
- Build::get_compiler inspects the toolchain binary path and compiler family flags
- Build::define and Build::include add macro definitions and header search paths to compiler arguments
- Build::opt_level and Build::debug configure optimization and debug symbol flags
- Build::try_compile compiles C source into a static archive output
Fichiers
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- src/sample.c
- test/contract.rs
Code source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "cc"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d"
[[package]]
name = "sample-cc"
version = "1.0.0"
dependencies = [
"cc",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[package]
name = "sample-cc"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
cc = "=1.4.3"
[[bin]]
name = "contract"
path = "test/contract.rs"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify cc::Build in pkg:cargo/cc@1.4.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/cc@1.4.3
Demonstrate these symbols/APIs:
- cc::Build
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:c72157607e36180637b28001918644a352a6f577facbea252aa99677c1ab24f0","contract":["Build::new initializes a C compiler configuration with target and optimization level","Build::get_compiler inspects the toolchain binary path and compiler family flags","Build::define and Build::include add macro definitions and header search paths to compiler arguments","Build::opt_level and Build::debug configure optimization and debug symbol flags","Build::try_compile compiles C source into a static archive output"],"goal":"verify cc::Build in pkg:cargo/cc@1.4.3","kind":"HOW","packages":["pkg:cargo/cc@1.4.3"],"schemaVersion":1,"symbols":["cc::Build"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/cc@1.4.3"],"schemaVersion":1,"subject":"pkg:cargo/cc@1.4.3","symbols":["cc::Build"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify cc::Build in pkg:cargo/cc@1.4.3",
"kind": "HOW",
"packages": [
"pkg:cargo/cc@1.4.3"
],
"symbols": [
"cc::Build"
]
}
//! Clean-room verification sample for cc.
pub use cc::Build;
/* Clean-room C source for cc::Build contract verification */
int compute_square(int val) {
return val * val;
}
use cc::Build;
use std::env;
use std::fs;
fn main() {
// 1. Build::new initializes a C compiler configuration with target and optimization level
if env::var("TARGET").is_err() {
#[cfg(target_env = "musl")]
let default_target = "x86_64-unknown-linux-musl";
#[cfg(not(target_env = "musl"))]
let default_target = "x86_64-unknown-linux-gnu";
env::set_var("TARGET", default_target);
}
if env::var("HOST").is_err() {
let current_target = env::var("TARGET").unwrap();
env::set_var("HOST", current_target);
}
if env::var("OPT_LEVEL").is_err() {
env::set_var("OPT_LEVEL", "0");
}
let mut b1 = Build::new();
b1.cargo_metadata(false);
b1.opt_level(0);
// 2. Build::get_compiler inspects the toolchain binary path and compiler family flags
let comp1 = b1.get_compiler();
let comp_path = comp1.path().to_string_lossy();
assert!(!comp_path.is_empty(), "compiler path should not be empty");
assert!(comp1.is_like_gnu() || comp1.is_like_clang(), "toolchain should be GNU or Clang compatible");
assert!(!comp1.is_like_msvc(), "toolchain should not be MSVC on Linux");
// 3. Build::define and Build::include add macro definitions and header search paths to compiler arguments
let mut b2 = Build::new();
b2.cargo_metadata(false);
b2.opt_level(1);
b2.include("src");
b2.define("CSX_TEST_MACRO", Some("100"));
b2.define("CSX_TEST_FLAG", None);
let comp2 = b2.get_compiler();
let args2: Vec<String> = comp2.args().iter().map(|s| s.to_string_lossy().to_string()).collect();
assert!(args2.iter().any(|a| a == "-DCSX_TEST_MACRO=100"), "macro with value should be in args");
assert!(args2.iter().any(|a| a == "-DCSX_TEST_FLAG"), "macro flag without value should be in args");
assert!(
args2.windows(2).any(|w| w[0] == "-I" && w[1] == "src") || args2.iter().any(|a| a == "-Isrc"),
"include path should be in args"
);
// 4. Build::opt_level and Build::debug configure optimization and debug symbol flags
let mut b3 = Build::new();
b3.cargo_metadata(false);
b3.opt_level(3);
b3.debug(true);
let comp3 = b3.get_compiler();
let args3: Vec<String> = comp3.args().iter().map(|s| s.to_string_lossy().to_string()).collect();
assert!(args3.iter().any(|a| a == "-O3"), "opt_level(3) should emit -O3");
assert!(args3.iter().any(|a| a == "-g"), "debug(true) should emit -g");
// 5. Build::try_compile compiles C source into a static archive output
let temp_out = env::temp_dir().join("csx_sample_cc_out");
let _ = fs::remove_dir_all(&temp_out);
fs::create_dir_all(&temp_out).expect("create temp out directory");
let mut b4 = Build::new();
b4.cargo_metadata(false);
b4.opt_level(2);
b4.out_dir(&temp_out);
b4.file("src/sample.c");
let compile_result = b4.try_compile("sample_c");
assert!(compile_result.is_ok(), "try_compile should succeed: {:?}", compile_result.err());
let archive_path = temp_out.join("libsample_c.a");
assert!(archive_path.exists(), "libsample_c.a should be created in output directory");
let _ = fs::remove_dir_all(&temp_out);
println!("All cc::Build contract assertions passed successfully.");
}
Seeder d'origine
anonyme