Skip to content

Allow more variables for enabled_if #4455

@toots

Description

@toots

enabled_if is currently pretty limited. In particular, it is not possible to enable a library depending on run-time configuration as, for instance, determined by dune-configurator.

In the case at hand, we want to optionally compile a library that implements support for OSS sound output. We have this configuration binary:

module C = Configurator.V1

let oss_test = {|
#include <sys/soundcard.h>

int main() {
   return 0;
}
|}

let () =
  C.main ~name:"liquidsoap" (fun c ->
      let oc = open_out "oss_enabled" in
      output_string oc (string_of_bool (C.c_test oss_test));
      close_out oc)

Then this dune configuration:

(library
 (name liquidsoap_oss)
 (libraries liquidsoap_core)
 (enabled_if (= "true" %{read:oss_enabled}))
 (library_flags -linkall)
 (optional)
 (foreign_stubs
  (language c)
  (names oss_io_c))
 (modules oss_io))

But this is currently impossible:

File "src/lib/dune", line 472, characters 25-42:
472 |  (enabled_if (= "true" %{read:oss_enabled}))
                               ^^^^^^^^^^^^^^^^^
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 read should also be allowed, please file an issue
about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions