Ppx_getenv, dune compatible alternative?

Dear All,

I have a dune-based build. I want to do optional compilation based on the value of an environment variable. I would like to use ppx_optcomp. However, I can’t see how to make compilation depend on an env var.

There is ppx_getenv https://github.com/ocaml-ppx/ppx_getenv, but this doesn’t seem to work with dune.

Does anyone have any suggestions?

The particular use case is that I want to enable/disable profiling based on an env var, and it is important to me that I can disable at compile time in order that profiling does not affect non-profiled performance.

I would suggest to send a PR to ppx_optcomp to read the unix environment at condition-evaluation time. For example you could add a new optcomp-time function env_has(var, val) that checks if the variable var is defined in the environment and equal to val, or getenv_or(var, default) – or add support for option types in the interpreter and return a string option to handle undefined variables (more work…).

In any case, I expect that most of the action would be in
https://github.com/janestreet/ppx_optcomp/blob/master/src/interpreter.ml

OK. Thanks.

Request here: