Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OCaml 5.3.0 #148

Merged
merged 15 commits into from
Mar 7, 2025
Merged
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
11 changes: 2 additions & 9 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ freebsd_task:
OPAMYES: 1
env:
matrix:
- OCAML_VERSION: 5.2.1
- OCAML_VERSION: 5.3.0
pkg_install_script: pkg install -y ocaml-opam gmp gmake pkgconf bash
opam_ocaml_cache:
folder: $HOME/.opam
reupload_on_changes: false # since there is a fingerprint script
fingerprint_script:
- echo $CIRRUS_OS
- echo $OCAML_VERSION
populate_script:
- opam init -a --comp=$OCAML_VERSION
setup_script:
- opam init -a --comp=$OCAML_VERSION
- opam update
- opam install dune
- opam pin add -n -t .
Expand Down
27 changes: 14 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
ocaml-compiler: [5.2.1]
ocaml-compiler: [5.3.0]
name: OCaml ${{ matrix.ocaml-compiler }}
runs-on: ubuntu-latest
steps:
Expand All @@ -17,20 +17,21 @@ jobs:
!ocaml-solo5-cross-aarch64.opam
- name: Install ocaml-solo5 and dune
run: opam install ocaml-solo5 conf-libseccomp dune
- name: Compile example with hvt
- name: Show the toolchain configuration
run: |
set -x
opam exec -- ocamlfind -toolchain solo5 opt -config
opam exec -- ocamlfind -toolchain solo5 printconf
opam exec -- ocamlfind -toolchain solo5 list
- name: Compile examples with hvt
run: MODE=hvt opam exec -- dune build --root example
- name: Compile example with spt
- name: Compile examples with spt
run: MODE=spt opam exec -- dune build --root example
- name: Run example with spt
run: opam exec -- solo5-spt example/_build/solo5/main.exe
- name: Compile a failing example with spt
run: MODE=spt SOLO5TEST=sysfail opam exec -- dune build --root example
- name: Run a failing example with spt
run: |
! opam exec -- solo5-spt example/_build/solo5/main.exe
- name: Compile example with virtio
- name: Run examples with spt
run: MODE=spt opam exec -- dune runtest --root example
- name: Compile examples with virtio
run: MODE=virtio opam exec -- dune build --root example
- name: Compile example with muen
- name: Compile examples with muen
run: MODE=muen opam exec -- dune build --root example
- name: Compile example with xen
- name: Compile examples with xen
run: MODE=xen opam exec -- dune build --root example
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## XXX

