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
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/<OCaml version>/`
# 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" ; \
Expand Down
28 changes: 25 additions & 3 deletions example/startup.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
#include <solo5.h>

#define CAML_NAME_SPACE
#include <caml/callback.h>

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 <caml/callback.h>
#include <caml/startup_aux.h> //not needed for a minimal hello
#include <caml/domain.h> //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;
}
3 changes: 1 addition & 2 deletions ocaml-solo5-cross-aarch64.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
Expand Down
3 changes: 1 addition & 2 deletions ocaml-solo5.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
35 changes: 35 additions & 0 deletions patch_ocaml.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 0 additions & 39 deletions patches/5.5/0001-Use-the-same-os_type-as-the-host.patch

This file was deleted.

44 changes: 0 additions & 44 deletions patches/5.5/0003-Set-Max_domains_-def-max-to-1.patch

This file was deleted.

Loading