diff --git a/Makefile b/Makefile index cb6dfd44..ea4d4cd8 100644 --- a/Makefile +++ b/Makefile @@ -91,17 +91,13 @@ $(TOOLDIR_FINAL)/$(MAKECONF_TARGET_ARCH)-solo5-ocaml-%: \ toolchains: $(TOOLCHAIN_FOR_BUILD) $(TOOLCHAIN_FINAL) # OCAML -# Extract sources from the ocaml-src package and apply patches if there any in -# `patches//` +# Extract sources from the ocaml-src package and apply our patches ocaml: # First make sure the ocaml directory doesn't exist, otherwise the cp would # create an ocaml-src subdirectory test ! -d $@ cp -r "$$(ocamlfind query ocaml-src)" $@ - VERSION="$$(head -n1 ocaml/VERSION | cut -d '.' -f 1-2)" ; \ - if test -d "patches/$$VERSION" ; then \ - opatch -v -C $@ "patches/$$VERSION"/*; \ - fi + ./patch_ocaml.sh ocaml/Makefile.config: $(LIBS) $(TOOLCHAIN_FOR_BUILD) | ocaml PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" ; \ diff --git a/example/startup.c b/example/startup.c index 263eddb3..7dc4c22c 100644 --- a/example/startup.c +++ b/example/startup.c @@ -1,14 +1,36 @@ #include -#define CAML_NAME_SPACE -#include - static char *unused_argv[] = { "mirage", NULL }; void _nolibc_init(uintptr_t heap_start, size_t heap_size); // defined in nolibc/sysdeps_solo5.c +/* Please note that this makes some additional checks whether the modifications + to the OCaml runtime (see patch_ocaml.sh) were successful + (Max_domains_{def,max} and caml_params->max_domains are 1). This is not + needed for a minimal hello world. */ +#define CAML_NAME_SPACE +#define CAML_INTERNALS //not needed for a minimal hello +#include +#include //not needed for a minimal hello +#include //not needed for a minimal hello + int solo5_app_main(const struct solo5_start_info *si) { + //additional check for ocaml-solo5 sanity, not needed for a minimal hello + if (Max_domains_def != 1) { + fprintf(stderr, "expected Max_domains_def to be 1, found %d\n", Max_domains_def); + return 1; + }; + //additional check for ocaml-solo5 sanity, not needed for a minimal hello + if (Max_domains_max != 1) { + fprintf(stderr, "expected Max_domains_max to be 1, found %d\n", Max_domains_max); + return 1; + }; _nolibc_init(si->heap_start, si->heap_size); caml_startup(unused_argv); + //additional check for ocaml-solo5 sanity, not needed for a minimal hello + if (caml_params->max_domains != 1) { + fprintf(stderr, "expected max_domains to be 1, found %d\n", caml_params->max_domains); + return 1; + }; return 0; } diff --git a/ocaml-solo5-cross-aarch64.opam b/ocaml-solo5-cross-aarch64.opam index 55ad18ee..65a928f4 100644 --- a/ocaml-solo5-cross-aarch64.opam +++ b/ocaml-solo5-cross-aarch64.opam @@ -28,10 +28,9 @@ run-test: [ [make "test"] ] depends: [ - "opatch" {build} # to patch the compiler sources "ocamlfind" {build} "ocaml-src" {build} - "ocaml" {>= "5.5.2" & < "5.6"} + "ocaml" {>= "5.5" & < "5.6"} "solo5" {>= "0.9.1"} "solo5-cross-aarch64" {>= "0.9.1" } ] diff --git a/ocaml-solo5.opam b/ocaml-solo5.opam index df69991f..08b34479 100644 --- a/ocaml-solo5.opam +++ b/ocaml-solo5.opam @@ -28,10 +28,9 @@ run-test: [ [make "test"] ] depends: [ - "opatch" {build} # to patch the compiler sources "ocamlfind" {build} "ocaml-src" {build} - "ocaml" {>= "5.5.2" & < "5.6"} + "ocaml" {>= "5.5" & < "5.6"} "solo5" {>= "0.9.1"} ] conflicts: [ diff --git a/patch_ocaml.sh b/patch_ocaml.sh new file mode 100755 index 00000000..ced577a7 --- /dev/null +++ b/patch_ocaml.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -eu + +# Are we using GNU sed or BSD sed? +# (`sed --version` is defined only by GNU sed, btw) +# The intent is to set `sep` so that we can call `sed -i$sep''` to make it +# portable +case "$(sed --version 2>&1)" in + *GNU*) sep='' ;; + *) sep=' ' ;; +esac + +# PATCH 1: Set `Max_domains_{def,max}` to 1 +# +# Solo5 is single-core with no scheduler, so avoid the useless memory +# waste +# +# We have in examples/startup.c a test whether this was successful: +# - we check Max_domains_{def,max} as well as caml_params->max_domains to be 1 + +sed -i$sep'' \ + -e 's/#define Max_domains_def 128/#define Max_domains_def 1/' \ + -e 's/#define Max_domains_max 4096/#define Max_domains_max 1/' \ + ocaml/runtime/caml/domain.h + +# PATCH 2: Use the same os_type as the host +# +# The examples/hello.exe tests this behaviour, since OCaml will complain if +# the host-provided "fmt" package is compiled with a differently checksummed +# Stdlib. + +sed -i$sep'' \ + -e 's/ostype="None"/ostype="$(ocamlc -config-var os_type)"/' \ + ocaml/configure diff --git a/patches/5.5/0001-Use-the-same-os_type-as-the-host.patch b/patches/5.5/0001-Use-the-same-os_type-as-the-host.patch deleted file mode 100644 index d7ec28cd..00000000 --- a/patches/5.5/0001-Use-the-same-os_type-as-the-host.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 1271f2a6a55483e9a0825a6f79f384b710444510 Mon Sep 17 00:00:00 2001 -From: Calascibetta Romain -Date: Sat, 20 Jun 2026 13:04:38 +0200 -Subject: [PATCH] Use the same os_type as the host - ---- - configure | Bin 764478 -> 764503 bytes - configure.ac | 2 +- - 2 files changed, 1 insertion(+), 1 deletion(-) - -diff --git a/configure b/configure -index b159afee80..0ce6c1a1c2 100755 ---- a/configure -+++ b/configure -@@ -16507,7 +16507,7 @@ esac - gcc-*,powerpc-*-linux*) : - oc_ldflags="-mbss-plt" ;; #( - *,*-*-none|*,*-*-elf*) : -- ostype="None" ;; #( -+ ostype="$(ocamlc -config-var os_type)" ;; #( - *) : - ;; - esac -diff --git a/configure.ac b/configure.ac -index 167629fbbf..a92274bf43 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1354,7 +1354,7 @@ AS_CASE([$ocaml_cc_vendor,$target], - [gcc-*,powerpc-*-linux*], - [oc_ldflags="-mbss-plt"], - [*,*-*-none|*,*-*-elf*], -- [ostype="None"]) -+ [ostype="$(ocamlc -config-var os_type)"]) - - # How to build sak - --- -2.54.0 - diff --git a/patches/5.5/0003-Set-Max_domains_-def-max-to-1.patch b/patches/5.5/0003-Set-Max_domains_-def-max-to-1.patch deleted file mode 100644 index 0411d5e8..00000000 --- a/patches/5.5/0003-Set-Max_domains_-def-max-to-1.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 038db6e2efd54d13a6841b250f9efe338eea72e2 Mon Sep 17 00:00:00 2001 -From: Samuel Hym -Date: Fri, 12 Apr 2024 19:21:52 +0200 -Subject: [PATCH 3/3] Set `Max_domains_{def,max}` to 1 - -Solo5 is single-core with no scheduler, so avoid the useless memory -waste - -Note that since PR#13272 the maximum number of domains can set using a -parameter in `OCAMLRUNPARAM` so a patchless implementation could be to -add to `nolibc`: -- a `secure_getenv` returning `"d=1"` for the `OCAMLRUNPARAM` value, -- a `sscanf`; it could be hard-coded version just for that use case - (namely recover the `1`) -but this would still be rather brittle ---- - runtime/caml/domain.h | 8 ++------ - 1 file changed, 2 insertions(+), 6 deletions(-) - -diff --git a/runtime/caml/domain.h b/runtime/caml/domain.h -index c7d6c1136f..ef3ff52ede 100644 ---- a/runtime/caml/domain.h -+++ b/runtime/caml/domain.h -@@ -30,15 +30,11 @@ - CAMLextern bool caml_thread_running_on_expected_domain(uintnat); - CAMLextern void caml_thread_record_domain_id(uintnat); - --#ifdef ARCH_SIXTYFOUR --#define Max_domains_def 128 --#else --#define Max_domains_def 16 --#endif -+#define Max_domains_def 1 - - /* Upper limit for the number of domains. Chosen to be arbitrarily large. Used - * for sanity checking [max_domains] value in OCAMLRUNPARAM. */ --#define Max_domains_max 4096 -+#define Max_domains_max 1 - - /* is the minor heap full or an external interrupt has been triggered */ - Caml_inline int caml_check_gc_interrupt(caml_domain_state * dom_st) --- -2.51.0 -