Skip to content

Commit 258ced5

Browse files
authoredJun 18, 2018
Merge pull request #906 from mirage/dev-solo5
Merge dev-solo5 branch into master
2 parents a6b1aa6 + 16c498d commit 258ced5

File tree

3 files changed

+82
-60
lines changed

3 files changed

+82
-60
lines changed
 

‎lib/mirage.ml

+74-56
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ let connect_err name number =
4343

4444
(* Mirage implementation backing the target. *)
4545
let backend_predicate = function
46-
| `Xen | `Qubes -> "mirage_xen"
47-
| `Virtio | `Ukvm -> "mirage_solo5"
48-
| `Unix | `MacOSX -> "mirage_unix"
46+
| `Xen | `Qubes -> "mirage_xen"
47+
| `Virtio | `Ukvm | `Muen -> "mirage_solo5"
48+
| `Unix | `MacOSX -> "mirage_unix"
4949

5050
(** {2 Devices} *)
5151
let qrexec = job
@@ -232,7 +232,7 @@ let nocrypto = impl @@ object
232232
| `Xen | `Qubes ->
233233
[ package ~min:"0.5.4" ~sublibs:["mirage"] "nocrypto";
234234
package ~ocamlfind:[] "zarith-xen" ]
235-
| `Virtio | `Ukvm ->
235+
| `Virtio | `Ukvm | `Muen ->
236236
[ package ~min:"0.5.4" ~sublibs:["mirage"] "nocrypto";
237237
package ~ocamlfind:[] "zarith-freestanding" ]
238238
| `Unix | `MacOSX ->
@@ -241,7 +241,7 @@ let nocrypto = impl @@ object
241241
method! build _ = R.ok (enable_entropy ())
242242
method! connect i _ _ =
243243
match get_target i with
244-
| `Xen | `Qubes | `Virtio | `Ukvm -> "Nocrypto_entropy_mirage.initialize ()"
244+
| `Xen | `Qubes | `Virtio | `Ukvm | `Muen -> "Nocrypto_entropy_mirage.initialize ()"
245245
| `Unix | `MacOSX -> "Nocrypto_entropy_lwt.initialize ()"
246246
end
247247
@@ -300,7 +300,8 @@ let custom_console str =
300300
`Xen, console_xen str;
301301
`Qubes, console_xen str;
302302
`Virtio, console_solo5 str;
303-
`Ukvm, console_solo5 str
303+
`Ukvm, console_solo5 str;
304+
`Muen, console_solo5 str
304305
] ~default:(console_unix str)
305306
306307
let default_console = custom_console "0"
@@ -349,7 +350,8 @@ let direct_kv_ro dirname =
349350
`Xen, crunch dirname;
350351
`Qubes, crunch dirname;
351352
`Virtio, crunch dirname;
352-
`Ukvm, crunch dirname
353+
`Ukvm, crunch dirname;
354+
`Muen, crunch dirname
353355
] ~default:(direct_kv_ro_conf dirname)
354356

355357
type block = BLOCK
@@ -415,7 +417,7 @@ class block_conf file =
415417
method! packages =
416418
Key.match_ Key.(value target) @@ function
417419
| `Xen | `Qubes -> xen_block_packages
418-
| `Virtio | `Ukvm -> [ package ~min:"0.2.1" "mirage-block-solo5" ]
420+
| `Virtio | `Ukvm | `Muen -> [ package ~min:"0.2.1" "mirage-block-solo5" ]
419421
| `Unix | `MacOSX -> [ package ~min:"2.5.0" "mirage-block-unix" ]
420422

421423
method! configure _ =
@@ -424,15 +426,18 @@ class block_conf file =
424426

