A B0 driver like b0 or d0 is an executable that provides a service on the definitions of a B0 file. This manual shows how to develop a custom driver for B0 files.
The B0 file needs to be compiled and made accessible to the driver executable. At the moment the OCaml Dynlink API is not being used. Instead the driver executable relinks its objects with a compilation of the B0 file to produce another executable that is executed to run the driver on the definitions.
With the help of the B0_driver module this all happens transparently in the .drivers directory of the _b0 directory.
For your driver to access a B0 file you need to create an OCaml library which has all the objects of your driver and registers its main function by calling B0_driver.set.
Source wise a typical driver source structure is:
src/mydriver_main.ml
src/mydriver_main_run.mlThe mydriver_main.ml file implements and registers the driver. It's compiled object should be part of your driver library. Here's a minimal example :
open B0_std
open Cmdliner
let driver =
let name = "mydriver" and version = "v0.0.2-12-g2e7fa30e" in
let libs = ["mydriver" (* other needed libraries can be added here *) ] in
B0_driver.create ~name ~version ~libs
let my_driver conf = Fmt.pr "Running %s!@."; B0_driver.Exit.ok
let my_driver =
let doc = "My driver" in
let sdocs = Manpage.s_common_options in
let exits = B0_driver.Exit.Info.base_cmd in
let man = [ `S Manpage.s_description; "$(mname) does not much." ] in
B0_driver.with_b0_file ~driver (Term.const unit_cmd),
Term.info "mydriver" ~version:"v0.0.2-12-g2e7fa30e" ~doc ~sdocs ~exits ~man
let main () = Term.eval mydriver
let () = B0_driver.set driver ~mainThe mydriver_main_run.ml file defines your driver executable when it has no B0 file linked in. It's the program that runs your driver without the B0 file linked in. It should simply be:
let () =
let module D = Mydriver_main (* make sure we link it *) in
if !Sys.interactive then () else B0_driver.run ~has_b0_file:falseA few things to note:
OCAMLPATH under the name you gave in to B0_driver.#require directive.The driver dance seems to be a bit slow for now. Even for the up-to-date dance we get into the 43ms b0 unit list. But there's room for improvement. Here are different things to consider that could be done.
Dylink once it gets lib support, but then what about platforms that don't support it.b0 file log --stats and b0 -v -v don't add up to what time b0 reports. Investigate, is it the execv ? June 2020: maybe it is/was that. Also see how much toplevel init takes (how ?).