Skip to content

Support cross-building the OCaml toolchain on macOS - #14

Open
samoht wants to merge 1 commit into
mirage:mainfrom
samoht:macos-cross
Open

Support cross-building the OCaml toolchain on macOS#14
samoht wants to merge 1 commit into
mirage:mainfrom
samoht:macos-cross

Conversation

@samoht

@samoht samoht commented Jul 6, 2026

Copy link
Copy Markdown
Member

I'd like to cross-build Unikraft OCaml unikernels on an Apple Silicon Mac.

On a macOS host, targeting aarch64-linux is a cross build the arch check misses: host and target arch are both aarch64, only the OS differs, so the build falls back to the host compiler unless CROSS_COMPILE is set. This sets it for {os = "macos"} to the same <arch>-linux-gnu- prefix Linux auto-selects. The messense/macos-cross-toolchains Homebrew tap provides that full toolchain (gcc and binutils under aarch64-linux-gnu-*), so the existing conf-<arch>-linux-gnu-gcc dependency resolves on macOS too, with no divergent triple or gating.

It also passes --disable-function-sections to the OCaml configure on macOS, since crossopt's ocamlopt is built without function-sections support, and marks the packages available on macOS.

The same --disable-function-sections finding drives the macOS support in the sibling ocaml-solo5 backend (mirage/ocaml-solo5#171).

@samoht samoht mentioned this pull request Jul 7, 2026
@samoht
samoht marked this pull request as draft July 7, 2026 00:19
@samoht
samoht marked this pull request as ready for review July 7, 2026 01:26
On a macOS host, targeting aarch64-linux is a cross build the arch check misses:
the host and target arch are both aarch64, only the OS differs, so CROSS_COMPILE
must be set explicitly to the <arch>-linux-gnu- prefix that Linux auto-selects.
The messense/macos-cross-toolchains Homebrew tap provides that toolchain, so
conf-<arch>-linux-gnu-gcc resolves on macOS too. Patch Makefile.cross so
crossopt does not pass -function-sections to the host .opt tools (the macOS host
ocamlopt is Mach-O and rejects it), keeping it for the target library; mark the
packages available on macOS.

Rewrite the crossopt version check without `case` inside `$(...)`, which macOS's
bash 3.2 mis-parses (it reads the `)` in `5.5.*)` as closing the substitution).
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