425427
method private connect_name target root =
426428
match target with
427-
| `Unix | `MacOSX | `Virtio | `Ukvm ->
429+
| `Unix | `MacOSX | `Virtio | `Ukvm | `Muen ->
428430
Fpath.(to_string (root / file)) (* open the file directly *)
429431
| `Xen | `Qubes ->
430432
let b = make_block_t file in
431433
xenstore_id_of_index b.number |> string_of_int
432434

433435
method! connect i s _ =
434-
Fmt.strf "%s.connect %S" s
435-
(self#connect_name (get_target i) @@ Info.build_dir i)
436+
match get_target i with
437+
| `Muen -> failwith "Block devices not supported on Muen target."
438+
| `Unix | `MacOSX | `Virtio | `Ukvm | `Xen | `Qubes ->
439+
Fmt.strf "%s.connect %S" s
440+
(self#connect_name (get_target i) @@ Info.build_dir i)
436441
end
437442

438443
let block_of_file file = impl (new block_conf file)
@@ -600,7 +605,7 @@ let network_conf (intf : string Key.key) =
600605
| `MacOSX -> [ package ~min:"1.3.0" "mirage-net-macosx" ]
601606
| `Xen -> [ package ~min:"1.7.0" "mirage-net-xen"]
602607
| `Qubes -> [ package ~min:"1.7.0" "mirage-net-xen" ; package ~min:"0.4" "mirage-qubes" ]
603-
| `Virtio | `Ukvm -> [ package ~min:"0.2.0" "mirage-net-solo5" ]
608+
| `Virtio | `Ukvm | `Muen -> [ package ~min:"0.2.0" "mirage-net-solo5" ]
604609
method! connect _ modname _ =
605610
Fmt.strf "%s.connect %a" modname Key.serialize_call key
606611
method! configure i =
@@ -705,9 +710,9 @@ let (@??) x y = opt_map Key.abstract x @? y
705710
(* convenience function for linking tcpip.unix or .xen for checksums *)
706711
let right_tcpip_library ?min ?max ?ocamlfind ~sublibs pkg =
707712
Key.match_ Key.(value target) @@ function
708-
|`MacOSX | `Unix -> [ package ?min ?max ?ocamlfind ~sublibs:("unix"::sublibs) pkg ]
709-
|`Qubes | `Xen -> [ package ?min ?max ?ocamlfind ~sublibs:("xen"::sublibs) pkg ]
710-
|`Virtio | `Ukvm -> [ package ?min ?max ?ocamlfind ~sublibs pkg ]
713+
|`MacOSX | `Unix -> [ package ?min ?max ?ocamlfind ~sublibs:("unix"::sublibs) pkg ]
714+
|`Qubes | `Xen -> [ package ?min ?max ?ocamlfind ~sublibs:("xen"::sublibs) pkg ]
715+
|`Virtio | `Ukvm | `Muen -> [ package ?min ?max ?ocamlfind ~sublibs pkg ]
711716

712717
let ipv4_keyed_conf ?network ?gateway () = impl @@ object
713718
inherit base_configurable
@@ -1343,7 +1348,8 @@ let default_argv =
13431348
`Xen, argv_xen;
13441349
`Qubes, argv_xen;
13451350
`Virtio, argv_solo5;
1346-
`Ukvm, argv_solo5
1351+
`Ukvm, argv_solo5;
1352+
`Muen, argv_solo5
13471353
] ~default:argv_unix
13481354

13491355
(** Log reporting *)
@@ -1413,7 +1419,7 @@ let mprof_trace ~size () =
14131419
method! packages =
14141420
Key.match_ Key.(value target) @@ function
14151421
| `Xen | `Qubes -> [ package "mirage-profile"; package "mirage-profile-xen" ]
1416-
| `Virtio | `Ukvm -> []
1422+
| `Virtio | `Ukvm | `Muen -> []
14171423
| `Unix | `MacOSX -> [ package "mirage-profile"; package "mirage-profile-unix" ]
14181424
method! build _ =
14191425
match query_ocamlfind ["lwt.tracing"] with
@@ -1422,7 +1428,7 @@ let mprof_trace ~size () =
14221428
opam pin add lwt https://github.com/mirage/lwt.git#tracing"
14231429
| Ok _ -> Ok ()
14241430
method! connect i _ _ = match get_target i with
1425-
| `Virtio | `Ukvm -> failwith "tracing is not currently implemented for solo5 targets"
1431+
| `Virtio | `Ukvm | `Muen -> failwith "tracing is not currently implemented for solo5 targets"
14261432
| `Unix | `MacOSX ->
14271433
Fmt.strf
14281434
"Lwt.return ())@.\
@@ -1858,12 +1864,12 @@ let compile libs warn_error target =
18581864
(if terminal () then ["color(always)"] else [])
18591865
and result = match target with
18601866
| `Unix | `MacOSX -> "main.native"
1861-
| `Xen | `Qubes | `Virtio | `Ukvm -> "main.native.o"
1867+
| `Xen | `Qubes | `Virtio | `Ukvm | `Muen -> "main.native.o"
18621868
and cflags = [ "-g" ]
18631869
and lflags =
18641870
let dontlink =
18651871
match target with
1866-
| `Xen | `Qubes | `Virtio | `Ukvm -> ["unix"; "str"; "num"; "threads"]
1872+
| `Xen | `Qubes | `Virtio | `Ukvm | `Muen -> ["unix"; "str"; "num"; "threads"]
18671873
| `Unix | `MacOSX -> []
18681874
in
18691875
let dont = List.map (fun k -> [ "-dontlink" ; k ]) dontlink in
@@ -1942,6 +1948,26 @@ let ldflags pkg = pkg_config pkg ["--variable=ldflags"]
19421948

19431949
let ldpostflags pkg = pkg_config pkg ["--variable=ldpostflags"]
19441950

1951+
let find_ld pkg =
1952+
match pkg_config pkg ["--variable=ld"] with
1953+
| Ok (ld::_) ->
1954+
Log.warn (fun m -> m "using %s as ld (pkg-config %s --variable=ld)" ld pkg) ;
1955+
ld
1956+
| Ok [] ->
1957+
Log.warn (fun m -> m "pkg-config %s --variable=ld returned nothing, using ld" pkg) ;
1958+
"ld"
1959+
| Error msg ->
1960+
Log.warn (fun m -> m "error %a while pkg-config %s --variable=ld, using ld"
1961+
Rresult.R.pp_msg msg pkg) ;
1962+
"ld"
1963+
1964+
let solo5_pkg = function
1965+
| `Virtio -> "solo5-kernel-virtio", ".virtio"
1966+
| `Muen -> "solo5-kernel-muen", ".muen"
1967+
| `Ukvm -> "solo5-kernel-ukvm", ".ukvm"
1968+
| `Unix | `MacOSX | `Xen | `Qubes ->
1969+
invalid_arg "solo5_kernel only defined for solo5 targets"
1970+
19451971
let link info name target target_debug =
19461972
let libs = Info.libraries info in
19471973
match target with
@@ -1976,46 +2002,37 @@ let link info name target target_debug =
19762002
Bos.OS.Cmd.run link >>= fun () ->
19772003
Ok out
19782004
end
1979-
| `Virtio ->
2005+
| `Virtio | `Muen | `Ukvm ->
2006+
let pkg, post = solo5_pkg target in
19802007
extra_c_artifacts "freestanding" libs >>= fun c_artifacts ->
19812008
static_libs "mirage-solo5" >>= fun static_libs ->
1982-
ldflags "solo5-kernel-virtio" >>= fun ldflags ->
1983-
ldpostflags "solo5-kernel-virtio" >>= fun ldpostflags ->
1984-
let out = name ^ ".virtio" in
2009+
ldflags pkg >>= fun ldflags ->
2010+
ldpostflags pkg >>= fun ldpostflags ->
2011+
let out = name ^ post in
2012+
let ld = find_ld pkg in
19852013
let linker =
1986-
Bos.Cmd.(v "ld" %% of_list ldflags % "_build/main.native.o" %%
2014+
Bos.Cmd.(v ld %% of_list ldflags % "_build/main.native.o" %%
19872015
of_list c_artifacts %% of_list static_libs % "-o" % out
19882016
%% of_list ldpostflags)
19892017
in
19902018
Log.info (fun m -> m "linking with %a" Bos.Cmd.pp linker);
19912019
Bos.OS.Cmd.run linker >>= fun () ->
1992-
Ok out
1993-
| `Ukvm ->
1994-
extra_c_artifacts "freestanding" libs >>= fun c_artifacts ->
1995-
static_libs "mirage-solo5" >>= fun static_libs ->
1996-
ldflags "solo5-kernel-ukvm" >>= fun ldflags ->
1997-
ldpostflags "solo5-kernel-ukvm" >>= fun ldpostflags ->
1998-
let out = name ^ ".ukvm" in
1999-
let linker =
2000-
Bos.Cmd.(v "ld" %% of_list ldflags % "_build/main.native.o" %%
2001-
of_list c_artifacts %% of_list static_libs % "-o" % out
2002-
%% of_list ldpostflags)
2003-
in
2004-
let ukvm_mods =
2005-
List.fold_left (fun acc -> function
2006-
| "mirage-net-solo5" -> "net" :: acc
2007-
| "mirage-block-solo5" -> "blk" :: acc
2008-
| _ -> acc)
2009-
[] libs @ (if target_debug then ["gdb"] else [])
2010-
in
2011-
pkg_config "solo5-kernel-ukvm" ["--variable=libdir"] >>= function
2012-
| [ libdir ] ->
2013-
Bos.OS.Cmd.run Bos.Cmd.(v "ukvm-configure" % (libdir ^ "/src/ukvm") %% of_list ukvm_mods) >>= fun () ->
2014-
Bos.OS.Cmd.run Bos.Cmd.(v "make" % "-f" % "Makefile.ukvm" % "ukvm-bin") >>= fun () ->
2015-
Log.info (fun m -> m "linking with %a" Bos.Cmd.pp linker);
2016-
Bos.OS.Cmd.run linker >>= fun () ->
2020+
if target = `Ukvm then
2021+
let ukvm_mods =
2022+
List.fold_left (fun acc -> function
2023+
| "mirage-net-solo5" -> "net" :: acc
2024+
| "mirage-block-solo5" -> "blk" :: acc
2025+
| _ -> acc)
2026+
[] libs @ (if target_debug then ["gdb"] else [])
2027+
in
2028+
pkg_config pkg ["--variable=libdir"] >>= function
2029+
| [ libdir ] ->
2030+
Bos.OS.Cmd.run Bos.Cmd.(v "ukvm-configure" % (libdir ^ "/src/ukvm") %% of_list ukvm_mods) >>= fun () ->
2031+
Bos.OS.Cmd.run Bos.Cmd.(v "make" % "-f" % "Makefile.ukvm" % "ukvm-bin") >>= fun () ->
2032+
Ok out
2033+
| _ -> R.error_msg ("pkg-config " ^ pkg ^ " --variable=libdir failed")
2034+
else
20172035
Ok out
2018-
| _ -> R.error_msg "pkg-config solo5-kernel-ukvm --variable=libdir failed"
20192036

20202037
let build i =
20212038
let name = Info.name i in
@@ -2046,6 +2063,7 @@ let clean i =
20462063
Bos.OS.File.delete Fpath.(v name + "xen") >>= fun () ->
20472064
Bos.OS.File.delete Fpath.(v name + "elf") >>= fun () ->
20482065
Bos.OS.File.delete Fpath.(v name + "virtio") >>= fun () ->
2066+
Bos.OS.File.delete Fpath.(v name + "muen") >>= fun () ->
20492067
Bos.OS.File.delete Fpath.(v name + "ukvm") >>= fun () ->
20502068
Bos.OS.File.delete Fpath.(v "Makefile.ukvm") >>= fun () ->
20512069
Bos.OS.Dir.delete ~recurse:true Fpath.(v "_build-ukvm") >>= fun () ->
@@ -2086,12 +2104,12 @@ module Project = struct
20862104
package ~build:true "ocamlbuild" ;
20872105
] in
20882106
Key.match_ Key.(value target) @@ function
2089-
| `Xen | `Qubes -> [ package ~min:"3.0.4" "mirage-xen" ] @ common
2090-
| `Virtio -> [ package ~min:"0.2.1" ~ocamlfind:[] "solo5-kernel-virtio" ;
2091-
package ~min:"0.2.0" "mirage-solo5" ] @ common
2092-
| `Ukvm -> [ package ~min:"0.2.1" ~ocamlfind:[] "solo5-kernel-ukvm" ;
2093-
package ~min:"0.2.0" "mirage-solo5" ] @ common
20942107
| `Unix | `MacOSX -> [ package ~min:"3.0.0" "mirage-unix" ] @ common
2108+
| `Xen | `Qubes -> [ package ~min:"3.0.4" "mirage-xen" ] @ common
2109+
| `Virtio | `Ukvm | `Muen as tgt ->
2110+
let pkg, _ = solo5_pkg tgt in
2111+
[ package ~min:"0.2.1" ~ocamlfind:[] pkg ;
2112+
package ~min:"0.2.0" "mirage-solo5" ] @ common
20952113

20962114
method! build = build
20972115
method! configure = configure

‎lib/mirage_key.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type mode = [
8686
| `Xen
8787
| `Virtio
8888
| `Ukvm
89+
| `Muen
8990
| `MacOSX
9091
| `Qubes
9192
]
@@ -97,6 +98,7 @@ let target_conv: mode Cmdliner.Arg.converter =
9798
"xen" , `Xen;
9899
"virtio", `Virtio;
99100
"ukvm" , `Ukvm;
101+
"muen" , `Muen;
100102
"qubes" , `Qubes
101103
]
102104

