Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,15 @@ ocaml/Makefile.config: $(TOOLCHAIN) | ocaml
--with-additional-stublibsdir \
--with-relative-libdir \
--enable-runtime-search \
--enable-runtime-search-target
--enable-runtime-search-target \
$(OCAMLCONFIGUREEXTRA)

$(OCAMLBUILT): ocaml/Makefile.config | _build
PATH="$$PWD/$(BLDBIN):$$PATH" \
$(MAKE) -C ocaml crossopt \
prefix=$(call SHQUOTE,$(prefix)/lib/$(OCAMLPKG)) \
OLDS="-o yacc/ocamlyacc -o lex/ocamllex" \
$$(case "$$(ocamlc -vnum)" in \
5.5.*) echo LIBDIR=../lib/ocaml ;; \
esac)
$$(ocamlc -vnum | grep -qE '^5[.]5[.]' && echo LIBDIR=../lib/ocaml)
touch $@

OCAMLFIND_CONF := _build/unikraft_$(OCUKARCH).conf
Expand Down
7 changes: 4 additions & 3 deletions gen_opams.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ tags: "org:mirage"|};
src checksum);
if !repository_layout then
Printf.fprintf out
{|available: os = "linux"
{|available: os = "linux" | os = "macos"
x-maintenance-intent: ["(latest)"]
|})

Expand Down Expand Up @@ -162,7 +162,7 @@ url {
"sha256=f1e97df806acbd1a0a31ce4ca385e44ab65a1732c92199bd9ef50de4ceca7c76"
}
available:
os = "linux" &
(os = "linux" | os = "macos") &
(arch = "arm64" | arch = "x86_64" | arch = "s390x" | arch = "riscv64" |
arch = "ppc64")
x-maintenance-intent: ["(latest)"]
Expand Down Expand Up @@ -317,11 +317,12 @@ build: [
"OCUKCUSTOMCFGDIR=%%{ocaml-unikraft-custom-configs:share}%%"
{ocaml-unikraft-custom-configs:installed}
"UK_CFLAGS=-std=gnu11"
"CROSS_COMPILE=%s-linux-gnu-" {os = "macos"}
"%%{name}%%.install"
]
]
|}
short_name arch;
short_name arch (prefix_arch arch);
if !repository_layout then
Printf.fprintf out
{|x-ci-accept-failures: [
Expand Down
1 change: 1 addition & 0 deletions ocaml-unikraft-backend-firecracker-arm64.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build: [
"OCUKCUSTOMCFGDIR=%{ocaml-unikraft-custom-configs:share}%"
{ocaml-unikraft-custom-configs:installed}
"UK_CFLAGS=-std=gnu11"
"CROSS_COMPILE=aarch64-linux-gnu-" {os = "macos"}
"%{name}%.install"
]
]
1 change: 1 addition & 0 deletions ocaml-unikraft-backend-firecracker-x86_64.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build: [
"OCUKCUSTOMCFGDIR=%{ocaml-unikraft-custom-configs:share}%"
{ocaml-unikraft-custom-configs:installed}
"UK_CFLAGS=-std=gnu11"
"CROSS_COMPILE=x86_64-linux-gnu-" {os = "macos"}
"%{name}%.install"
]
]
1 change: 1 addition & 0 deletions ocaml-unikraft-backend-qemu-arm64.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build: [
"OCUKCUSTOMCFGDIR=%{ocaml-unikraft-custom-configs:share}%"
{ocaml-unikraft-custom-configs:installed}
"UK_CFLAGS=-std=gnu11"
"CROSS_COMPILE=aarch64-linux-gnu-" {os = "macos"}
"%{name}%.install"
]
]
1 change: 1 addition & 0 deletions ocaml-unikraft-backend-qemu-x86_64.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build: [
"OCUKCUSTOMCFGDIR=%{ocaml-unikraft-custom-configs:share}%"
{ocaml-unikraft-custom-configs:installed}
"UK_CFLAGS=-std=gnu11"
"CROSS_COMPILE=x86_64-linux-gnu-" {os = "macos"}
"%{name}%.install"
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ index 0000000000..c30d2e2b4f
+ $(MAKE) -C otherlibs all $(CROSS_OVERRIDES)
+ $(MAKE) runtimeopt
+ $(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \
+ $(CROSS_COMPILER_OVERRIDES) "$(HOST_ZSTD_LIBS)"
+ $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS= "$(HOST_ZSTD_LIBS)"
+ $(MAKE) libraryopt $(CROSS_OVERRIDES)
+ $(MAKE) otherlibrariesopt ocamltoolsopt $(CROSS_OVERRIDES)
+ $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES)
+ $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS=
+ # We now build the compiler libs again, but for target this time
+ rm -f $(ocamlcommon_NCOBJS) $(ocamlmiddleend_NCOBJS) \
+ $(ocamlbytecomp_NCOBJS) $(ocamloptcomp_NCOBJS) \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 3bf151678f524f65a96d0e2173735e37243b5082 Mon Sep 17 00:00:00 2001
From: Thomas Gazagnaire <thomas@gazagnaire.org>
Date: Wed, 8 Jul 2026 23:43:23 -0700
Subject: [PATCH 3/3] Makefile.cross: keep -function-sections off the host .opt
tools

crossopt builds ocamlc.opt/ocamlopt.opt and the *.opt tools with the host
ocamlopt, but injects the target's OC_NATIVE_COMPFLAGS (which includes
-function-sections when the target supports it) into every native compile.
When the target enables function sections but the host does not -- an ELF
cross target built on a macOS host, whose ocamlopt is Mach-O and rejects
-function-sections -- crossopt fails building the host tools.

