package b0
Install
Dune Dependency
Authors
Maintainers
Sources
sha512=d24b09eb520b8b91a1e5715badc9f5bcd6a6ec49c047f719a07afef6b835c128dc63e00c3be73d5353b037f4c3c9f2889e40666b30e297e872e4d011f098394c
doc/unit_manual.html
Build unit manual
This manual shows how to deal with B0 build units and create your own.
Custom unit tutorial
We show how to devise a custom unit that compiles a .ml
file to a bytecode executable.
To create a custom unit from scratch it is better not to clutter your B0 file too much and develop it in its own file. At the root of your project issue:
mkdir B0
touch B0/custom.ml
And at the very beginning of your B0.ml
file add:
#mod_use "B0/custom.ml"
open B0_kit.V000
You now have the Custom
module and its definitions available in the B0 file. To make sure everything is working propery. Write in custom.ml
let () = print_endline "Hop!" (* In practice, don't do that ! *)
and test that everything runs properly:
> b0 --what Hop! Empty build.
A build unit is just a build script with static and dynamic metadata attached. Best is to start writing the minimal ad-hoc script and only gradually abstract over parts of it later to make it customizable and eventually turn it into a library if appropriate.
In B0/custom.ml
erase that silly print statement and start over by defining an empty build shell, made of a dummy build procedure and a function that produces build units invoking it.
open B00_kit.V000
open B00_std
open Fut.Syntax
open B00_memo
let exe_proc b =
let m = B0_build.memo b in
Memo.notify `Warn "Not building, yet.";
Fut.return ()
let exe ?doc ?meta ?action n =
B0_unit.v ?doc ?meta ?action n exe_proc
and in B0.ml
declare your unit:
let echo = Custom.exe "echo" ~doc:"A tool screaming in the void"
We now have a unit and a silly build procedure.
> b0 unit list [ ] echo A tool screaming in the void > b0 [WARN] [echo]: Not building, yet.