Skip to content

fix(rocq_library): add self -Q even when out_dir is parent of dep paths#35

Merged
avrabe merged 1 commit into
mainfrom
fix/example-standalone-rocq-import
May 23, 2026
Merged

fix(rocq_library): add self -Q even when out_dir is parent of dep paths#35
avrabe merged 1 commit into
mainfrom
fix/example-standalone-rocq-import

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 23, 2026

What

Two-part fix that closes the standalone-build residual flagged in PR #34
(the rules_rust migration):

  1. rocq_library rule (rocq/private/rocq.bzl) — stop dropping the
    self -Q out_dir prefix whenever a dep's -Q dir lives underneath
    out_dir. coqc resolves overlapping -Q mappings by deepest-ancestor
    match per source, so a parent self--Q does not override a more
    specific dep -- the dep wins for its own files. Only skip when a dep
    already maps the exact same directory.

  2. examples/rust_to_rocq — give the translated point.v a
    position-stable Rocq logical prefix Example via include_path on
    both point_compiled and point_verified (they compete for the
    same output path, so Bazel only deduplicates the conflict if the args
    match). point_proofs.v imports as From Example Require Import point, which now resolves the same nested or standalone.

Why

The actual consequence of the over-cautious rocq_library check: when
out_dir was a parent directory (typical when a target lives in the root
package, e.g. building examples/rust_to_rocq as its own root module),
no self -Q reached the coqc command line — the compiled .vo got
no logical prefix, only the source basename. That broke any From <prefix> Require Import x import of a generated .v whose target
compiled at the bin root — and so the entire standalone build of the
example module.

Verified

Nix + Bazel, locally:

  • bazel test //tests:all //examples/rust_to_rocq:all (nested, root module is rules_rocq_rust) — 5/5 pass
  • cd examples/rust_to_rocq && bazel test //... (standalone, root module is the example) — 2/2 pass

Closes the known residual from #34.

🤖 Generated with Claude Code

`rocq_library` was deliberately skipping the self `-Q out_dir prefix`
whenever a dependency's `-Q` dir lived underneath `out_dir`, on the theory
that the self mapping would "override" the dep. That is incorrect: coqc
resolves overlapping `-Q dir prefix` mappings by deepest-ancestor match
per source file, so a parent self `-Q` does NOT override a more specific
dep -- the dep's mapping still wins for its own files.

The actual consequence: when out_dir was a parent (e.g. `bazel-out/.../bin`
in a standalone module), no self `-Q` reached the coqc command line, and
the compiled `.vo` had no logical prefix -- just the source basename. That
broke `From <prefix> Require Import x` imports of any generated `.v` whose
target compiled at the bin root, including the entire standalone build of
examples/rust_to_rocq.

Only skip when a dep already maps the exact same directory (where two
`-Q`s for one dir with different prefixes would be genuinely ambiguous).

Also pin examples/rust_to_rocq's point.v to a position-stable Rocq logical
prefix `Example` via `include_path` on both targets that compile it, so the
example's hand-written point_proofs.v import (`From Example Require Import
point`) resolves the same nested or standalone -- closes the residual
flagged in the rules_rust migration (#34).

Verified locally (nix + bazel):
- `bazel test //tests:all //examples/rust_to_rocq:all` (nested)  -> 5/5 pass
- `cd examples/rust_to_rocq && bazel test //...`     (standalone) -> 2/2 pass

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit 36184f0 into main May 23, 2026
7 checks passed
@avrabe avrabe deleted the fix/example-standalone-rocq-import branch May 23, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant