CodeSampleX

Exemple

modernc.org/ccgo/v4 v4.34.6

Échantillon vérifié pour golang modernc.org/ccgo/v4 v4.34.6. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:f23fe9810bf17578472b820f3c9ce2373bd9dfb75a061890ee97a947b7d9be01

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 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-09-16

Cas

HOW
Objectif
verify pkg:golang/modernc.org/ccgo/v4@v4.34.6
Paquets
Créé
2026-09-16T01:20:23Z

Contrat

  1. NewTask creates a Task compiler job configured for target OS and architecture
  2. Task.Main transpiles C code with -c to Go code containing transpiled function definitions
  3. Task.Main transpiles preprocessor define macros to Go constants
  4. Task.Main returns an error when given invalid arguments or nonexistent source files
  5. IsExecEnv returns false outside a ccgo exec environment

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Télécharger l’artefact source (tar.gz)

Code source

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:golang/modernc.org/ccgo/v4@v4.34.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/modernc.org/ccgo/v4@v4.34.6

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:ec3834281c25eec8bbbee0dc7ea6e4f504964bdbc55ae0bdcdaa19d3346d58ec","contract":["NewTask creates a Task compiler job configured for target OS and architecture","Task.Main transpiles C code with -c to Go code containing transpiled function definitions","Task.Main transpiles preprocessor define macros to Go constants","Task.Main returns an error when given invalid arguments or nonexistent source files","IsExecEnv returns false outside a ccgo exec environment"],"goal":"verify pkg:golang/modernc.org/ccgo/v4@v4.34.6","kind":"HOW","packages":["pkg:golang/modernc.org/ccgo/v4@v4.34.6"],"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.6"],"schemaVersion":1,"subject":"pkg:golang/modernc.org/ccgo/v4@v4.34.6","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require modernc.org/ccgo/v4 v4.34.6

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.37.0 // indirect
	golang.org/x/sync v0.21.0 // indirect
	golang.org/x/tools v0.46.0 // indirect
	modernc.org/cc/v4 v4.29.0 // indirect
	modernc.org/gc/v2 v2.6.5 // indirect
	modernc.org/gc/v3 v3.1.4 // 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
)
go.sum
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.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.46.0 h1:7jTurBkPZu4moS/Uy4OQT1M+QBlsj3wejyZwsT8Z7rk=
golang.org/x/tools v0.46.0/go.mod h1:FrD85F8l+NWL+9XWBSyVSHO6Ne4jutsfIFba7AWQ5Ys=
modernc.org/cc/v4 v4.29.0 h1:CXgwL8cvxmyzBQZzbSl/6xFtMCryb6u8IOqDci39cgc=
modernc.org/cc/v4 v4.29.0/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
modernc.org/ccgo/v4 v4.34.6/go.mod h1:SZ8YcN9NG7XVsQYdm6jYBvi8PQP1qi+kqB6OhjqI3Fk=
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.4 h1:2g65LGVSmFQrXeITAw97x7hCRvZFcyE1uDP+7Vng7JI=
modernc.org/gc/v3 v3.1.4/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.73.5 h1:G34rN/cRqL+zOUnrbz9uPq/+OxJ8/vzQ2CQwTJ42Wmw=
modernc.org/libc v1.73.5/go.mod h1:+Aoyx4M0etg6GikzCrip1VtvAtUlMlo2Aq+GHwQSqOA=
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=
main.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"strings"

	ccgo "modernc.org/ccgo/v4/lib"
)

