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

Conditional compilation #59

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 0 additions & 4 deletions .github/workflows/esy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
18 changes: 12 additions & 6 deletions config/discover.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
module C = Configurator.V1

let () =
C.main ~name:"mirage-clock-unix" (fun c ->
let is_android =
let defines =
C.main ~name:"mirage-clock" (fun c ->
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)
4 changes: 2 additions & 2 deletions lib_test/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(test
(name portable)
(package mirage-clock-unix)
(libraries mirage-clock-unix))
(package mirage-clock)
(libraries mirage-clock))
2 changes: 2 additions & 0 deletions lib_test/portable.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 0 additions & 29 deletions mirage-clock-solo5.opam

This file was deleted.

26 changes: 0 additions & 26 deletions mirage-clock-unix.opam

This file was deleted.

Empty file removed solo5/clock_stubs.default.c
Empty file.
33 changes: 0 additions & 33 deletions solo5/clock_stubs.solo5.c

This file was deleted.

26 changes: 0 additions & 26 deletions solo5/dune

This file was deleted.

22 changes: 0 additions & 22 deletions solo5/mclock.mli

This file was deleted.

21 changes: 0 additions & 21 deletions solo5/pclock.mli

This file was deleted.

24 changes: 24 additions & 0 deletions unix/clock_stubs.c → src/clock_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#if defined(__ocaml_solo5__)

#include "solo5.h"

#include <sys/time.h>

#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>

// 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 <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
Expand Down Expand Up @@ -240,3 +262,5 @@ CAMLprim value ocaml_posix_clock_period_ns (value unit)
return caml_copy_int64 (0L);
}
#endif

#endif // ocaml_solo5
20 changes: 19 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
(library
(name mirage_clock)
(public_name mirage-clock))
(public_name 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))))
File renamed without changes.
File renamed without changes.
56 changes: 2 additions & 54 deletions src/mirage_clock.ml
Original file line number Diff line number Diff line change
@@ -1,54 +1,2 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* 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.
*)
(** Clock devices for MirageOS

This module define clock devices signatures for MirageOS.

{e Release %%VERSION%%} *)

(** {2 POSIX clock}

Clock counting time since the Unix epoch. Subject to adjustment by e.g. NTP. *)
module type 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.
[ps] is in the range \[[0];[86_399_999_999_999_999L]\]. *)

val current_tz_offset_s : unit -> int option
(** [current_tz_offset_s ()] is the clock's current local time zone offset to
UTC in seconds, if known. This is the duration local time - UTC time in
seconds. *)

val period_d_ps : unit -> (int * int64) option
(** [period_d_ps ()] is [Some (d, ps)] representing the clock's picosecond
period [d] * 86'400e12 + [ps], if known. [ps] is in the range
\[[0];[86_399_999_999_999_999L]\]. *)
end

(** {2 Monotonic clock}

Clock returning monotonic time since an arbitrary point. To be used for e.g.
profiling. *)
module type MCLOCK = sig
val elapsed_ns : unit -> int64
(** [elapsed_ns ()] is a monotonically increasing count of nanoseconds elapsed
since some arbitrary point *)

val period_ns : unit -> int64 option
(** [period_ns ()] is [Some ns] representing the clock's nanosecond period
[ns], if known *)
end
module Pclock = Pclock
module Mclock = Mclock
Loading
Loading