Neutralise OC_NATIVE_COMPFLAGS for those host-only .opt builds; the target
library/otherlibs phases keep it, so target code is still emitted with
function sections (and can be garbage-collected by the linker).
---
Makefile.cross | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Makefile.cross b/Makefile.cross
index b0a21c3d7c..af7e0d5b21 100644
--- a/Makefile.cross
+++ b/Makefile.cross
@@ -76,11 +76,15 @@ endif
$(MAKE) dynlink-all $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) -C otherlibs all $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) runtimeopt $(OLDS)
+# Host binaries: drop OC_NATIVE_COMPFLAGS (e.g. -function-sections, which a
+# Mach-O host ocamlopt rejects); the target phases below keep it.
$(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \
- $(CROSS_COMPILER_OVERRIDES) "$(HOST_ZSTD_LIBS)" $(OLDS)
+ $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS= \
+ "$(HOST_ZSTD_LIBS)" $(OLDS)
$(MAKE) libraryopt $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) otherlibrariesopt ocamltoolsopt $(CROSS_OVERRIDES) $(OLDS)
- $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) $(OLDS)
+ $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS= \
+ $(OLDS)
# We now build the compiler libs again, but for target this time
rm -f $(ocamlcommon_NCOBJS) $(ocamlmiddleend_NCOBJS) \
$(ocamlbytecomp_NCOBJS) $(ocamloptcomp_NCOBJS) \
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From e4dbf608b08d03e7af71e123ddddf9ad576e4092 Mon Sep 17 00:00:00 2001
From: Thomas Gazagnaire <thomas@gazagnaire.org>
Date: Wed, 8 Jul 2026 23:51:53 -0700
Subject: [PATCH 1/1] Makefile.cross: keep -function-sections off the host .opt
tools

crossopt builds ocamlc.opt/ocamlopt.opt and the *.opt tools with the host
ocamlopt, but injects the target's OC_NATIVE_COMPFLAGS (which includes
-function-sections when the target supports it) into every native compile.
When the target enables function sections but the host does not -- an ELF
cross target built on a macOS host, whose ocamlopt is Mach-O and rejects
-function-sections -- crossopt fails building the host tools.

Neutralise OC_NATIVE_COMPFLAGS for those host-only .opt builds; the target
library/otherlibs phases keep it, so target code is still emitted with
function sections (and can be garbage-collected by the linker).
---
Makefile.cross | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Makefile.cross b/Makefile.cross
index cf069212ea..a33ad8f28d 100644
--- a/Makefile.cross
+++ b/Makefile.cross
@@ -89,11 +89,15 @@ endif
$(MAKE) dynlink-all $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) -C otherlibs all $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) runtimeopt $(OLDS)
+# Host binaries: drop OC_NATIVE_COMPFLAGS (e.g. -function-sections, which a
+# Mach-O host ocamlopt rejects); the target phases below keep it.
$(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \
- $(CROSS_COMPILER_OVERRIDES) "$(HOST_ZSTD_LIBS)" $(OLDS)
+ $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS= \
+ "$(HOST_ZSTD_LIBS)" $(OLDS)
$(MAKE) libraryopt $(CROSS_OVERRIDES) $(OLDS)
$(MAKE) otherlibrariesopt ocamltoolsopt $(CROSS_OVERRIDES) $(OLDS)
- $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) $(OLDS)
+ $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) OC_NATIVE_COMPFLAGS= \
+ $(OLDS)
# We now build the compiler libs again, but for target this time
rm -f $(ocamlcommon_NCOBJS) $(ocamlmiddleend_NCOBJS) \
$(ocamlbytecomp_NCOBJS) $(ocamloptcomp_NCOBJS) \