Skip to content

fix: support building dune with ocamlfind-secondary on older OCaml switches - #14443

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-rwztynqnpuro
May 8, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-rwztynqnpuro

Conversation

@Alizter

@Alizter Alizter commented May 6, 2026 •

Copy link
Copy Markdown
Collaborator

The secondary compiler fallback in bootstrap.ml was broken in two ways:

  1. It invoked ocamlfind -toolchain secondary ocaml, but ocamlfind does not support the ocaml toplevel as a subcommand. Only compiler tools like ocamlc and ocamlopt. We now query ocamlfind -toolchain secondary query ocaml -format "%d" to locate the secondary compiler's bin directory and invoke ocaml and ocamllex from there directly.

  2. The secondary ocaml toplevel would pick up the primary switch's unix.cma and dllunix.so, which are ABI-incompatible. We now pass -I for the secondary compiler's lib directory and set CAML_LD_LIBRARY_PATH to its stublibs directory.

The opam constraint is restored to the historical pattern, allowing dune to be installed on switches with OCaml >= 4.02 via ocamlfind-secondary:

  ("ocaml" {>= "4.14"} | ("ocaml" {>= "4.02" & < "4.14~~"} & "ocamlfind-secondary"))

Tested on OCaml 4.02.3 and 4.13.1 switches with ocaml-secondary-compiler 4.14.2.

@Alizter
Alizter force-pushed the push-rwztynqnpuro branch from 7c5316f to 5e4c112 Compare May 6, 2026 22:56
@Alizter Alizter mentioned this pull request May 6, 2026
20 tasks done
@hhugo hhugo mentioned this pull request May 7, 2026
2 tasks done
@Alizter
Alizter marked this pull request as ready for review May 7, 2026 14:55

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on my machine and it worked! Just one fix I think needed in the constraints.

Comment thread opam/dune.opam Resolved
Comment thread boot/bootstrap.ml Resolved
@Alizter
Alizter force-pushed the push-rwztynqnpuro branch from 5e4c112 to d922723 Compare May 8, 2026 10:48
@Alizter
Alizter requested a review from shonfeder May 8, 2026 10:50
…itches

The secondary compiler fallback in bootstrap.ml was broken in two ways:

1. It invoked [ocamlfind -toolchain secondary ocaml], but ocamlfind does
   not support the [ocaml] toplevel as a subcommand — only compiler tools
   like [ocamlc] and [ocamlopt]. We now query [ocamlfind -toolchain
   secondary query ocaml -format "%d"] to locate the secondary compiler's
   bin directory and invoke [ocaml] and [ocamllex] from there directly.

2. The secondary [ocaml] toplevel would pick up the primary switch's
   [unix.cma] and [dllunix.so], which are ABI-incompatible. We now pass
   [-I] for the secondary compiler's lib directory and set
   [CAML_LD_LIBRARY_PATH] to its stublibs directory.

The opam constraint is restored to the historical pattern, allowing dune
to be installed on switches with OCaml >= 4.02 via ocamlfind-secondary:

  ("ocaml" {>= "4.14"} | ("ocaml" {>= "4.02" & < "4.14~~"} & "ocamlfind-secondary"))

Tested on OCaml 4.02.3 and 4.13.1 switches with ocaml-secondary-compiler
4.14.2.

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the push-rwztynqnpuro branch from d922723 to 50bd33d Compare May 8, 2026 10:53
@Alizter

Alizter commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

@kit-ty-kate Would you mind taking a look?

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

LGTM.

@Alizter
Alizter merged commit 9e65007 into ocaml:main May 8, 2026
30 checks passed
@Alizter
Alizter deleted the push-rwztynqnpuro branch May 8, 2026 23:53
Alizter added a commit that referenced this pull request May 11, 2026
Backport #14443 onto 3.23.1-rc
shonfeder added a commit that referenced this pull request May 14, 2026
Required for the patch release since it announces a user-facing fix.
Since this missed landing in main initially, it's not important to but
it there, because it will just be deleted and moved into the
`CHANGELOG.md` when the release is cut anyhow.

---------

Signed-off-by: Shon Feder <[email protected]>
Co-authored-by: Ali Caglayan <[email protected]>
shonfeder added a commit to ocaml/opam-repository that referenced this pull request May 19, 2026
CHANGES:

### Fixed

- Fix the `menhir` opam dependency injection introduced in 3.23. Dune
  now only fills in the lower bound `{>= "20180523"}` on an existing
  user-declared `menhir` dependency; it no longer adds `menhir` as a
  new dependency to packages that did not declare it themselves.
  (ocaml/dune#14434, fixes ocaml/dune#14428, @robinbb)

- Gate the `dune` version-bound deduplication in generated opam files
  (introduced in 3.23) on `(lang dune 3.23)`. Projects at earlier lang
  versions get the prior `And [...]` shape — e.g.
  `{>= "3.17" & >= "3.20"}` — restoring 3.22 behaviour and avoiding a
  silent change to opam output on dune-binary upgrade. (ocaml/dune#14436,
  @robinbb)

- Preserve library order when building a shared jsoo standalone runtime.
  (ocaml/dune#14438, @vouillon)

- Fix the fallback to the secondary compiler, allowing recovering of support for
  packages with upper bounds on OCaml less than 4.14. Packages depending on dune
  3.23.1 or later and with an upper bound on the OCaml compiler that is less
  than 4.14, will now be able to use the latest dune, but dune will be built
  with the secondary compiler at version 4.14. (ocaml/dune#14443, @Alizter)

- Fix the bootstrap on NetBSD by including `<sys/wait.h>` in `lev_stubs.c`,
  matching the existing FreeBSD/OpenBSD guard.
  (ocaml/dune#14512, fixes ocaml/dune#14484, @0-wiz-0)
pull Bot pushed a commit to metanivek/dune that referenced this pull request May 19, 2026
…itches (ocaml#14443)

The secondary compiler fallback in bootstrap.ml was broken in two ways:

1. It invoked `ocamlfind -toolchain secondary ocaml`, but `ocamlfind`
does not support the `ocaml` toplevel as a subcommand. Only compiler
tools like `ocamlc` and `ocamlopt`. We now query `ocamlfind -toolchain
secondary query ocaml -format "%d"` to locate the secondary compiler's
bin directory and invoke `ocaml` and `ocamllex` from there directly.

2. The secondary `ocaml` toplevel would pick up the primary switch's
`unix.cma` and `dllunix.so`, which are ABI-incompatible. We now pass
`-I` for the secondary compiler's lib directory and set
`CAML_LD_LIBRARY_PATH` to its stublibs directory.

The opam constraint is restored to the historical pattern, allowing dune
to be installed on switches with OCaml >= 4.02 via ocamlfind-secondary:

```
  ("ocaml" {>= "4.14"} | ("ocaml" {>= "4.02" & < "4.14~~"} & "ocamlfind-secondary"))
```

Tested on OCaml 4.02.3 and 4.13.1 switches with ocaml-secondary-compiler
4.14.2.

- Fixes ocaml#13908

(cherry picked from commit 9e65007)
Signed-off-by: Shon Feder <[email protected]>
@Alizter Alizter added this to the 3.23.1 milestone Jun 10, 2026
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.

new release of dune-secondary package

2 participants