Claude-skill-registry compile-compcert
Guidance for building CompCert, a formally verified C compiler. This skill applies when tasks involve compiling CompCert from source, setting up Coq/OCaml environments with opam, or building software with strict proof assistant dependencies. Use for CompCert compilation, Coq-dependent project builds, or formal verification toolchain setup.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/compile-compcert" ~/.claude/skills/majiayu000-claude-skill-registry-compile-compcert && rm -rf "$T"
skills/data/compile-compcert/SKILL.mdBuilding CompCert (Verified C Compiler)
Overview
CompCert is a formally verified optimizing C compiler. Building it requires careful coordination of Coq (proof assistant), OCaml, and Menhir (parser generator) versions. The primary challenge is ensuring version compatibility across all dependencies before beginning compilation.
Critical Pre-Build Analysis
Before installing any dependencies, perform these steps in order:
1. Obtain Source First
Download and extract the CompCert source before installing dependencies:
- Download the specific version tarball from GitHub releases or official mirrors
- Extract and locate the
scriptconfigure - Read the configure script to identify supported Coq versions
2. Check Version Requirements
Examine CompCert's configure script to find exact dependency requirements:
- Supported Coq version range (often specific minor versions only)
- Required OCaml version
- Required Menhir version
- The configure script typically contains explicit version checks
3. Verify System Compatibility
Check system requirements before proceeding:
- Architecture (x86_64 is most commonly supported for full backend)
- Operating system (Linux is primary target)
- Available memory (builds can be memory-intensive)
- Disk space for build artifacts
Dependency Installation Approach
Environment Setup with opam
CompCert requires opam (OCaml Package Manager) for managing OCaml and Coq:
- Initialize opam if not already done
- Create a switch with appropriate OCaml version
- Set up the environment:
eval $(opam env) - Install dependencies in correct order: OCaml → Menhir → Coq
Version Selection Strategy
To avoid wasted effort from incompatible versions:
- Check CompCert's configure script BEFORE installing Coq
- Install the highest compatible Coq version within the supported range
- Ensure Menhir version matches requirements
- Verify all versions after installation
Build Process
Configuration
Run configure with appropriate target:
- Common targets:
,x86_64-linux
,x86_32-linuxarm-linux - Check available targets with
./configure --help - Note the installation prefix and binary locations
Compilation
Build considerations:
- Full build includes proof checking and can be memory-intensive
- If encountering OOM (Out of Memory) errors:
- Reduce parallel jobs (
instead of parallel)make -j1 - Consider adding swap space if in a container that allows it
- Monitor memory usage during proof checking phases
- Reduce parallel jobs (
Installation and Verification
After successful build:
- Note where
binary is installedccomp - Create symlinks if binary needs to be at a specific location
- Test with a simple C program compilation
- Verify the reported version matches expected version
Common Pitfalls
Dependency Order Mistakes
- Installing Coq before checking CompCert's requirements wastes time
- Multiple failed installation attempts consume significant resources
- Always read project requirements before installing dependencies
Memory Issues
- Coq proof checking is memory-intensive
- Container environments may have memory limits
- Swap creation may be restricted in some environments
- Sequential builds (
) use less memory than parallel builds-j1
Environment Persistence
- opam environment must be sourced in each shell session
needed before running opam-installed toolseval $(opam env)- Consider setting up persistent environment configuration
Version Verification
- CompCert version reported at runtime may differ from release tag
- Version 3.13.1 source may report as "3.13" at runtime
- Verify functionality rather than relying solely on version strings
Verification Checklist
Before considering the task complete:
- Binary exists at required location
-
executes without errorccomp --version - Simple C program compiles successfully
- Generated executable runs correctly
- Any linker warnings are understood (some are benign)
Resource Management
Cleanup Considerations
After successful build:
- Source tarballs can be removed
- Extracted source directories may be kept for reference or removed
- Build artifacts in source tree consume significant space
Security Notes
- Verify source downloads against official checksums when available
- Building from official release tarballs preferred over arbitrary commits
- Note and investigate any unexpected warnings during compilation