@@ -10,25 +10,42 @@ Bazel rules for Rocq/Coq theorem proving and Rust formal verification with herme
1010- ** Cross-Platform** : Linux, macOS (Intel & Apple Silicon)
1111- ** Bazel 8 bzlmod** : Modern module system support
1212
13- ## Prerequisites: Installing Nix
13+ ## Prerequisites
1414
15- ** Nix is required ** for the Rocq toolchain.
15+ ### Nix (Required)
1616
17- ### macOS
17+ Nix is required for the Rocq toolchain.
1818
19+ ** macOS:**
1920``` bash
2021sh <( curl -L https://nixos.org/nix/install)
2122. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
2223nix --version
2324```
2425
25- ### Linux
26-
26+ ** Linux:**
2727``` bash
2828sh <( curl -L https://nixos.org/nix/install) --daemon
2929nix --version
3030```
3131
32+ ### Rust Nightly (Linux only)
33+
34+ On Linux, rocq-of-rust requires Rust nightly with rustc internals:
35+
36+ ``` bash
37+ # Install nightly toolchain
38+ rustup toolchain install nightly-2024-12-01
39+
40+ # Add required components
41+ rustup component add rustc-dev rust-src --toolchain nightly-2024-12-01
42+
43+ # Set library path for LLVM (add to ~/.bashrc or ~/.zshrc)
44+ export LIBRARY_PATH=" $( rustc +nightly-2024-12-01 --print sysroot) /lib:$LIBRARY_PATH "
45+ ```
46+
47+ On macOS, Nix provides the complete Rust toolchain automatically.
48+
3249## Quick Start
3350
3451### 1. Add to MODULE.bazel
@@ -71,53 +88,174 @@ impl Point {
7188### 3. Add BUILD.bazel
7289
7390``` starlark
74- load(" @rules_rocq_rust//coq_of_rust:defs.bzl" , " coq_of_rust_library " )
91+ load(" @rules_rocq_rust//coq_of_rust:defs.bzl" , " rocq_rust_verified_library " )
7592load(" @rules_rocq_rust//rocq:defs.bzl" , " rocq_library" )
7693
77- # Translate Rust to Rocq
78- coq_of_rust_library (
79- name = " point_translated " ,
94+ # One-liner: translate and compile
95+ rocq_rust_verified_library (
96+ name = " point_verified " ,
8097 rust_sources = [" point.rs" ],
81- edition = " 2021" ,
82- )
83-
84- # Compile translated Rocq code
85- rocq_library(
86- name = " point_compiled" ,
87- srcs = [" :point_translated" ],
88- deps = [" @rocq_of_rust_source//:rocq_of_rust_main" ],
8998 extra_flags = [" -impredicative-set" ],
9099)
91100
92101# Write proofs about the Rust code
93102rocq_library(
94103 name = " point_proofs" ,
95104 srcs = [" point_proofs.v" ],
96- deps = [" :point_compiled " , " @rocq_of_rust_source//:rocq_of_rust_main " ],
105+ deps = [" :point_verified " ],
97106 extra_flags = [" -impredicative-set" ],
98107)
99108```
100109
101110### 4. Build and verify
102111
103112``` bash
104- # Translate and compile
105- bazel build //:point_compiled
106-
107- # Verify proofs
108113bazel build //:point_proofs
109114```
110115
116+ ## API Reference
117+
118+ ### rocq_library
119+
120+ Compiles Rocq ` .v ` files to ` .vo ` .
121+
122+ ``` starlark
123+ rocq_library(
124+ name = " my_proofs" ,
125+ srcs = [" proof.v" ],
126+ deps = [" :other_library" ],
127+ include_path = " MyProject" , # Logical path prefix
128+ extra_flags = [" -impredicative-set" ],
129+ )
130+ ```
131+
132+ | Attribute | Description |
133+ | -----------| -------------|
134+ | ` srcs ` | Rocq source files (` .v ` ) |
135+ | ` deps ` | Dependencies on other ` rocq_library ` targets |
136+ | ` include_path ` | Logical path for this library (default: package path) |
137+ | ` extra_flags ` | Extra flags passed to coqc |
138+
139+ ### coq_of_rust_library
140+
141+ Translates Rust source files to Rocq.
142+
143+ ``` starlark
144+ coq_of_rust_library(
145+ name = " translated" ,
146+ rust_sources = [" lib.rs" ],
147+ edition = " 2021" ,
148+ )
149+ ```
150+
151+ | Attribute | Description |
152+ | -----------| -------------|
153+ | ` rust_sources ` | Rust source files to translate |
154+ | ` edition ` | Rust edition (default: "2021") |
155+
156+ ### rocq_rust_verified_library
157+
158+ Convenience macro: translates Rust to Rocq and compiles.
159+
160+ ``` starlark
161+ rocq_rust_verified_library(
162+ name = " verified" ,
163+ rust_sources = [" lib.rs" ],
164+ edition = " 2021" ,
165+ deps = [], # Additional Rocq dependencies
166+ extra_flags = [" -impredicative-set" ],
167+ )
168+ ```
169+
170+ ### rocq_proof_test
171+
172+ Test rule that verifies proofs compile successfully.
173+
174+ ``` starlark
175+ rocq_proof_test(
176+ name = " proofs_test" ,
177+ srcs = [" proofs.v" ],
178+ deps = [" :proofs" ],
179+ )
180+ ```
181+
182+ ## Configuration Options
183+
184+ ### rocq_of_rust.toolchain()
185+
186+ ``` starlark
187+ rocq_of_rust.toolchain(
188+ use_real_library = True , # Use full RocqOfRust library (recommended)
189+ fail_on_error = True , # Fail if rocq-of-rust build fails (default: True)
190+ rust_nightly = " nightly-2024-12-01" , # Rust nightly version
191+ )
192+ ```
193+
194+ | Option | Description |
195+ | --------| -------------|
196+ | ` use_real_library ` | Use full RocqOfRust library with coqutil/hammer/smpl |
197+ | ` fail_on_error ` | Fail build if rocq-of-rust cannot be built |
198+ | ` rust_nightly ` | Rust nightly version for building rocq-of-rust |
199+
200+ ## Troubleshooting
201+
202+ ### "unable to find library -lLLVM-19-rust-* " (Linux)
203+
204+ The Rust nightly compiler bundles its own LLVM. Set ` LIBRARY_PATH ` :
205+
206+ ``` bash
207+ export LIBRARY_PATH=" $( rustc +nightly-2024-12-01 --print sysroot) /lib:$LIBRARY_PATH "
208+ ```
209+
210+ ### "cargo not found"
211+
212+ Install Rust via rustup:
213+
214+ ``` bash
215+ curl --proto ' =https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
216+ ```
217+
218+ ### "rustc-dev component not found"
219+
220+ Install the required nightly components:
221+
222+ ``` bash
223+ rustup component add rustc-dev rust-src --toolchain nightly-2024-12-01
224+ ```
225+
226+ ### Build fails silently with placeholder
227+
228+ By default, builds fail loudly. If you see placeholder output, check the build logs for the actual error. To debug, run:
229+
230+ ``` bash
231+ bazel build @rocq_of_rust_source//:rocq_of_rust_main --verbose_failures
232+ ```
233+
234+ ### Proofs fail with "reference not found"
235+
236+ Ensure the translated code compiled successfully first:
237+
238+ ``` bash
239+ bazel build //:point_compiled
240+ ```
241+
242+ Then check that your proof imports match the generated module names.
243+
111244## Example
112245
113- See ` examples/rust_to_rocq/ ` for a complete working example with:
114- - ` point.rs ` - Rust source code
115- - Translated ` point.v ` (auto-generated)
116- - ` point_proofs.v ` - Formal proofs about the Rust code
246+ See ` examples/rust_to_rocq/ ` for a complete working example:
247+
248+ - ` point.rs ` - Rust source with Point and Rectangle structs
249+ - ` advanced.rs ` - Generics, traits, lifetimes, enums
250+ - ` point_proofs.v ` - Formal proofs about the translated code
117251
118252``` bash
119- # Build the example
253+ # Build all examples
120254bazel build //examples/rust_to_rocq:point_proofs
255+ bazel build //examples/rust_to_rocq:advanced_verified
256+
257+ # Run proof tests
258+ bazel test //examples/rust_to_rocq:point_proofs_test
121259```
122260
123261## How It Works
@@ -129,15 +267,13 @@ bazel build //examples/rust_to_rocq:point_proofs
129267
130268## Toolchain Contents
131269
132- The nixpkgs-based toolchain provides:
133-
134270| Component | Description |
135271| -----------| -------------|
136272| Rocq 9.0 | Core theorem prover |
137273| coqutil | Utility library |
138274| Hammer | Automated proof tactics |
139275| smpl | Simplification tactics |
140- | rocq-of-rust | Rust-to-Rocq translator |
276+ | rocq-of-rust | Rust-to-Rocq translator (pinned version) |
141277
142278## Supported Platforms
143279
0 commit comments