示例
modernc.org/ccgo/v4 v4.34.0
已验证示例 — golang modernc.org/ccgo/v4 v4.34.0. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: ccgo.IsExecEnv returns false when CCGO_EXEC_ENV is unset…
sha256:f1a54e423ea1e012693e3d373bd198f93b4ae1d31f7cf5fe74fbfd8658787f3a
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-11-28 |
案例
HOW- 目标
- verify pkg:golang/modernc.org/ccgo/v4@v4.34.0
- 创建时间
- 2026-11-28T04:40:37Z
契约
- ccgo.IsExecEnv returns false when CCGO_EXEC_ENV is unset or empty and true when set to a non-empty value
- ccgo.NewTask and Task.Main with -E, -I, and -D preprocess a C source file with local header inclusion from an in-memory fs.FS and expand macros and conditional directives
- ccgo.NewTask and Task.Main with -c and -o transpile C functions and #define constants from an in-memory fs.FS into Go source code
- Task.Main returns a non-nil error when invoked on a nonexistent C input file
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
源代码
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:golang/modernc.org/ccgo/v4@v4.34.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/modernc.org/ccgo/v4@v4.34.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:b10ee5f717a4d52d6d4d005bedc24c68c5b50a032f35daed6b2c32e2f5ba8158","contract":["ccgo.IsExecEnv returns false when CCGO_EXEC_ENV is unset or empty and true when set to a non-empty value","ccgo.NewTask and Task.Main with -E, -I, and -D preprocess a C source file with local header inclusion from an in-memory fs.FS and expand macros and conditional directives","ccgo.NewTask and Task.Main with -c and -o transpile C functions and #define constants from an in-memory fs.FS into Go source code","Task.Main returns a non-nil error when invoked on a nonexistent C input file"],"goal":"verify pkg:golang/modernc.org/ccgo/v4@v4.34.0","kind":"HOW","packages":["pkg:golang/modernc.org/ccgo/v4@v4.34.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/modernc.org/ccgo/v4@v4.34.0"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/ccgo/v4@v4.34.0","verifierAdapter":"golang@1"}
module example.com/ccgo-sample
go 1.25.0
require modernc.org/ccgo/v4 v4.34.0
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/tools v0.42.0 // indirect
modernc.org/cc/v4 v4.28.1 // indirect
modernc.org/gc/v2 v2.6.5 // indirect
modernc.org/gc/v3 v3.1.2 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/opt v0.2.0 // indirect
modernc.org/sortutil v1.2.1 // indirect
modernc.org/strutil v1.2.1 // indirect
modernc.org/token v1.1.0 // indirect
)
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
modernc.org/cc/v4 v4.28.1 h1:XpLbkYVQ24E8tX5u8+yWGvaxerxkR/S4zqxI8ZoSBuc=
modernc.org/cc/v4 v4.28.1/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.0 h1:yRLPFZieg532OT4rp4JFNIVcquwalMX26G95WQDqwCQ=
modernc.org/ccgo/v4 v4.34.0/go.mod h1:AS5WYMyBakQ+fhsHhtP8mWB82KTGPkNNJDGfGQCe0/A=
modernc.org/ccorpus2 v1.6.0 h1:JODbahvmixwZDoF1kZs/9Rj6aHA2vAPP7HKiNDq//xo=
modernc.org/ccorpus2 v1.6.0/go.mod h1:Wifvo4Q/qS/h1aRoC2TffcHsnxwTikmi1AuLANuucJQ=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/lex v1.1.1 h1:prSCNTLw1R4rn7M/RzwsuMtAuOytfyR3cnyM07P+Pas=
modernc.org/lex v1.1.1/go.mod h1:6r8o8DLJkAnOsQaGi8fMoi+Vt6LTbDaCrkUK729D8xM=
modernc.org/lexer v1.0.4 h1:hU7xVbZsqwPphyzChc7nMSGrsuaD2PDNOmzrzkS5AlE=
modernc.org/lexer v1.0.4/go.mod h1:tOajb8S4sdfOYitzCgXDFmbVJ/LE0v1fNJ7annTw36U=
modernc.org/libc v1.72.1 h1:db1xwJ6u1kE3KHTFTTbe2GCrczHPKzlURP0aDC4NGD0=
modernc.org/libc v1.72.1/go.mod h1:HRMiC/PhPGLIPM7GzAFCbI+oSgE3dhZ8FWftmRrHVlY=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/scannertest v1.0.2 h1:JPtfxcVdbRvzmRf2YUvsDibJsQRw8vKA/3jb31y7cy0=
modernc.org/scannertest v1.0.2/go.mod h1:RzTm5RwglF/6shsKoEivo8N91nQIoWtcWI7ns+zPyGA=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/modernc.org/ccgo/v4@v4.34.0",
"kind": "HOW",
"packages": [
"pkg:golang/modernc.org/ccgo/v4@v4.34.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"bytes"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing/fstest"
ccgo "modernc.org/ccgo/v4/lib"
)
func assert(cond bool, msg string) {
if !cond {
fmt.Fprintf(os.Stderr, "FAIL: %s\n", msg)
os.Exit(1)
}
}
func checkExecEnv() {
orig, hadOrig := os.LookupEnv("CCGO_EXEC_ENV")
defer func() {
if hadOrig {
_ = os.Setenv("CCGO_EXEC_ENV", orig)
} else {
_ = os.Unsetenv("CCGO_EXEC_ENV")
}
}()
assert(os.Unsetenv("CCGO_EXEC_ENV") == nil, "unset CCGO_EXEC_ENV")
assert(!ccgo.IsExecEnv(), "IsExecEnv should be false when CCGO_EXEC_ENV is unset")
assert(os.Setenv("CCGO_EXEC_ENV", "") == nil, "set empty CCGO_EXEC_ENV")
assert(!ccgo.IsExecEnv(), "IsExecEnv should be false when CCGO_EXEC_ENV is empty")
assert(os.Setenv("CCGO_EXEC_ENV", "1") == nil, "set non-empty CCGO_EXEC_ENV")
assert(ccgo.IsExecEnv(), "IsExecEnv should be true when CCGO_EXEC_ENV is non-empty")
}
func checkPreprocess() {
memFS := fstest.MapFS{
"defs.h": &fstest.MapFile{
Data: []byte("#define BASE_OFFSET 100\n"),
},
"input.c": &fstest.MapFile{
Data: []byte(`#include "defs.h"
#ifdef USE_BONUS
#define RESULT_EXPR (BASE_OFFSET + 23)
#else
#define RESULT_EXPR (BASE_OFFSET + 0)
#endif
int compute_value(void) {
return RESULT_EXPR;
}
`),
},
}
var stdout, stderr bytes.Buffer
args := []string{"ccgo", "-E", "-I.", "-DUSE_BONUS=1", "input.c"}
task := ccgo.NewTask(runtime.GOOS, runtime.GOARCH, args, &stdout, &stderr, memFS)
assert(task != nil, "NewTask should return a non-nil Task")
err := task.Main()
assert(err == nil, fmt.Sprintf("Task.Main -E failed: %v (stderr: %s)", err, stderr.String()))
assert(task.E, "Task.E should be true when -E flag is passed")
out := stdout.String()
assert(strings.Contains(out, "compute_value"), fmt.Sprintf("preprocessed output missing function name: %s", out))
assert(strings.Contains(out, "100") && strings.Contains(out, "23"), fmt.Sprintf("preprocessed output missing expanded macro values: %s", out))
assert(!strings.Contains(out, "BASE_OFFSET") && !strings.Contains(out, "RESULT_EXPR"), fmt.Sprintf("macros were not expanded: %s", out))
}
func checkCompile() {
memFS := fstest.MapFS{
"mathops.c": &fstest.MapFile{
Data: []byte(`#define SCALE_FACTOR 7
int multiply_add(int a, int b, int c) {
return (a * b) + c;
}
int scale_input(int x) {
return x * SCALE_FACTOR;
}
`),
},
}
tmpDir, err := os.MkdirTemp("", "ccgo-sample-*")
assert(err == nil, fmt.Sprintf("MkdirTemp failed: %v", err))
defer os.RemoveAll(tmpDir)
outPath := filepath.Join(tmpDir, "mathops.go")
var stdout, stderr bytes.Buffer
args := []string{"ccgo", "-c", "-o", outPath, "mathops.c"}
task := ccgo.NewTask(runtime.GOOS, runtime.GOARCH, args, &stdout, &stderr, memFS)
assert(task != nil, "NewTask for -c should return a non-nil Task")
err = task.Main()
assert(err == nil, fmt.Sprintf("Task.Main -c failed: %v (stderr: %s)", err, stderr.String()))
generated, err := os.ReadFile(outPath)
assert(err == nil, fmt.Sprintf("reading generated output failed: %v", err))
src := string(generated)
assert(strings.Contains(src, "package "), fmt.Sprintf("generated Go file missing package clause: %s", src))
assert(strings.Contains(src, "multiply_add"), fmt.Sprintf("generated Go file missing multiply_add: %s", src))
assert(strings.Contains(src, "scale_input"), fmt.Sprintf("generated Go file missing scale_input: %s", src))
}
func checkMissingFileError() {
memFS := fstest.MapFS{}
var stdout, stderr bytes.Buffer
args := []string{"ccgo", "-E", "does_not_exist.c"}
task := ccgo.NewTask(runtime.GOOS, runtime.GOARCH, args, &stdout, &stderr, memFS)
assert(task != nil, "NewTask for missing file should return a non-nil Task")
err := task.Main()
assert(err != nil, "Task.Main should return a non-nil error for a nonexistent input file")
}
func main() {
checkExecEnv()
checkPreprocess()
checkCompile()
checkMissingFileError()
fmt.Println("PASS")
}
原始种子者
匿名