Skip to content

Honor OCAML* environment variables in configure#173

Open
samoht wants to merge 2 commits into
ocaml:masterfrom
samoht:honor-ocaml-env
Open

Honor OCAML* environment variables in configure#173
samoht wants to merge 2 commits into
ocaml:masterfrom
samoht:honor-ocaml-env

Conversation

@samoht

@samoht samoht commented Jun 18, 2026

Copy link
Copy Markdown
Member

configure hardcodes the OCaml tools to bare names (ocamlc, ocamlopt, ...), so it can't be pointed at a cross toolchain: cross-compiling builds caml_z.c against the host compiler and headers, not the target's.

This PR makes each tool honor an environment variable (OCAML, OCAMLC, OCAMLOPT, OCAMLMKLIB, OCAMLDEP, OCAMLDOC), falling back to the bare name when unset so native builds are unchanged. Setting OCAMLC="ocamlfind -toolchain <target> ocamlc" (etc.) then builds for that target.

Came up cross-building MirageOS unikernels on macOS:

Default ocaml, ocamlc, ocamlopt, ocamlmklib, ocamldep and ocamldoc to their
environment variables when set, and use $ocamlc (not a bare ocamlc) to query
-where and -version, so a cross build is configured entirely against the
toolchain it was given: the C stub compiles against the target's caml headers
and the target's compiler, not the build machine's. Native builds are
unchanged, each variable defaulting to the bare tool name.
Building the native plugin needs shared libraries; a cross target without them
(a freestanding or static backend) still ships dynlink.cmxa, so the old
`checkcmxalib dynlink.cmxa` test wrongly enabled it and the link failed against
an empty shared GMP. Gate on `ocamlopt -config`'s supports_shared_libraries.
@samoht samoht force-pushed the honor-ocaml-env branch from 89d5ac9 to 416b78d Compare June 21, 2026 04:15
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 21, 2026
End-to-end macOS check: build the aarch64 cross-compiler and cross-build zarith
(C stubs + GMP) with it. Pins the not-yet-released forks (Solo5/solo5#641,
mirage/ocaml-gmp#29, ocaml/Zarith#173); drop this commit, or at least the pins
and fork clones, once they are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 21, 2026
Pin the not-yet-released forks (Solo5/solo5#641, mirage/ocaml-gmp#29,
ocaml/Zarith#173) and build the cross-compiler plus zarith through opam. Drop
this commit (or at least the pins) once they are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 21, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` so
zarith's configure (ocaml/Zarith#173) compiles caml_z.c with the cross cc.
Pins the not-yet-released forks (also mirage/ocaml-gmp#29); drop this commit,
or at least the pins, once they are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 21, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: install ocaml-gmp (mirage/ocaml-gmp#29) for its relocatable
gmp.pc, then point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` and
PKG_CONFIG_PATH at that gmp.pc so zarith's configure (ocaml/Zarith#173) compiles
caml_z.c with the cross cc against ocaml-gmp. Drop this commit, or the pins,
once the forks are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 21, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: install ocaml-gmp (mirage/ocaml-gmp#29) for its relocatable
gmp.pc, then point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` and
PKG_CONFIG_PATH at that gmp.pc so zarith's configure (ocaml/Zarith#173) compiles
caml_z.c with the cross cc against ocaml-gmp. Drop this commit, or the pins,
once the forks are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 22, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: install ocaml-gmp (mirage/ocaml-gmp#29) for its relocatable
gmp.pc, then point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` and
PKG_CONFIG_PATH at that gmp.pc so zarith's configure (ocaml/Zarith#173) compiles
caml_z.c with the cross cc against ocaml-gmp. Drop this commit, or the pins,
once the forks are in opam.
@samoht samoht marked this pull request as ready for review June 22, 2026 16:41
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 23, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: install ocaml-gmp (mirage/ocaml-gmp#29) for its relocatable
gmp.pc, then point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` and
PKG_CONFIG_PATH at that gmp.pc so zarith's configure (ocaml/Zarith#173) compiles
caml_z.c with the cross cc against ocaml-gmp. Drop this commit, or the pins,
once the forks are in opam.
samoht added a commit to samoht/ocaml-solo5 that referenced this pull request Jun 23, 2026
Build the aarch64 cross-compiler (pinning Solo5/solo5#641) and cross-build
zarith with it: install ocaml-gmp (mirage/ocaml-gmp#29) for its relocatable
gmp.pc, then point OCAMLC/OCAMLOPT/... at `ocamlfind -toolchain solo5` and
PKG_CONFIG_PATH at that gmp.pc so zarith's configure (ocaml/Zarith#173) compiles
caml_z.c with the cross cc against ocaml-gmp. Drop this commit, or the pins,
once the forks are in opam.
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