-
Notifications
You must be signed in to change notification settings - Fork 454
Closed
ocaml/opam-repository
#26975Labels
Description
In the docs, it is claimed that the field enabled_if behaves for executables the same as libraries. As of dune 3.15, enabled_if should allow to enable/disable a library (and therefore executable) based on environment variables.
Expected Behavior
Given a directory with
dune-project file:
(lang dune 3.15)
(name dune-test)
(package
(name dune-test))
dune file:
(executable
(name main)
(public_name dune_test)
(modules main)
(package dune-test)
(modes exe))
(executable
(name main_2)
(public_name dune_test_2)
(enabled_if (= %{env:MYVAR=disabled} enabled))
(modules main_2)
(package dune-test)
(modes exe))
and files main.ml and main_2.ml (omitted as irrelevant), running dune build should result in producing either main.exe, or both main.exe and main_2.exe, based on the value of $MYVAR.
Actual Behavior
dune build fails with the following error:
File "dune", line 11, characters 16-37:
11 | (enabled_if (= %{env:MYVAR=disabled} enabled))
^^^^^^^^^^^^^^^^^^^^^
Error: Only architecture, system, model, os_type, ccomp_type, profile,
ocaml_version, context_name and arch_sixtyfour variables are allowed in this
'enabled_if' field. Please upgrade your dune language to at least 3.15.
Note that dune-project already states (lang dune 3.15). Setting the language version to 3.16 results in the same error.
Also note that the same enabled_if expression has the desired effect if used on library.
Specifications
- Version of
dune: 3.16.0 - Version of
ocaml: 4.12.1 - Operating system: macOS 13.5.1, Darwin Kernel Version 22.6.0 arm64