Dune rule depending on profile


I’m wondering whether it’s possible to have a dune stanza or rule depend on the profile being used.

The use case is as follows: I want to introduce some automatic checks in my build process when using the dev profile. However, I want to disable them when distributing the software (with opam and the release profile).

I may have missed it, but I could not find any hint to achieve this in the dune documentation.

Thanks for your help,

The simplest way is to check for the profile in the action that does your check:

 (alias check) ;; or whatever alias you have here
 (deps (universe)) ;; specify your dependencies correctly here
 (action (run checker %{profille})))

Then checker should do nothing if %{profile} is dev.

Thanks for the hint.

Actually, the check I’m currently using is itself implemented as an alias. I missed it, but the alias stanza accepts a enabled_if optional field.

So I think I succeeded in implementing what I was looking for as follows:

  (targets my_target_file)
     (alias my_check)
 (action <some_action>)

  (name my_check)
  (enable_if (= %{profile} dev))
  (action <whatever-action>)

AFAICT, when using the release profile, the my_check alias is simply not run.

It even seems that the enabled_if optional field is also available for the rule stanza since 1.4 (this feature does not seem to appear in the documentation, so I don’t know whether it is stable).