* Support for Ocaml 5.3.0 (@shym #148)
* Update the FreeBSD version for CI (@shym #149)

## v1.0.1 (2024-12-17)

* allow findlib/dune use libraries available from OPAM (@dinosaure #144)
Expand Down
25 changes: 11 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,10 @@ ocaml/Makefile.config: $(LIBS) $(TOOLCHAIN_FOR_BUILD) | ocaml

OCAML_IS_BUILT := _build/ocaml_is_built
$(OCAML_IS_BUILT): ocaml/Makefile.config | _build
PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" $(MAKE) -C ocaml cross.opt
cd ocaml && ocamlrun tools/stripdebug ocamlc ocamlc.tmp
cd ocaml && ocamlrun tools/stripdebug ocamlopt ocamlopt.tmp
PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" \
$(MAKE) -C ocaml crossopt OLDS="-o yacc/ocamlyacc -o lex/ocamllex"
touch $@

DOT_INSTALL_PREFIX_FOR_OCAML := _build/ocaml.install
DOT_INSTALL_CHUNKS_FOR_OCAML := $(addprefix $(DOT_INSTALL_PREFIX_FOR_OCAML),\
.lib .libexec)
$(DOT_INSTALL_CHUNKS_FOR_OCAML): | ocaml/Makefile.config
MAKE="$(MAKE)" ./gen_ocaml_install.sh \
$(DOT_INSTALL_PREFIX_FOR_OCAML) ocaml $(MAKECONF_SYSROOT)

# CONFIGURATION FILES
_build/solo5.conf: gen_solo5_conf.sh $(OCAML_IS_BUILT)
PREFIX="$(MAKECONF_PREFIX)" SYSROOT="$(MAKECONF_SYSROOT)" ./gen_solo5_conf.sh > $@
Expand All @@ -144,14 +136,19 @@ _build/empty-META: | _build
PACKAGES := $(basename $(wildcard *.opam))
INSTALL_FILES := $(foreach pkg,$(PACKAGES),$(pkg).install)

$(INSTALL_FILES): $(TOOLCHAIN_FINAL) $(DOT_INSTALL_CHUNKS_FOR_OCAML)
./gen_dot_install.sh $(DOT_INSTALL_PREFIX_FOR_OCAML) $(TOOLCHAIN_FINAL)\
> $@
$(INSTALL_FILES): $(TOOLCHAIN_FINAL)
./gen_dot_install.sh $(TOOLCHAIN_FINAL) > $@

# COMMANDS
.PHONY: install-ocaml
install-ocaml:
ln -sf "$$(command -v ocamllex)" ocaml/lex/ocamllex
ln -sf "$$(command -v ocamlyacc)" ocaml/yacc/ocamlyacc
$(MAKE) -C ocaml installcross

PACKAGE := ocaml-solo5
.PHONY: install
install: $(PACKAGE).install
install: $(PACKAGE).install install-ocaml
opam-installer --prefix=$(MAKECONF_PREFIX) $<

.PHONY: clean
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ application manifest and a startup file to initialize the libc.

## Supported compiler versions

Tested against OCaml 5.2.1. Other versions would require specific patches (see
Tested against OCaml 5.3.0. Other versions would require specific patches (see
the `patches` directory).

## Porting to a different (uni)kernel base layer
Expand Down
6 changes: 6 additions & 0 deletions example/compilerlibsx86.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(* Access fields provided by the (x86_64) compiler libs *)
(* Requires patches in 5.3+ *)

let _ =
Printf.printf "allow_unaligned_access = %b\n" Arch.allow_unaligned_access;
Printf.printf "win64 = %b\n" Arch.win64
3 changes: 3 additions & 0 deletions example/config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let _ =
Printf.printf "Version: %s\nOS: %s\nUnix: %b\nWin: %b\nCygwin: %b\n"
Sys.ocaml_version Sys.os_type Sys.unix Sys.win32 Sys.cygwin
32 changes: 20 additions & 12 deletions example/dune
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
(executable
(name main)
(link_flags :standard -cclib "-z solo5-abi=%{env:MODE=hvt}")
(name dune_gen)
(modules dune_gen))

(rule
(alias runtest)
(mode promote)
(action
(with-stdout-to
dune.inc
(run ./dune_gen.exe))))

(include dune.inc)

; As we add the manifest to a library, we'll need to explicitly ask for it to be
; linked in (for instance by telling the compiler / linker that the
; `__solo5_mft1_note` symbol is undefined) otherwise we'll end up with errors such
; as: `solo5-hvt: ...: Invalid or unsupported executable`
(library
(name solo5os)
(modules)
(foreign_stubs
(language c)
(names startup manifest)))

(rule
(copy main.%{env:SOLO5TEST=hello}.ml main.ml))

(rule
(targets manifest.c)
(deps manifest.json)
(action
(run solo5-elftool gen-manifest manifest.json manifest.c)))

(rule
(alias runtest)
(enabled_if
(= %{context_name} solo5))
(action
(run "solo5-%{env:MODE=hvt}" "%{dep:main.exe}")))

(alias
(name default)
(enabled_if
Expand Down
96 changes: 96 additions & 0 deletions example/dune.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
(executable
(name hello)
(enabled_if
(= %{context_name} solo5))
(modules hello)
(link_flags
:standard
-cclib
"-z solo5-abi=%{env:MODE=hvt}"
; Force linking the manifest in
-cclib
"-u __solo5_mft1_note")
(libraries solo5os)
(modes native))

(rule
(alias runtest)
(enabled_if
(= %{context_name} solo5))
(action
(run "solo5-%{env:MODE=hvt}" "%{dep:hello.exe}")))

(executable
(name sysfail)
(enabled_if
(= %{context_name} solo5))
(modules sysfail)
(link_flags
:standard
-cclib
"-z solo5-abi=%{env:MODE=hvt}"
; Force linking the manifest in
-cclib
"-u __solo5_mft1_note")
(libraries solo5os)
(modes native))

(rule
(alias runtest)
(enabled_if
(= %{context_name} solo5))
(action
(with-accepted-exit-codes
2
(run "solo5-%{env:MODE=hvt}" "%{dep:sysfail.exe}"))))

(executable
(name config)
(enabled_if
(= %{context_name} solo5))
(modules config)
(link_flags
:standard
-cclib
"-z solo5-abi=%{env:MODE=hvt}"
; Force linking the manifest in
-cclib
"-u __solo5_mft1_note")
(libraries solo5os)
(modes native))

(rule
(alias runtest)
(enabled_if
(= %{context_name} solo5))
(action
(run "solo5-%{env:MODE=hvt}" "%{dep:config.exe}")))

(executable
(name compilerlibsx86)
(enabled_if
(and
(>= %{ocaml_version} 5.3.0)
(= %{architecture} amd64)
(= %{context_name} solo5)))
(modules compilerlibsx86)
(link_flags
:standard
-cclib
"-z solo5-abi=%{env:MODE=hvt}"
; Force linking the manifest in
-cclib
"-u __solo5_mft1_note")
(libraries solo5os compiler-libs.optcomp)
(modes native))

(rule
(alias runtest)
(enabled_if
(and
(>= %{ocaml_version} 5.3.0)
(= %{architecture} amd64)
(= %{context_name} solo5)))
(action
(run "solo5-%{env:MODE=hvt}" "%{dep:compilerlibsx86.exe}")))

60 changes: 60 additions & 0 deletions example/dune_gen.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
let print_rule test exitcode extraifs extralibs =
let enabled_if out extraifs =
Printf.fprintf out {|(enabled_if
%a(= %%{context_name} solo5)%a)|}
(fun out ifs ->
match ifs with
| [] -> ()
| _ ->
Printf.fprintf out {|(and
|};
List.iter (Printf.fprintf out {|%s
|}) ifs)
extraifs
(fun out ifs -> match ifs with [] -> () | _ -> Printf.fprintf out ")")
extraifs
in
Printf.printf
{|(executable
(name %s)
%a
(modules %s)
(link_flags
:standard
-cclib
"-z solo5-abi=%%{env:MODE=hvt}"
; Force linking the manifest in
-cclib
"-u __solo5_mft1_note")
(libraries solo5os%a)
(modes native))

(rule
(alias runtest)
%a
(action
%a(run "solo5-%%{env:MODE=hvt}" "%%{dep:%s.exe}")%a))

|}
test enabled_if extraifs test
(fun out -> List.iter (Printf.fprintf out " %s"))
extralibs enabled_if extraifs
(fun out exitcode ->
match exitcode with
| None -> ()
| Some code ->
Printf.fprintf out {|(with-accepted-exit-codes
%d
|} code)
exitcode test
(fun out exitcode ->
match exitcode with None -> () | Some _ -> Printf.fprintf out ")")
exitcode

let _ =
print_rule "hello" None [] [];
print_rule "sysfail" (Some 2) [] [];
print_rule "config" None [] [];
print_rule "compilerlibsx86" None
[ "(>= %{ocaml_version} 5.3.0)"; "(= %{architecture} amd64)" ]
[ "compiler-libs.optcomp" ]
File renamed without changes.
File renamed without changes.
16 changes: 1 addition & 15 deletions gen_dot_install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/sh

if [ ! -e "$1.lib" ] || [ ! -e "$1.libexec" ]; then
echo "Usage: $0 <prefix.file.install>"
echo "The *.install.lib and *.install.libexec for OCaml must be available."
exit 1
fi

prefix_for_ocaml_chunks="$1"
shift

install_file() {
# install_file <src> [dest]
if [ -z "$2" ]; then
Expand Down Expand Up @@ -42,12 +33,7 @@ main() {
install_file _build/solo5.conf findlib.conf.d/solo5.conf
printf ']\n'

printf '%s: [\n' libexec
cat "$prefix_for_ocaml_chunks".libexec
printf ']\n'

printf '%s: [\n' lib
cat "$prefix_for_ocaml_chunks".lib
walk_tree nolibc/include include
install_file nolibc/libnolibc.a lib/libnolibc.a
walk_tree openlibm/include include
Expand All @@ -60,5 +46,5 @@ main() {
printf ']\n'
}

# The only arguments left are the toolchain tools
# The only arguments are the toolchain tools
main "$@"
Loading