Skip to content

pulseengine/rules_rocq_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rules_rocq_rust

Bazel rules for Rocq/Coq theorem proving with hermetic toolchain support via Nix.

Prerequisites: Installing Nix

Nix is required for the Rocq toolchain. The toolchain uses nixpkgs to provide hermetic Coq installations across all platforms.

macOS

# Install Nix (multi-user installation, recommended)
sh <(curl -L https://nixos.org/nix/install)

# Restart your terminal, or source the nix profile:
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

# Verify installation
nix --version

Linux

# Install Nix (multi-user installation)
sh <(curl -L https://nixos.org/nix/install) --daemon

# Restart your terminal or start a new shell
# Verify installation
nix --version

Windows (via WSL2)

# In WSL2 Ubuntu/Debian:
sh <(curl -L https://nixos.org/nix/install) --no-daemon

# Verify installation
nix --version

Verify Coq is Available

# Test that Coq can be fetched from nixpkgs
nix-shell -p coq --run "coqc --version"

Features

  • Hermetic Toolchains: Coq toolchain provided via nixpkgs for reproducible builds
  • Cross-Platform: Linux (x86_64, aarch64), macOS (x86_64, aarch64)
  • Multiple Coq Versions: 8.20, 8.19, 8.18, 8.17, 8.16
  • Bazel 8 bzlmod: Modern module system support
  • Rocq Platform Integration: Provides equivalent tools to Rocq Platform
  • coq-of-rust Support: Planned integration for Rust-to-Coq translation
  • Reproducible: Pinned nixpkgs commit for deterministic builds

Quick Start

1. Add to your MODULE.bazel

bazel_dep(name = "rules_rocq_rust", version = "0.1.0")

# Override to fetch from GitHub (not yet in BCR)
git_override(
    module_name = "rules_rocq_rust",
    remote = "https://github.com/pulseengine/rules_rocq_rust.git",
    commit = "<latest-commit>",
)

# Configure Rocq toolchain
rocq = use_extension("@rules_rocq_rust//rocq:extensions.bzl", "rocq")
rocq.toolchain(
    version = "8.20",  # Coq version
    strategy = "nix",  # Hermetic nix-based installation
)
use_repo(rocq, "rocq_toolchains")

register_toolchains("@rocq_toolchains//:all")

2. Create proof files

(* proofs/example.v *)
Theorem plus_comm : forall n m : nat, n + m = m + n.
Proof.
  intros n m.
  induction n as [| n' IHn'].
  - simpl. rewrite Nat.add_0_r. reflexivity.
  - simpl. rewrite IHn'. rewrite Nat.add_succ_r. reflexivity.
Qed.

3. Add BUILD.bazel

load("@rules_rocq_rust//rocq:defs.bzl", "rocq_library", "rocq_proof_test")

rocq_library(
    name = "example_proofs",
    srcs = ["example.v"],
)

rocq_proof_test(
    name = "example_test",
    srcs = ["example.v"],
    deps = [":example_proofs"],
)

4. Build and test

# Build proofs
bazel build //proofs:example_proofs

# Run proof tests
bazel test //proofs:example_test

How It Works

First Build (one-time setup)

On the first build, Bazel will:

  1. Fetch the pinned nixpkgs repository (~200MB download)
  2. Use nix to fetch/build Coq from nixpkgs cache (~100MB)
  3. Cache everything in ~/.cache/bazel/

This takes 5-10 minutes depending on your internet connection.

Subsequent Builds

After initial setup:

  • Toolchain is cached locally
  • No nix invocation needed
  • Builds are fast and hermetic

Supported Platforms

Platform Architecture Status
Linux x86_64 ✅ Supported
Linux aarch64 ✅ Supported
macOS x86_64 (Intel) ✅ Supported
macOS aarch64 (Apple Silicon) ✅ Supported
Windows x86_64 ⚠️ Via WSL2 only

Coq Versions

Available Coq versions via nixpkgs:

Version nixpkgs attribute Status
8.20 coq_8_20 ✅ Default
8.19 coq_8_19 ✅ Supported
8.18 coq_8_18 ✅ Supported
8.17 coq_8_17 ✅ Supported
8.16 coq_8_16 ✅ Supported
latest coq ✅ Supported

To use a specific version:

rocq.toolchain(
    version = "8.19",  # Use Coq 8.19
    strategy = "nix",
)

Examples

See the proofs/ directory for example usage:

# Build example proofs
bazel build //proofs:all

# Test proofs compile
bazel test //proofs:...

Toolchain Management

The toolchain is managed via nixpkgs, providing hermetic Coq installations:

  • Pinned nixpkgs: Reproducible builds with fixed commit
  • Multiple versions: Switch Coq versions via version attribute
  • Cross-platform: Same configuration works on Linux and macOS

Rocq Platform Integration

While we use nixpkgs instead of Rocq Platform binaries, the toolchain provides equivalent functionality:

  • Coq compiler and tools
  • Standard library
  • Documentation generator

coq-of-rust Support

coq-of-rust integration is planned for future releases. The rocq_library rule can compile Coq files generated by coq-of-rust.

Toolchain Contents

The nix toolchain provides:

Tool Description
coqc Coq compiler
coqtop Interactive toplevel
coqdoc Documentation generator
coqchk Proof checker
Standard Library lib/coq/theories/

Troubleshooting

"nix: command not found"

Nix is not installed or not in PATH. See Installing Nix.

"error: cannot connect to daemon"

The nix daemon isn't running:

# macOS/Linux with systemd
sudo systemctl start nix-daemon

# macOS without systemd
sudo launchctl start org.nixos.nix-daemon

Slow first build

The first build downloads nixpkgs and Coq. This is normal and only happens once. Subsequent builds use the cached toolchain.

"hash mismatch" errors

The nixpkgs commit hash may have changed. Update the hash in MODULE.bazel or wait for a rules_rocq_rust update.

Development

Running Tests

# Verify rules load correctly
bazel query //rocq/...

# Build all targets
bazel build //...

Updating nixpkgs

To update the pinned nixpkgs version:

  1. Find a recent commit from NixOS/nixpkgs
  2. Compute SHA256: nix-prefetch-url --unpack https://github.com/NixOS/nixpkgs/archive/<commit>.tar.gz
  3. Update MODULE.bazel with new commit and sha256

License

Apache License 2.0 - See LICENSE file

Related Projects

About

Bazel rules for Rocq theorem proving and coq-of-rust integration with hermetic toolchain support

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •