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

Some tweaks to be able to use ocaml-solo5 with miou #144

Merged
merged 2 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $(DOT_INSTALL_CHUNKS_FOR_OCAML): | ocaml/Makefile.config

# CONFIGURATION FILES
_build/solo5.conf: gen_solo5_conf.sh $(OCAML_IS_BUILT)
SYSROOT="$(MAKECONF_SYSROOT)" ./gen_solo5_conf.sh > $@
PREFIX="$(MAKECONF_PREFIX)" SYSROOT="$(MAKECONF_SYSROOT)" ./gen_solo5_conf.sh > $@

_build/empty-META: | _build
touch $@
Expand Down
38 changes: 36 additions & 2 deletions gen_solo5_conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,43 @@ checkopt() {
fi
}

# [path(solo5)] is important because it explains, from the user's point of
# view, where we could find the OCaml compiler to generate a Solo5 unikernel,
# but also where we could find the OCaml libraries (which is what findlib is
# all about).
#
# The current choice is to consider the artefacts available in an OPAM switch
# as possible solutions to the dependencies of a unikernel. For example, if a
# unikernel depends on the [fmt] library, we give the option of using
# [fmt.cmx{,a}] from [opam install fmt]. Reusing what may have been compiled by
# the host OCaml compiler and installed via OPAM poses no problem in principle,
# since we are not changing the way an OCaml file is compiled between the host
# OCaml compiler and our cross-compiler, which uses Solo5. In fact, the
# [*.cmx{,a}] files generated by the two compilers are strictly the same.
#
# However, the difference will be in the generation of the object files and the
# link, but the build-system can ensure that our compiler is used at these
# times.
#
# The only problem concerns the [*.a] archives installed via OPAM. These are
# not compiled with our C compiler for Solo5. The mirage tool takes care of
# downloading the sources of the unikernel dependencies so that if they contain
# C files, they can be compiled with our cross-compiler. However, this is a
# choice relating to the mirage tool that we should not impose at this level
# (that of simply offering a cross-compiler). We also know that with dune,
# primacy is given to the sources available in the dune environment rather than
# to the artefacts available via OPAM/findlib.
#
# So, compiling a project with our Solo5 toolchain gives the user the
# possibility of reusing what is available in OPAM and already installed. On
# the very specific question of [*.a] archives, it is up to the user to take
# care not to reuse the [*.a] files offered by OPAM/findlib but to recompile
# them themselves with our cross-compiler from the sources. In this case, the
# mirage tool takes care of this detail, using opam monorepo.

cat << EOF
path(solo5) = "$SYSROOT/lib"
destdir(solo5) = "$SYSROOT/lib"
path(solo5) = "$SYSROOT/lib/:$PREFIX/lib"
destdir(solo5) = "$PREFIX/lib"
stdlib(solo5) = "$SYSROOT/lib/ocaml"
ocamlopt(solo5) = "$SYSROOT/bin/ocamlopt$(checkopt ocamlopt)"
ocamlc(solo5) = "$SYSROOT/bin/ocamlc$(checkopt ocamlc)"
Expand Down
8 changes: 7 additions & 1 deletion nolibc/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ STUB_IGNORE(int, pthread_condattr_init, 0);
*/

STUB_IGNORE(int, pthread_cond_init, 0);
STUB_ABORT(pthread_cond_destroy);
STUB_IGNORE(int, pthread_cond_destroy, 0);
/* it's possible to create a [Stdlib.Condition.t] but an execution path exists
* where we don't really use it. However, OCaml will try to destroy this
* [Stdlib.Condition.t] and we must ignore such execution path which is still
* safe for unikernels (with one core). The real issue with [pthread_cond_*] is
* when we would like to suspend the execution with [pthread_cond_wait] but
* [pthread_cond_init] and [pthread_cond_destroy] are safe to just ignore. */
STUB_ABORT(pthread_cond_wait);
STUB_ABORT(pthread_cond_signal);
STUB_IGNORE(int, pthread_cond_broadcast, 0);
Expand Down
Loading