[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [MirageOS-devel] Trouble building a separate module that depends on Mirage types
Hi Matt, I am relatively new to all of this, but I think I can help... Start by moving the code in session.ml under a new functor (I'll call it Tcp for lack of inspiration): open Lwt module Tcp (S: V1_LWT.STACKV4) = struct type t = { flow: S.TCPV4.flow; on_close: ( string -> unit ) } (* ... *) let close session reason = session.on_close reason; S.TCPV4.close session.flow (* ... *) end Session.Tcp takes a module parameter "S" that conforms to the V1_LWT.STACKV4 signature. In unikernel.ml, we will need to instantiate a Session.Tcp module, using the STACKV4 parameter "S" fed to Unikernel.Main: open Lwt module Main (C: V1_LWT.CONSOLE) (S: V1_LWT.STACKV4) = struct module Ses = Session.Tcp(S) (* ... *) let start c s = let log message = C.log c message in let write_welcome session = Ses.write session horse_ascii in (* ... *) Neither Unikernel.Main or Session.Tcp "know" the concrete module represented by S, only that its signature matches STACKV4. When you run "mirage configure", the mirage tool uses your config.ml to choose an implementation of STACKV4 that is appropriate to your target environment, and generates main.ml to feed that module into Unikernel.Main. With these changes I was able to build and run your code in --unix. -- Len On Sat, Apr 4, 2015 at 6:59 AM, Matthew Gray <matthew.thomas.gray@xxxxxxxxx> wrote: > Hello, > > I've been working on this https://github.com/mattgray/horseos as a means of > learning about OCaml and the Mirage project. It's a super-basic chat program > that works over TCP. Like IRC with almost no features. > > I've got it all working so far by defining everything in unikernel.ml, and > now I'm trying to split things out into modules - specifically a session > module which deals with reading and writing strings to the TCP connection. > This module works OK when it's also defined in unikernel.ml (see: eg > https://github.com/mattgray/horseos/blob/2563d75b59d95f4a69937cee690f6c8c53a6e79b/unikernel.ml > ) > > However when I pull the module out into it's own file entirely like this: ( > https://github.com/mattgray/horseos/blob/4e7e419ee06e8e245ef466bfa5e9fca546746871/session.ml > ) I get build errors from make (after doing mirage clean/configure): > > ocamlbuild -classic-display -use-ocamlfind -pkgs > lwt.syntax,mirage-console.unix,mirage-types.lwt,tcpip.stack-socket -tags > "syntax(camlp4o),annot,bin_annot,strict_sequence,principal" -tag-line > "<static*.*>: -syntax(camlp4o)" -cflag -g -lflags -g,-linkpkg main.native > ocamlfind ocamlc -c -g -annot -bin-annot -principal -strict-sequence > -package tcpip.stack-socket -package mirage-types.lwt -package > mirage-console.unix -package lwt.syntax -syntax camlp4o -o session.cmo > session.ml > + ocamlfind ocamlc -c -g -annot -bin-annot -principal -strict-sequence > -package tcpip.stack-socket -package mirage-types.lwt -package > mirage-console.unix -package lwt.syntax -syntax camlp4o -o session.cmo > session.ml > File "session.ml", line 3, characters 17-35: > Error: Unbound module STACKV4 > > I'm not sure how to make the STACKV4 (or ultimately the TCPV4.flow type > which is what I really need) into scope here. It seems like mirage-types.lwt > is being passed as a package into ocamlbuild, and I have tried various > permutations on open-ing V1, V1_LWT, V1_LWT.STACKV4 to no avail. The other > thing I have considered (but not tried yet) is that the session module needs > to be "functorized" to work with the types from Mirage. > > Any pointers here would be most appreciated.... I feel like there's > something simple / fundamental here that I'm completely missing! > > Matt > > > > _______________________________________________ > MirageOS-devel mailing list > MirageOS-devel@xxxxxxxxxxxxxxxxxxxx > http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel > _______________________________________________ MirageOS-devel mailing list MirageOS-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |