CodeSampleX

Exemplo

cc 1.4.3

Amostra verificada para cargo cc 1.4.3. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou: Build::new creates a build configuration and…

sha256:7b8d173d722d2a9f0ab7f96863dc5792b1cd064f556ba06c476dc299b240b6a5

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux · alpine · musl x64 cargo

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify pkg:cargo/cc@1.4.3
Pacotes
Criado
2026-09-17T21:13:14Z

Contrato

  1. Build::new creates a build configuration and resolves the default C compiler
  2. Build configures compile definitions, include paths, and flags
  3. Build sets optimization levels and debug symbols
  4. Build compiles a C source file into a library using try_compile
  5. Compiler inspects compiler family and command arguments

Arquivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

Cargo.lock
# 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"
Cargo.toml
[package]
name = "sample-cc"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
cc = "=1.4.3"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
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 pkg:cargo/cc@1.4.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/cc@1.4.3

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.
csx.json
{"case":{"caseId":"case:sha256:57acca31cd29eb8f5ccc682b137ed408770cd6c57ff619b6db758b0960944c72","contract":["Build::new creates a build configuration and resolves the default C compiler","Build configures compile definitions, include paths, and flags","Build sets optimization levels and debug symbols","Build compiles a C source file into a library using try_compile","Compiler inspects compiler family and command arguments"],"goal":"verify pkg:cargo/cc@1.4.3","kind":"HOW","packages":["pkg:cargo/cc@1.4.3"],"schemaVersion":1},"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","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/cc@1.4.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/cc@1.4.3"
  ]
}
src/lib.rs
//! Clean-room verification sample for cc.

pub use cc::*;
test/contract.rs
use std::fs;

fn get_host_target() -> String {
    if let Ok(t) = std::env::var("TARGET") {
        return t;
    }
    let output = std::process::Command::new("rustc")
        .arg("-vV")
        .output()
        .expect("failed to run rustc -vV");
    let stdout = String::from_utf8(output.stdout).expect("rustc -vV output is utf8");
    for line in stdout.lines() {
        if let Some(rest) = line.strip_prefix("host: ") {
            return rest.trim().to_string();
        }
    }
    "x86_64-unknown-linux-gnu".to_string()
}

fn main() {
    let target = get_host_target();
    let temp_dir = std::env::temp_dir().join("sample_cc_contract");
    let _ = fs::remove_dir_all(&temp_dir);
    fs::create_dir_all(&temp_dir).expect("failed to create temp dir");

    // 1. Build::new creates a build configuration and resolves the default C compiler
    let mut build1 = cc::Build::new();
    build1.cargo_metadata(false);
    build1.opt_level(0);
    build1.target(&target);
    build1.host(&target);
    let compiler = build1.get_compiler();
    assert!(!compiler.path().as_os_str().is_empty());
    assert!(compiler.is_like_gnu() || compiler.is_like_clang() || compiler.is_like_msvc());

    // 2. Build configures compile definitions, include paths, and flags
    let include_dir = temp_dir.join("include");
    fs::create_dir_all(&include_dir).expect("failed to create include dir");
    let header_file = include_dir.join("defs.h");
    fs::write(&header_file, "#define MULTIPLIER 3\nint compute(int x);\n").expect("write header");

    let c_file = temp_dir.join("compute.c");
    fs::write(
        &c_file,
        "#include \"defs.h\"\n#ifdef EXTRA_BONUS\nint compute(int x) { return x * MULTIPLIER + EXTRA_BONUS; }\n#else\nint compute(int x) { return x * MULTIPLIER; }\n#endif\n",
    ).expect("write c file");

    let mut build2 = cc::Build::new();
    build2.cargo_metadata(false);
    build2.target(&target);
    build2.host(&target);
    build2.opt_level(1);
    build2.out_dir(&temp_dir);
    build2.include(&include_dir);
    build2.define("EXTRA_BONUS", Some("5"));
    build2.file(&c_file);

    // 3. Build sets optimization levels and debug symbols
    build2.debug(false);
    build2.warnings(false);

    // 4. Build compiles a C source file into a library using try_compile
    let res = build2.try_compile("compute");
    assert!(res.is_ok(), "Compilation failed: {:?}", res);
    let lib_artifact = temp_dir.join("libcompute.a");
    assert!(lib_artifact.exists(), "Expected artifact libcompute.a was not generated");

    // 5. Compiler inspects compiler family and command arguments
    let cmd = compiler.to_command();
    assert_eq!(cmd.get_program(), compiler.path());

    let _ = fs::remove_dir_all(&temp_dir);
    println!("All cc contract tests passed successfully.");
}

Seeder de origem

anônimo