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.
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.
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.
Building 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 configure script
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-linux, arm-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 (make -j1 instead of parallel)
Consider adding swap space if in a container that allows it
Monitor memory usage during proof checking phases
Installation and Verification
After successful build:
Note where ccomp binary is installed
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