Skip to content

Commit

Permalink
port to dune and port opam metadata to 2.0
Browse files Browse the repository at this point in the history
* Port library to Dune from jbuilder and the builtin
  `dune.configurator` to reduce the build dependency cone
* Remove unused variable warnings (@avsm).
* Update opam package metadata to 2.0 format (@avsm).
  • Loading branch information
avsm committed Dec 27, 2018
1 parent 2e27c50 commit d57102f
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 142 deletions.
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
### v2.0.0

* Constrain the clock type `t` to `unit` to improve compatability with
the webmachine CLOCK interface. All current implementations satisfy
this interface so there shouldn't be an issue, but bumping the
library major version number to reflect the interface change (#38 @hannesm)

* Port library to Dune from jbuilder and use `dune-release` and the builtin
`dune.configurator` to reduce the build dependency cone (@avsm).

* Remove unused variable warnings (@avsm).

* Update opam package metadata to 2.0 format (@avsm).

### v1.4.1 (2018-08-03)

* mirage-clock-unix: fix integer overflow on 32 bit (#37, @mattgray)
Expand Down
27 changes: 8 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@

.PHONY: build clean test

build:
jbuilder build @install
dune build @install

test:
jbuilder runtest
dune runtest

install:
jbuilder install
dune install

uninstall:
jbuilder uninstall

clean:
rm -rf _build *.install
dune uninstall

REPO=../../mirage/opam-repository
PACKAGES=$(REPO)/packages
# until we have https://github.com/ocaml/opam-publish/issues/38
pkg-%:
topkg opam pkg -n $*
mkdir -p $(PACKAGES)/$*
cp -r _build/$*.* $(PACKAGES)/$*/
cd $(PACKAGES) && git add $*
doc:
dune build @doc

PKGS=$(basename $(wildcard *.opam))
opam-pkg:
$(MAKE) $(PKGS:%=pkg-%)
clean:
dune clean
10 changes: 2 additions & 8 deletions config/discover.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
open Base
open Stdio
module C = Configurator

let write_sexp fn sexp =
Out_channel.write_all fn ~data:(Sexp.to_string sexp)
module C = Configurator.V1

let () =
C.main ~name:"mirage-clock-unix" (fun c ->
let ccflags =
match C.ocaml_config_var c "system" with
| Some "linux" -> ["-lrt"]
| _ -> [] in
write_sexp "cclib.sexp" (Sexp.List (List.map ~f:(fun x -> Sexp.Atom x) ccflags));
Out_channel.write_all "cclib" ~data:(String.concat ccflags ~sep:" ")
C.Flags.write_sexp "cclib.sexp" ccflags;
)
8 changes: 8 additions & 0 deletions config/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(executables
(names discover)
(libraries dune.configurator))

(rule
(targets cclib.sexp)
(deps discover.exe)
(action (run ./discover.exe)))
10 changes: 0 additions & 10 deletions config/jbuild

This file was deleted.

2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.0)
(name mirage-clock)
5 changes: 5 additions & 0 deletions freestanding/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name mirage_clock_freestanding)
(wrapped false)
(public_name mirage-clock-freestanding)
(libraries mirage-clock mirage-clock-lwt))
6 changes: 0 additions & 6 deletions freestanding/jbuild

This file was deleted.

1 change: 0 additions & 1 deletion freestanding/mclock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

type t = unit
type 'a io = 'a Lwt.t
type error = unit

let connect _ = Lwt.return_unit
let disconnect _t = Lwt.return_unit
Expand Down
7 changes: 3 additions & 4 deletions freestanding/pclock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

type t = unit
type 'a io = 'a Lwt.t
type error = unit

external time : unit -> float = "unix_gettimeofday"

Expand All @@ -28,7 +27,7 @@ let connect _ = Lwt.return_unit
let disconnect _t = Lwt.return_unit

(* Based on Ptime.of_float_s *)
let now_d_ps t =
let now_d_ps () =
let secs = time () in
if secs <> secs then failwith "unix_gettimeofday returned NaN" else
let days = floor (secs /. 86_400.) in
Expand All @@ -42,10 +41,10 @@ let now_d_ps t =
let frac_ps = Int64.(of_float (frac_s *. 1e12)) in
(int_of_float days, (Int64.add rem_ps frac_ps))

let current_tz_offset_s t = None
let current_tz_offset_s () = None

(* According to
* https://github.com/mirage/mini-os/blob/edfd5aae6ec5ba7d0a8834a3e9dfe5e69424150a/arch/x86/time.c#L194
* the clock period is 1 microsecond
* *)
let period_d_ps t = Some (0, 1_000_000L)
let period_d_ps () = Some (0, 1_000_000L)
3 changes: 3 additions & 0 deletions lib_test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(test
(name portable)
(libraries lwt.unix mirage-clock-unix))
9 changes: 0 additions & 9 deletions lib_test/jbuild

This file was deleted.

2 changes: 1 addition & 1 deletion lib_test/portable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let print_offset c = match Pclock.current_tz_offset_s c with
| None -> Printf.printf "Clock UTC offset unavailable\n"

let print_period c = match Pclock.period_d_ps c with
| Some (d, ps) -> Printf.printf "The clock period is: %Ld picoseconds\n" ps
| Some (_, ps) -> Printf.printf "The clock period is: %Ld picoseconds\n" ps
| None -> Printf.printf "Clock period unavailable\n"

let print_mtime c =
Expand Down
4 changes: 4 additions & 0 deletions lwt/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name mirage_clock_lwt)
(public_name mirage-clock-lwt)
(libraries mirage-clock lwt))
5 changes: 0 additions & 5 deletions lwt/jbuild

This file was deleted.

30 changes: 19 additions & 11 deletions mirage-clock-freestanding.opam
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
opam-version: "1.2"
authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"]
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"
dev-repo: "git://github.com/mirage/mirage-clock"
license: "ISC"
tags: ["org:mirage"]
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: [
"jbuilder" {build & >="1.0+beta9"}
"mirage-clock" {>= "1.2.0"}
"mirage-clock-lwt" {>= "1.2.0"}
"ocaml" {>= "4.04.2"}
"dune" {build}
"mirage-clock" {>= version}
"mirage-clock-lwt" {>= version}
"lwt"
]
build: [
[ "jbuilder" "subst" ] {pinned}
[ "jbuilder" "build" "-p" name "-j" jobs ]
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
available: [ ocaml-version >= "4.04.2" ]
dev-repo: "git://github.com/mirage/mirage-clock"
34 changes: 19 additions & 15 deletions mirage-clock-lwt.opam
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
opam-version: "1.2"
authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"]
maintainer: "anil@recoil.org"
homepage: "https://github.com/mirage/mirage-clock"
bug-reports: "https://github.com/mirage/mirage-clock/issues"
dev-repo: "https://github.com/mirage/mirage-clock.git"
doc: "https://mirage.github.io/mirage-clock/"
license: "ISC"
tags: ["org:mirage"]

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: "Lwt-based implementation of the MirageOS Clock interface"
description: """
This implementation of the MirageOS CLOCK interface specialises
the `io` type to use the Lwt concurrency monad.
"""
depends: [
"jbuilder" {build & >="1.0+beta9"}
"mirage-clock" {>= "1.2.0"}
"ocaml" {>= "4.04.2"}
"dune" {build}
"mirage-clock" {>= version}
"lwt"
]
build: [
[ "jbuilder" "subst" ] {pinned}
[ "jbuilder" "build" "-p" name "-j" jobs ]
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
available: [ ocaml-version >= "4.04.2" ]
dev-repo: "git+https://github.com/mirage/mirage-clock.git"
40 changes: 22 additions & 18 deletions mirage-clock-unix.opam
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
opam-version: "1.2"
authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"]
maintainer: "anil@recoil.org"
homepage: "https://github.com/mirage/mirage-clock"
bug-reports: "https://github.com/mirage/mirage-clock/issues"
dev-repo: "https://github.com/mirage/mirage-clock.git"
doc: "https://mirage.github.io/mirage-clock/"
license: "ISC"
tags: ["org:mirage"]

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: [
"jbuilder" {build & >="1.0+beta9"}
"mirage-clock" {>= "1.2.0"}
"mirage-clock-lwt" {>= "1.2.0"}
"ocaml" {>= "4.04.2"}
"dune" {build}
"mirage-clock" {>= version}
"mirage-clock-lwt" {>= versionn}
"lwt"
"configurator" {build}
]
build: [
[ "jbuilder" "subst" ] {pinned}
[ "jbuilder" "build" "-p" name "-j" jobs ]
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name] {with-test}
]
build-test: ["jbuilder" "runtest" "-p" name]
available: [ ocaml-version >= "4.04.2" ]
dev-repo: "git+https://github.com/mirage/mirage-clock.git"
35 changes: 22 additions & 13 deletions mirage-clock.opam
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
opam-version: "1.2"
authors: ["Anil Madhavapeddy" "Daniel C. Bünzli" "Matthew Gray"]
maintainer: "anil@recoil.org"
homepage: "https://github.com/mirage/mirage-clock"
bug-reports: "https://github.com/mirage/mirage-clock/issues"
dev-repo: "https://github.com/mirage/mirage-clock.git"
doc: "https://mirage.github.io/mirage-clock/"
license: "ISC"
tags: ["org:mirage"]
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: "Libraries and module types for portable clocks"
description: """
This library implements portable support for an operating system timesource
that is compatible with the [MirageOS](https://mirage.io) library interfaces
found in: <https://github.com/mirage/mirage>

It implements an `MCLOCK` module that represents a monotonic timesource
since an arbitrary point, and `PCLOCK` which counts time since the Unix
epoch.
"""
depends: [
"jbuilder" {build & >="1.0+beta9"}
"ocaml" {>= "4.04.2"}
"dune" {build}
"mirage-device" {>= "1.0.0"}
]
build: [
[ "jbuilder" "subst" ] {pinned}
[ "jbuilder" "build" "-p" name "-j" jobs ]
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
available: [ ocaml-version >= "4.04.2" ]
dev-repo: "git+https://github.com/mirage/mirage-clock.git"
2 changes: 0 additions & 2 deletions pkg/pkg.ml

This file was deleted.

4 changes: 4 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name mirage_clock)
(public_name mirage-clock)
(libraries mirage-device))
5 changes: 0 additions & 5 deletions src/jbuild

This file was deleted.

8 changes: 8 additions & 0 deletions unix/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(library
(name mirage_clock_unix)
(wrapped false)
(public_name mirage-clock-unix)
(libraries mirage-clock mirage-clock-lwt)
(c_names clock_stubs)
(c_flags ((:standard \ -Wall -g -O2)))
(c_library_flags (:standard (:include ../config/cclib.sexp))))
9 changes: 0 additions & 9 deletions unix/jbuild

This file was deleted.

2 changes: 1 addition & 1 deletion unix/mclock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*)
type t = unit
type 'a io = 'a Lwt.t
type error = unit
type _error = unit

external _elapsed_ns : unit -> int64 = "ocaml_monotonic_clock_elapsed_ns"

Expand Down
Loading

0 comments on commit d57102f

Please sign in to comment.