func main() {
	tmpDir, err := os.MkdirTemp("", "ccgo-demo-*")
	if err != nil {
		panic(err)
	}
	defer os.RemoveAll(tmpDir)

	cFile := filepath.Join(tmpDir, "demo.c")
	goFile := filepath.Join(tmpDir, "demo.o.go")

	cCode := `
#define MULTIPLIER 2

int double_val(int x) {
    return x * MULTIPLIER;
}
`
	if err := os.WriteFile(cFile, []byte(cCode), 0644); err != nil {
		panic(err)
	}

	var stdout, stderr bytes.Buffer
	task := ccgo.NewTask(
		runtime.GOOS,
		runtime.GOARCH,
		[]string{"ccgo", "-nostdinc", "-c", "-o", goFile, cFile},
		&stdout,
		&stderr,
		nil,
	)

	if err := task.Main(); err != nil {
		fmt.Fprintf(os.Stderr, "Transpilation failed: %v\nstderr: %s\n", err, stderr.String())
		os.Exit(1)
	}

	output, err := os.ReadFile(goFile)
	if err != nil {
		panic(err)
	}

	fmt.Println("Transpiled Go code successfully:")
	for _, line := range strings.Split(string(output), "\n") {
		if strings.HasPrefix(line, "func X") || strings.HasPrefix(line, "const mvMULTIPLIER") {
			fmt.Println(" ", line)
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/modernc.org/ccgo/v4@v4.34.6",
  "kind": "HOW",
  "packages": [
    "pkg:golang/modernc.org/ccgo/v4@v4.34.6"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"strings"

	ccgo "modernc.org/ccgo/v4/lib"
)

func main() {
	// Assertion 1: NewTask creates a Task compiler job configured for target OS and architecture
	task := ccgo.NewTask("linux", "amd64", []string{"ccgo"}, nil, nil, nil)
	if task == nil {
		fmt.Fprintf(os.Stderr, "FAIL: NewTask returned nil\n")
		os.Exit(1)
	}

	tmpDir, err := os.MkdirTemp("", "ccgo-contract-*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MkdirTemp failed: %v\n", err)
		os.Exit(1)
	}
	defer os.RemoveAll(tmpDir)

	// Assertion 2: Task.Main transpiles C code with -c to Go code containing transpiled function definitions
	squareC := filepath.Join(tmpDir, "square.c")
	squareGo := filepath.Join(tmpDir, "square.o.go")
	cFuncCode := "int square(int n) { return n * n; }\n"
	if err := os.WriteFile(squareC, []byte(cFuncCode), 0644); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: WriteFile square.c failed: %v\n", err)
		os.Exit(1)
	}

	var stdout, stderr bytes.Buffer
	compileTask := ccgo.NewTask(
		runtime.GOOS,
		runtime.GOARCH,
		[]string{"ccgo", "-nostdinc", "-c", "-o", squareGo, squareC},
		&stdout,
		&stderr,
		nil,
	)
	if err := compileTask.Main(); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Task.Main compile square.c failed: %v, stderr: %s\n", err, stderr.String())
		os.Exit(1)
	}

	content, err := os.ReadFile(squareGo)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ReadFile square.o.go failed: %v\n", err)
		os.Exit(1)
	}
	if !strings.Contains(string(content), "func Xsquare") {
		fmt.Fprintf(os.Stderr, "FAIL: square.o.go missing transpiled func Xsquare: %s\n", string(content))
		os.Exit(1)
	}

	// Assertion 3: Task.Main transpiles preprocessor define macros to Go constants
	macroC := filepath.Join(tmpDir, "macro.c")
	macroGo := filepath.Join(tmpDir, "macro.o.go")
	cMacroCode := "#define MAX_BUFFER_SIZE 1024\nint get_size(void) { return MAX_BUFFER_SIZE; }\n"
	if err := os.WriteFile(macroC, []byte(cMacroCode), 0644); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: WriteFile macro.c failed: %v\n", err)
		os.Exit(1)
	}

	stdout.Reset()
	stderr.Reset()
	macroTask := ccgo.NewTask(
		runtime.GOOS,
		runtime.GOARCH,
		[]string{"ccgo", "-nostdinc", "-c", "-o", macroGo, macroC},
		&stdout,
		&stderr,
		nil,
	)
	if err := macroTask.Main(); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Task.Main compile macro.c failed: %v, stderr: %s\n", err, stderr.String())
		os.Exit(1)
	}

	macroContent, err := os.ReadFile(macroGo)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ReadFile macro.o.go failed: %v\n", err)
		os.Exit(1)
	}
	if !strings.Contains(string(macroContent), "const mvMAX_BUFFER_SIZE = 1024") {
		fmt.Fprintf(os.Stderr, "FAIL: macro.o.go missing const mvMAX_BUFFER_SIZE: %s\n", string(macroContent))
		os.Exit(1)
	}
	if !strings.Contains(string(macroContent), "func Xget_size") {
		fmt.Fprintf(os.Stderr, "FAIL: macro.o.go missing func Xget_size: %s\n", string(macroContent))
		os.Exit(1)
	}

	// Assertion 4: Task.Main returns an error when given invalid arguments or nonexistent source files
	stdout.Reset()
	stderr.Reset()
	errTask := ccgo.NewTask(
		runtime.GOOS,
		runtime.GOARCH,
		[]string{"ccgo", "-c", "-o", filepath.Join(tmpDir, "nonexistent.o.go"), filepath.Join(tmpDir, "nonexistent_source_file.c")},
		&stdout,
		&stderr,
		nil,
	)
	if err := errTask.Main(); err == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Task.Main unexpectedly succeeded for nonexistent file\n")
		os.Exit(1)
	}

	// Assertion 5: IsExecEnv returns false outside a ccgo exec environment
	if ccgo.IsExecEnv() {
		fmt.Fprintf(os.Stderr, "FAIL: IsExecEnv returned true outside exec environment\n")
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed.")
}

Seeder d'origine

anonyme