@@ -113,13 +115,14 @@ let default_unix = lazy (
113115
let target =
114116
let doc =
115117
"Target platform to compile the unikernel for. Valid values are: \
116-
$(i,xen), $(i,qubes), $(i,unix), $(i,macosx), $(i,virtio), $(i,ukvm)."
118+
$(i,xen), $(i,qubes), $(i,unix), $(i,macosx), $(i,virtio), $(i,ukvm), $(i,muen)."
117119
in
118120
let serialize ppf = function
119121
| `Unix -> Fmt.pf ppf "`Unix"
120122
| `Xen -> Fmt.pf ppf "`Xen"
121123
| `Virtio -> Fmt.pf ppf "`Virtio"
122124
| `Ukvm -> Fmt.pf ppf "`Ukvm"
125+
| `Muen -> Fmt.pf ppf "`Muen"
123126
| `MacOSX -> Fmt.pf ppf "`MacOSX"
124127
| `Qubes -> Fmt.pf ppf "`Qubes"
125128
in
@@ -134,7 +137,7 @@ let target =
134137
let is_unix =
135138
Key.match_ Key.(value target) @@ function
136139
| `Unix | `MacOSX -> true
137-
| `Qubes | `Xen | `Virtio | `Ukvm -> false
140+
| `Qubes | `Xen | `Virtio | `Ukvm | `Muen -> false
138141

139142
let warn_error =
140143
let doc = "Enable -warn-error when compiling OCaml sources." in

‎lib/mirage_key.mli

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ end
3030

3131
include Functoria.KEY with module Arg := Arg
3232

33-
type mode = [ `Unix | `Xen | `Qubes | `MacOSX | `Virtio | `Ukvm ]
33+
type mode = [ `Unix | `Xen | `Qubes | `MacOSX | `Virtio | `Ukvm | `Muen ]
3434

3535
(** {2 Mirage keys} *)
3636

3737
val target: mode key
3838
(** [-t TARGET]: Key setting the configuration mode for the current project.
39-
Is one of ["unix"], ["macosx"], ["xen"], ["qubes"], ["virtio"] or ["ukvm"].
39+
Is one of ["unix"], ["macosx"], ["xen"], ["qubes"], ["virtio"], ["ukvm"]
40+
or ["muen"].
4041
*)
4142

4243
val pp_target: mode Fmt.t

0 commit comments

Comments
 (0)
Please sign in to comment.