Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Per unit environment #7

Open
saagraa opened this issue Mar 3, 2021 · 0 comments
Open

Proposal: Per unit environment #7

saagraa opened this issue Mar 3, 2021 · 0 comments

Comments

@saagraa
Copy link

saagraa commented Mar 3, 2021

Usecase

(* Assume this exists *)
module Gen : sig
  val v : ?doc:string -> ?meta:B0_meta.t -> prog:B0_unit.t -> Fpath.t -> B0_unit.t
  val file : u : B0_srscs.sel
end

(* Compile this with Metaocaml. A metaocaml program that prints out regular ocaml code *)
let meta_gen = B0_ocaml.exe "meta_gen" ~srcs:[ `File (Fpath.v "some/source/file.ml")]

let gen_file = Gen.v ~prog:meta_gen Fpath.(v "gen_file.ml")

(* Compile this with normal Ocaml *)
let mylib = B0_ocaml.libname "mylib"
let mylib_lib = B0_ocaml.lib mylib ~srcs:[ Gen.file gen_file ]

Implementation

Based on my current understanding of how things work, this could be implemented in a few ways:

  1. Add an ~env argument to B0_ocaml.{lib,exe} They would then be responsible for passing those along to the tool spawns. The type should probably be something like (B0_build.t -> string String.Map.t) so that a tool spawn can generate the environment, such as a call to opam env
  2. Add an env key to the meta that gets passed to B0_ocaml.lib and B0_ocaml.exe. Again, B0_ocaml.{lib,exe} would be responsible for looking up that value and passing it to the tool spaws
  3. Add a wrapper around B0_unit.t to build that unit with a set of env vars. I'm not entirely clear how or if this would work, I need to look more that the unit definition/registration code.
  4. Probably some mechanism with B00_ocaml. From what I can tell, its only possible to mess with the environment from inside a (B0_build.t -> ...), and theres no mechanism to do that with the high level B0_ocaml.{lib,exe}

Or this is already possible and I completely missed it.

If you like any of these I could take a stab at implementing and submitting a pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant