Is it possible to refer to the current display mode in a dune rule?

A subdirectory of my dune project contains C++ code that is compiled through cmake. This can be done easily via a custom rule, and I can translate dune’s profile into cmake’s BUILD_TYPE with an appropriate env stanza, as in:

(env
 (dev (env-vars (CMAKE_BUILD_TYPE "Debug")))
 (release (env-vars (CMAKE_BUILD_TYPE "Release")))
)

(data_only_dirs my_cxx_dir)

(rule
  (deps
    (source_tree my_cxx_dir)
  )
  (targets my_cxx_lib.so)
  (action
    (no-infer
      (progn
        (echo "C++ build setup" "\n")
        (run cmake -S my_cxx_dir -B build -DCMAKE_BUILD_TYPE=%{env:CMAKE_BUILD_TYPE=Release})
        (echo "Generating clang plugin and demangler" "\n")
        (run cmake --build build)
        (copy my_cxx_dir/my_cxx_lib.so my_cxx_lib.so)
      )
    )
  )
)

However, I’d like to set a VERBOSE environment variable for the cmake runs if dune display mode is itself verbose, in order to see the actual options given to the C++ compiler. I could of course set another profile for that, but this has some drawbacks:

  • I would in fact need two profiles, dev-verbose and release-verbose
  • I’d prefer not having to write dune build --profile dev-verbose --display verbose

Thus, I’d like to know if it’s possible to set an environment variable in a user action conditionally on the chosen display mode. I haven’t found anything in dune’s documentation yet.

No, this is not currently possible.

Cheers,
Nicolas

OK, thanks for the confirmation. Would it make sense to open a feature request on github?

I think so. It won’t necessarily be added to Dune, but that way the use-case will at least be known to Dune’s devs.

Cheers,
Nicolas

Done here. Thanks again for your answer.

1 Like