ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 397 forks source link

env not supported in enabled_if Boolean language in library stanza #7571

Open alan-j-hu opened 1 year ago

alan-j-hu commented 1 year ago

The following code I want to write is not supported:

(library
  (name llvm_shared)
  (public_name llvm.shared)
  (implements llvm)
  (enabled_if %{env:LLVM_SHARED_AVAILABLE=false})
  (foreign_stubs
   (language c)
   (names llvm_ocaml))
  (c_library_flags (:include c_library_flags.sexp)))

The error message I get is

Error: Only architecture, system, model, os_type, ccomp_type, profile,
ocaml_version and context_name variables are allowed in this 'enabled_if'
field. If you think that env should also be allowed, please file an issue
about it.

The documentation just lists variables that are supported in general and variables that are not supported in general but supported in action stanzas. env:<var>=<default> is listed as a variable supported in general. So, there's either a bug in Dune or the Dune documentation is wrong.

Also, the error message mentions the ccomp_type variable, which isn't even in the documentation.

What I'm ultimately trying to do might be an XY problem, but in any case, in this specific situation, the documentation and behavior don't match.

Alizter commented 1 year ago

What you have written there is not a boolean comparison which is why enabled_if is rejecting it. I agree that the error message is poor. What you need to do is something like this:

 (enabled_if
  (= %{env:DUNE_COQ_TEST=disable} enable)))

The equality inside %{env:} is just a default value.

alan-j-hu commented 1 year ago

No, the following also doesn't work:

(library
  (name llvm_shared)
  (public_name llvm.shared)
  (implements llvm)
  (enabled_if (= %{env:LLVM_SHARED_AVAILABLE=false} true))
  (foreign_stubs
   (language c)
   (names llvm_ocaml))
  (c_library_flags (:include c_library_flags.sexp)))