From 9fc16d028908032939dd9cccd7721538d09f090c Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 23 Apr 2024 17:59:57 +0100 Subject: [PATCH 1/3] use dune variants --- lib_test/dune | 4 ++-- lib_test/portable.ml | 2 ++ solo5/dune | 5 ++--- solo5/mclock.mli | 22 ---------------------- solo5/pclock.mli | 21 --------------------- src/dune | 3 ++- src/{mirage_clock.ml => mirage_clock.mli} | 4 ++-- unix/dune | 6 +++--- unix/mclock.mli | 21 --------------------- unix/pclock.mli | 20 -------------------- 10 files changed, 13 insertions(+), 95 deletions(-) delete mode 100644 solo5/mclock.mli delete mode 100644 solo5/pclock.mli rename src/{mirage_clock.ml => mirage_clock.mli} (97%) delete mode 100644 unix/mclock.mli delete mode 100644 unix/pclock.mli diff --git a/lib_test/dune b/lib_test/dune index 02f0a22..80c2894 100644 --- a/lib_test/dune +++ b/lib_test/dune @@ -1,4 +1,4 @@ (test (name portable) - (package mirage-clock-unix) - (libraries mirage-clock-unix)) + (package mirage-clock) + (libraries mirage-clock.unix)) diff --git a/lib_test/portable.ml b/lib_test/portable.ml index f1e5944..656106a 100644 --- a/lib_test/portable.ml +++ b/lib_test/portable.ml @@ -1,3 +1,5 @@ +open Mirage_clock + let print_time c = let d, ps = Pclock.now_d_ps c in Printf.printf "The time is %d days and %Ld picoseconds since the epoch.\n" d diff --git a/solo5/dune b/solo5/dune index 9223bf4..6c04097 100644 --- a/solo5/dune +++ b/solo5/dune @@ -1,8 +1,7 @@ (library (name mirage_clock_solo5) - (wrapped false) - (public_name mirage-clock-solo5) - (libraries mirage-clock) + (public_name mirage-clock.solo5) + (implements mirage-clock) (foreign_stubs (language c) (names clock_stubs))) diff --git a/solo5/mclock.mli b/solo5/mclock.mli deleted file mode 100644 index fbbd0c2..0000000 --- a/solo5/mclock.mli +++ /dev/null @@ -1,22 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -(** Monotonic clock for MirageOS using paravirtual interfaces - - Clock returning monotonic time since an arbitrary point. To be used for eg. - profiling. *) - -include Mirage_clock.MCLOCK diff --git a/solo5/pclock.mli b/solo5/pclock.mli deleted file mode 100644 index bdef054..0000000 --- a/solo5/pclock.mli +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -(** POSIX clock for MirageOS using paravirtual interfaces - - Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) - -include Mirage_clock.PCLOCK diff --git a/src/dune b/src/dune index 5133e38..f29a728 100644 --- a/src/dune +++ b/src/dune @@ -1,3 +1,4 @@ (library (name mirage_clock) - (public_name mirage-clock)) + (public_name mirage-clock) + (virtual_modules mirage_clock)) diff --git a/src/mirage_clock.ml b/src/mirage_clock.mli similarity index 97% rename from src/mirage_clock.ml rename to src/mirage_clock.mli index a2cfa25..f87f2b6 100644 --- a/src/mirage_clock.ml +++ b/src/mirage_clock.mli @@ -22,7 +22,7 @@ (** {2 POSIX clock} Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) -module type PCLOCK = sig +module Pclock : sig val now_d_ps : unit -> int * int64 (** [now_d_ps ()] is [(d, ps)] representing the POSIX time occurring at [d] * 86'400e12 + [ps] POSIX picoseconds from the epoch 1970-01-01 00:00:00 UTC. @@ -43,7 +43,7 @@ end Clock returning monotonic time since an arbitrary point. To be used for e.g. profiling. *) -module type MCLOCK = sig +module Mclock : sig val elapsed_ns : unit -> int64 (** [elapsed_ns ()] is a monotonically increasing count of nanoseconds elapsed since some arbitrary point *) diff --git a/unix/dune b/unix/dune index e03be8e..877a2ca 100644 --- a/unix/dune +++ b/unix/dune @@ -1,8 +1,8 @@ (library (name mirage_clock_unix) - (wrapped false) - (public_name mirage-clock-unix) - (libraries mirage-clock unix) + (public_name mirage-clock.unix) + (implements mirage-clock) + (libraries unix) (foreign_stubs (language c) (flags diff --git a/unix/mclock.mli b/unix/mclock.mli deleted file mode 100644 index dab1720..0000000 --- a/unix/mclock.mli +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -include Mirage_clock.MCLOCK -(** Monotonic clock for Unix using MirageOS interfaces - - Clock returning monotonic time since an arbitrary point. To be used for eg. - profiling. *) diff --git a/unix/pclock.mli b/unix/pclock.mli deleted file mode 100644 index f01b8ee..0000000 --- a/unix/pclock.mli +++ /dev/null @@ -1,20 +0,0 @@ -(* - * Copyright (c) 2015 Daniel C. Bünzli - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - *) - -include Mirage_clock.PCLOCK -(** POSIX clock for MirageOS using Unix interfaces - - Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *) From 2fc6f9f6803d63e57deca9c691caf7af2bad5590 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 23 Apr 2024 21:18:31 +0100 Subject: [PATCH 2/3] use conditional compilation via dune --- config/discover.ml | 16 +++++++++---- lib_test/dune | 2 +- mirage-clock-solo5.opam | 29 ---------------------- mirage-clock-unix.opam | 26 -------------------- solo5/clock_stubs.default.c | 0 solo5/clock_stubs.solo5.c | 33 -------------------------- solo5/dune | 25 ------------------- {unix => src}/clock_stubs.c | 24 +++++++++++++++++++ src/dune | 19 ++++++++++++++- solo5/mclock.ml => src/mclock.solo5.ml | 0 unix/mclock.ml => src/mclock.unix.ml | 0 src/mirage_clock.ml | 2 ++ solo5/pclock.ml => src/pclock.solo5.ml | 0 unix/pclock.ml => src/pclock.unix.ml | 0 unix/dune | 13 ---------- 15 files changed, 56 insertions(+), 133 deletions(-) delete mode 100644 mirage-clock-solo5.opam delete mode 100644 mirage-clock-unix.opam delete mode 100644 solo5/clock_stubs.default.c delete mode 100644 solo5/clock_stubs.solo5.c delete mode 100644 solo5/dune rename {unix => src}/clock_stubs.c (94%) rename solo5/mclock.ml => src/mclock.solo5.ml (100%) rename unix/mclock.ml => src/mclock.unix.ml (100%) create mode 100644 src/mirage_clock.ml rename solo5/pclock.ml => src/pclock.solo5.ml (100%) rename unix/pclock.ml => src/pclock.unix.ml (100%) delete mode 100644 unix/dune diff --git a/config/discover.ml b/config/discover.ml index 8e8f03d..ac7643e 100644 --- a/config/discover.ml +++ b/config/discover.ml @@ -2,15 +2,21 @@ module C = Configurator.V1 let () = C.main ~name:"mirage-clock-unix" (fun c -> - let is_android = - let defines = + let android, solo5 = + let android_defines = C.C_define.import c ~includes:[] [ ("__ANDROID__", Switch) ] in - match defines with (_, Switch true) :: _ -> true | _ -> false + let solo5_defines = + C.C_define.import c ~includes:[] [ ("__ocaml_solo5__", Switch) ] + in + match android_defines, solo5_defines with + | (_, Switch true) :: _, _ -> true, false + | _, (_, Switch true) :: _ -> false, true + | _ -> false, false in let ccflags = - match (C.ocaml_config_var c "system", is_android) with - | Some "linux", false -> [ "-lrt" ] + match (C.ocaml_config_var c "system", android, solo5) with + | Some "linux", false, false -> [ "-lrt" ] | _ -> [] in C.Flags.write_sexp "cclib.sexp" ccflags) diff --git a/lib_test/dune b/lib_test/dune index 80c2894..dd0ee15 100644 --- a/lib_test/dune +++ b/lib_test/dune @@ -1,4 +1,4 @@ (test (name portable) (package mirage-clock) - (libraries mirage-clock.unix)) + (libraries mirage-clock)) diff --git a/mirage-clock-solo5.opam b/mirage-clock-solo5.opam deleted file mode 100644 index 9387cee..0000000 --- a/mirage-clock-solo5.opam +++ /dev/null @@ -1,29 +0,0 @@ -opam-version: "2.0" -maintainer: "anil@recoil.org" -authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"] -license: "ISC" -tags: "org:mirage" -homepage: "https://github.com/mirage/mirage-clock" -bug-reports: "https://github.com/mirage/mirage-clock/issues" -synopsis: "Paravirtual implementation of the MirageOS Clock interface" -description: """ -This 'freestanding' implementation of the MirageOS CLOCK interface -is designed to be linked against an embedded runtime that provides -a concrete implementation of the clock source. Example implementations -include the [Solo5](https://github.com/solo5/solo5) backend of -MirageOS. -""" -depends: [ - "ocaml" {>= "4.08.0"} - "dune" {>= "2.8"} - "mirage-clock" {= version} -] -conflicts: [ - "mirage-solo5" {< "0.7.0"} - "mirage-xen" {< "7.0.0"} -] -build: [ - ["dune" "subst"] {dev} - ["dune" "build" "-p" name "-j" jobs] -] -dev-repo: "git+https://github.com/mirage/mirage-clock.git" diff --git a/mirage-clock-unix.opam b/mirage-clock-unix.opam deleted file mode 100644 index 204dfc5..0000000 --- a/mirage-clock-unix.opam +++ /dev/null @@ -1,26 +0,0 @@ -opam-version: "2.0" -maintainer: "anil@recoil.org" -authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"] -license: "ISC" -tags: "org:mirage" -homepage: "https://github.com/mirage/mirage-clock" -doc: "https://mirage.github.io/mirage-clock/" -bug-reports: "https://github.com/mirage/mirage-clock/issues" -synopsis: "Unix-based implementation for the MirageOS Clock interface" -description: """ -The Unix implementation of the MirageOS Clock interface uses -`gettimeofday` or `clock_gettime`, depending on -which OS is in use (see [clock_stubs.c](https://github.com/mirage/mirage-clock/blob/master/unix/clock_stubs.c)). -""" -depends: [ - "ocaml" {>= "4.08.0"} - "dune" {>= "2.8"} - "dune-configurator" - "mirage-clock" {= version} -] -build: [ - ["dune" "subst"] {dev} - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name] {with-test} -] -dev-repo: "git+https://github.com/mirage/mirage-clock.git" diff --git a/solo5/clock_stubs.default.c b/solo5/clock_stubs.default.c deleted file mode 100644 index e69de29..0000000 diff --git a/solo5/clock_stubs.solo5.c b/solo5/clock_stubs.solo5.c deleted file mode 100644 index 8424b3b..0000000 --- a/solo5/clock_stubs.solo5.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2010 Anil Madhavapeddy - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "solo5.h" - -#include - -#include -#include -#include -#include - -// caml_get_monotonic_time is already defined in mirage-solo5 - -CAMLprim value -caml_get_wall_clock(value v_unit) -{ - CAMLparam1(v_unit); - CAMLreturn(caml_copy_int64(solo5_clock_wall())); -} diff --git a/solo5/dune b/solo5/dune deleted file mode 100644 index 6c04097..0000000 --- a/solo5/dune +++ /dev/null @@ -1,25 +0,0 @@ -(library - (name mirage_clock_solo5) - (public_name mirage-clock.solo5) - (implements mirage-clock) - (foreign_stubs - (language c) - (names clock_stubs))) - -(rule - (target clock_stubs.c) - (enabled_if - (<> %{context_name} "solo5")) - (deps - (:src clock_stubs.default.c)) - (action - (copy %{src} %{target}))) - -(rule - (target clock_stubs.c) - (enabled_if - (= %{context_name} "solo5")) - (deps - (:src clock_stubs.solo5.c)) - (action - (copy %{src} %{target}))) diff --git a/unix/clock_stubs.c b/src/clock_stubs.c similarity index 94% rename from unix/clock_stubs.c rename to src/clock_stubs.c index ae2bef4..9ae8a10 100644 --- a/unix/clock_stubs.c +++ b/src/clock_stubs.c @@ -14,6 +14,28 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if defined(__ocaml_solo5__) + +#include "solo5.h" + +#include + +#include +#include +#include +#include + +// caml_get_monotonic_time is already defined in mirage-solo5 + +CAMLprim value +caml_get_wall_clock(value v_unit) +{ + CAMLparam1(v_unit); + CAMLreturn(caml_copy_int64(solo5_clock_wall())); +} + +#else + #include #include #include @@ -240,3 +262,5 @@ CAMLprim value ocaml_posix_clock_period_ns (value unit) return caml_copy_int64 (0L); } #endif + +#endif // ocaml_solo5 diff --git a/src/dune b/src/dune index f29a728..b4c5b86 100644 --- a/src/dune +++ b/src/dune @@ -1,4 +1,21 @@ (library (name mirage_clock) (public_name mirage-clock) - (virtual_modules mirage_clock)) + (modules mirage_clock pclock mclock) + (libraries + (select pclock.ml from + (unix -> pclock.unix.ml) + (mirage-solo5 -> pclock.solo5.ml) + (mirage-xen -> pclock.solo5.ml) +) + (select mclock.ml from + (unix -> mclock.unix.ml) + (mirage-solo5 -> mclock.solo5.ml) + (mirage-xen -> mclock.solo5.ml) +)) + (foreign_stubs + (language c) + (names clock_stubs)) + (c_library_flags + (:standard + (:include ../config/cclib.sexp)))) diff --git a/solo5/mclock.ml b/src/mclock.solo5.ml similarity index 100% rename from solo5/mclock.ml rename to src/mclock.solo5.ml diff --git a/unix/mclock.ml b/src/mclock.unix.ml similarity index 100% rename from unix/mclock.ml rename to src/mclock.unix.ml diff --git a/src/mirage_clock.ml b/src/mirage_clock.ml new file mode 100644 index 0000000..4afb665 --- /dev/null +++ b/src/mirage_clock.ml @@ -0,0 +1,2 @@ +module Pclock = Pclock +module Mclock = Mclock diff --git a/solo5/pclock.ml b/src/pclock.solo5.ml similarity index 100% rename from solo5/pclock.ml rename to src/pclock.solo5.ml diff --git a/unix/pclock.ml b/src/pclock.unix.ml similarity index 100% rename from unix/pclock.ml rename to src/pclock.unix.ml diff --git a/unix/dune b/unix/dune deleted file mode 100644 index 877a2ca..0000000 --- a/unix/dune +++ /dev/null @@ -1,13 +0,0 @@ -(library - (name mirage_clock_unix) - (public_name mirage-clock.unix) - (implements mirage-clock) - (libraries unix) - (foreign_stubs - (language c) - (flags - (:standard \ -Wall -g -O2)) - (names clock_stubs)) - (c_library_flags - (:standard - (:include ../config/cclib.sexp)))) From 37803bc37bb6f08997a1c08298dcd65bc309c959 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 23 Apr 2024 21:30:30 +0100 Subject: [PATCH 3/3] minor --- .github/workflows/esy.yml | 4 ---- appveyor.yml | 4 ++-- config/discover.ml | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/esy.yml b/.github/workflows/esy.yml index f5313b6..11f0d20 100644 --- a/.github/workflows/esy.yml +++ b/.github/workflows/esy.yml @@ -30,14 +30,10 @@ jobs: "dependencies": { "ocaml": "4.12.x", "@opam/mirage-clock": "*", - "@opam/mirage-clock-unix": "*", - "@opam/mirage-clock-solo5": "*", "reason-mobile": "github:EduardoRFS/reason-mobile:generate.json#7ba258319b87943d2eb0d8fb84562d0afeb2d41f" }, "resolutions": { "@opam/mirage-clock": "./mirage-clock.opam", - "@opam/mirage-clock-unix": "./mirage-clock-unix.opam", - "@opam/mirage-clock-solo5": "./mirage-clock-solo5.opam" } }' > esy.json diff --git a/appveyor.yml b/appveyor.yml index f6a3eb6..c03cfbb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,8 +6,8 @@ environment: FORK_BRANCH: master CYG_ROOT: C:\cygwin64 OPAM_SWITCH: 4.08.0+mingw64c - PINS: "mirage-clock.dev:. mirage-clock-unix.dev:." - PACKAGE: "mirage-clock-unix" + PINS: "mirage-clock.dev:." + PACKAGE: "mirage-clock" install: - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/$env:FORK_USER/ocaml-ci-scripts/$env:FORK_BRANCH/appveyor-install.ps1")) diff --git a/config/discover.ml b/config/discover.ml index ac7643e..10937ff 100644 --- a/config/discover.ml +++ b/config/discover.ml @@ -1,7 +1,7 @@ module C = Configurator.V1 let () = - C.main ~name:"mirage-clock-unix" (fun c -> + C.main ~name:"mirage-clock" (fun c -> let android, solo5 = let android_defines = C.C_define.import c ~includes:[] [ ("__ANDROID__", Switch) ]