Repository navigation
fix: auto-inject menhir lower bound in generated opam files - #14168
Merged
Leonidas-from-XIV merged 5 commits intoApr 15, 2026
Merged
Leonidas-from-XIV merged 5 commits into
Leonidas-from-XIV merged 5 commits into
Conversation
When a project uses (using menhir ...), the generated opam file should include a lower bound on menhir (>= 20180523) since dune assumes support for --infer-write-query and --infer-read-reply. Signed-off-by: Robin Bate Boerop <[email protected]>
) When a project uses (using menhir ...), dune assumes menhir supports --infer-write-query and --infer-read-reply (available since 20180523). Auto-inject "menhir" {>= "20180523"} into generated opam files, following the same pattern as the existing dune and odoc auto-injected deps. Signed-off-by: Robin Bate Boerop <[email protected]>
Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
marked this pull request as ready for review
April 13, 2026 03:19
Leonidas-from-XIV
requested changes
Apr 13, 2026
Leonidas-from-XIV
left a comment
Member
There was a problem hiding this comment.
It's a good improvement, I was frustrated by this myself a number of times.
- Add comment explaining why 20180523 is the minimum menhir version - Replace recursive loop with List.exists + List.map - Simplify grep usage in cram test (drop useless cat) - Expand changelog entry with rationale Signed-off-by: Robin Bate Boerop <[email protected]>
Leonidas-from-XIV
requested changes
Apr 14, 2026
Leonidas-from-XIV
left a comment
Member
There was a problem hiding this comment.
Unless I am missing something, the two List.rev are probably unnecessary.
Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir lower-bound auto-injection (ocaml#14168) was triggered purely by the project-wide `(using menhir ...)` extension, which caused every package's generated opam file to gain a `menhir` build-time dependency — even packages that did not contain a `(menhir ...)` stanza, did not reference any menhir-generated module, or did not link any OCaml source at all. The released 3.23 behaviour is over-broad in three independent ways. This patch tightens the injection so the menhir dep lands only where it is actually needed. A package's opam file gains the dep only if the project contains, in some dune file, a `(menhir ...)` stanza alongside a stanza attributed to that package which: - compiles OCaml modules (`(library ...)`, `(executable[s] ...)`, `(test[s] ...)`, `(melange.emit ...)` — install / alias / rule / documentation / coq / rocq / plugin no longer count); AND - selects a module produced by the menhir stanza, determined by intersecting the two `(modules ...)` fields syntactically (handling `:standard`, explicit literals, `:standard \ ...` exclusions, with a conservative `Any` for `(:include ...)` and `pform` cases that cannot be resolved without file I/O — we never falsely report an empty intersection). When the only menhir consumer of a package is a `(test[s] ...)` stanza, the opam dep is filtered by `{with-test}` to match the generated build commands, which run `@runtest` only under `{with-test}`. `packages_using_menhir` takes a `Context_name.t` because `Dune_load.dune_files` is indexed per-context (an OCaml-syntax dune file can emit different stanzas per context via `%{context_name}`). Rule-generation callers pass the context whose opam files they are producing; `dune describe opam-files`, which is workspace-wide, picks the first valid build context. Test plan: seven new cram tests under `test/blackbox-tests/test-cases/menhir/`: - `opam-menhir-dep-multi-package.t` — three packages, only some use menhir; only those gain the dep. - `opam-menhir-dep-no-menhir-stanzas.t` — `(using menhir ...)` enabled, no `(menhir ...)` stanza anywhere; no package gains the dep (the strongest direct test of the regression fix). - `opam-menhir-dep-install-stanza.t` — an `(install ...)` stanza co-located with `(menhir ...)` does not drag its package in. - `opam-menhir-dep-shared-dir.t` — two libraries in different packages share a directory with `(menhir ...)`; only the library that actually consumes the menhir output gains the dep, including a `:standard \ p` variant. - `opam-menhir-dep-tests-only.t` — a tests-only consumer gets `"menhir" {with-test & >= "20180523"}`, not unconditional. - `opam-menhir-dep-custom-context.t` — workspace renames the default context; opam build still succeeds. - `opam-menhir-dep-inside-opam-dir.t` — `(opam_file_location inside_opam_directory)` mode still attributes correctly. Plus updates to `opam-menhir-dep.t` so its three cases still exercise the auto-injection now that a real `(menhir ...)` stanza is required. Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir lower-bound auto-injection (ocaml#14168) was triggered purely by the project-wide `(using menhir ...)` extension, which caused every package's generated opam file to gain a `menhir` build-time dependency — even packages that did not contain a `(menhir ...)` stanza, did not reference any menhir-generated module, or did not link any OCaml source at all. The released 3.23 behaviour is over-broad in three independent ways. This patch tightens the injection so the menhir dep lands only where it is actually needed. A package's opam file gains the dep only if the project contains, in some dune file, a `(menhir ...)` stanza alongside a stanza attributed to that package which: - compiles OCaml modules (`(library ...)`, `(executable[s] ...)`, `(test[s] ...)`, `(melange.emit ...)` — install / alias / rule / documentation / coq / rocq / plugin no longer count); AND - selects a module produced by the menhir stanza, determined by intersecting the two `(modules ...)` fields syntactically (handling `:standard`, explicit literals, `:standard \ ...` exclusions, with a conservative `Any` for `(:include ...)` and `pform` cases that cannot be resolved without file I/O — we never falsely report an empty intersection). When the only menhir consumer of a package is a `(test[s] ...)` stanza, the opam dep is filtered by `{with-test}` to match the generated build commands, which run `@runtest` only under `{with-test}`. `packages_using_menhir` takes a `Context_name.t` because `Dune_load.dune_files` is indexed per-context (an OCaml-syntax dune file can emit different stanzas per context via `%{context_name}`). Rule-generation callers pass the context whose opam files they are producing; `dune describe opam-files`, which is workspace-wide, picks the first valid build context. Test plan: seven new cram tests under `test/blackbox-tests/test-cases/menhir/`: - `opam-menhir-dep-multi-package.t` — three packages, only some use menhir; only those gain the dep. - `opam-menhir-dep-no-menhir-stanzas.t` — `(using menhir ...)` enabled, no `(menhir ...)` stanza anywhere; no package gains the dep (the strongest direct test of the regression fix). - `opam-menhir-dep-install-stanza.t` — an `(install ...)` stanza co-located with `(menhir ...)` does not drag its package in. - `opam-menhir-dep-shared-dir.t` — two libraries in different packages share a directory with `(menhir ...)`; only the library that actually consumes the menhir output gains the dep, including a `:standard \ p` variant. - `opam-menhir-dep-tests-only.t` — a tests-only consumer gets `"menhir" {with-test & >= "20180523"}`, not unconditional. - `opam-menhir-dep-custom-context.t` — workspace renames the default context; opam build still succeeds. - `opam-menhir-dep-inside-opam-dir.t` — `(opam_file_location inside_opam_directory)` mode still attributes correctly. Plus updates to `opam-menhir-dep.t` so its three cases still exercise the auto-injection now that a real `(menhir ...)` stanza is required. Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a new dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. Restrict the behaviour to that. - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in, as before. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a new dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. Restrict the behaviour to that. - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in, as before. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a new dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. Restrict the behaviour to that. - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in, as before. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 6, 2026
Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a new dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. Restrict the behaviour to that. - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in, as before. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. Signed-off-by: Robin Bate Boerop <[email protected]>
Leonidas-from-XIV
pushed a commit
that referenced
this pull request
May 7, 2026
…14434) ## Summary Fixes #14428. The 3.23 menhir auto-injection (#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a *new* dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in #10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. This PR restricts the behaviour to that. ## Behaviour - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. - Gated on `(using menhir ...)` being enabled — without the extension, no upgrade. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of #14428 and out of scope for #10707. --------- Signed-off-by: Robin Bate Boerop <[email protected]>
Sudha247
pushed a commit
to Sudha247/dune
that referenced
this pull request
May 7, 2026
…caml#14434) ## Summary Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a *new* dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. This PR restricts the behaviour to that. ## Behaviour - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. - Gated on `(using menhir ...)` being enabled — without the extension, no upgrade. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. --------- Signed-off-by: Robin Bate Boerop <[email protected]> (cherry picked from commit b471f2f) Signed-off-by: Sudha Parimala <[email protected]>
Sudha247
pushed a commit
to Sudha247/dune
that referenced
this pull request
May 7, 2026
…caml#14434) ## Summary Fixes ocaml#14428. The 3.23 menhir auto-injection (ocaml#14168) was triggered by the project-wide `(using menhir ...)` extension and added `menhir` as a *new* dependency to every package's generated opam file, regardless of whether the package's own `(depends ...)` field declared it. In multi-package projects where only some packages used menhir, every package gained a spurious build-time dependency. The original ask in ocaml#10707 was narrower: when a generated opam file *already* lists `menhir`, fill in the lower bound `{>= "20180523"}` that dune's menhir rules require. This PR restricts the behaviour to that. ## Behaviour - A package that does not declare `(depends menhir)` no longer has `menhir` added by dune. - A package that declares bare `(depends menhir)` has the lower bound filled in. - A package whose `(depends ...)` already specifies a constraint (version bound, `{with-test}`, etc.) is preserved verbatim. - Gated on `(using menhir ...)` being enabled — without the extension, no upgrade. The convenience of auto-adding `menhir` for users who use a `(menhir ...)` stanza but forget to declare `(depends menhir)` is deliberately removed: the dependency-inference logic that supported it was the source of ocaml#14428 and out of scope for ocaml#10707. --------- Signed-off-by: Robin Bate Boerop <[email protected]> (cherry picked from commit b471f2f) Signed-off-by: Sudha Parimala <[email protected]>
Contributor
|
This PR adds menhir dependency to all packages! It should only be for the packages that need it. |
Collaborator
Contributor
robinbb
added a commit
to robinbb/dune
that referenced
this pull request
May 13, 2026
Adds a tier between the existing < 3.23 skip and the post-PR full merge behaviour, so that [(lang dune 3.23)] projects keep the pre-ocaml#14453 behaviour they shipped under and avoid silent changes to opam output on dune-binary upgrade. [merge_dune_constraints] (dune-package side): - >= 3.24: enhanced rewrite/normalise (this PR's new behaviour). - >= 3.23: [merge_dune_constraints_simple] — the pre-ocaml#14453 simple dedup body (resurrected). Preserves the ocaml#14436 / ocaml#14466 behaviour shipped in 3.23.1. - else: bare [And [lang_constraint; user_constraint]]. [upgrade_menhir_constraint] (menhir-package side): - >= 3.24: full upgrade — bare-fill plus [merge_menhir_constraint] for user-written constraints (this PR's new behaviour). - >= 3.23: [upgrade_menhir_constraint_simple] — the pre-ocaml#14453 bare-fill-only body (resurrected). Preserves the ocaml#14168 / ocaml#14434 behaviour shipped in 3.23.x. - < 3.23: skip entirely (the original guard added by this PR). Tests: - Cases 7-8 reverted to [(lang dune 3.22)] — they exercise the < 3.23 skip tier. - New Cases 23-24 at [(lang dune 3.23)] — they exercise the simple tier (bare-fill yes, user-constraint preserved verbatim). - Existing Cases 0-22 stay at [(lang dune 3.24)] for the enhanced tier. - [dune-dep.t]'s "lower bound below lang" warning reverts to the pre-ocaml#14453 wording, since lang 3.23 now uses the simple function again. Signed-off-by: Robin Bate Boerop <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10707.
When a project uses
(using menhir ...), dune assumes menhir supports--infer-write-queryand--infer-read-reply(available since menhir 20180523), but the generated opam file includes no version constraint on menhir. This causes packages in opam-repository to frequently need manual lower-bound fixes.This PR auto-injects
"menhir" {>= "20180523"}into generated opam files when the menhir extension is active, following the same pattern as the existing dune and odoc auto-injected dependencies. If the user already declares a menhir dependency with a version constraint, it is preserved.