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

Reorganise the examples and add new ones #147

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
19 changes: 7 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ 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: 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
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.
Loading