This seems like it should be obvious bug how do I have a conditional dependency in dune-project? Specifically I want to depend on a library but only on Unix-like systems:
(package
(name foo)
(depends
(linenoise (and (>= 1.1.0) (= %{os_type} "Unix")))))))))
That doesn't actually work because it is invalid syntax. The only examples of %{os_type} I found were for enabled_if which only can disable or enable an entire package. It doesn't work for dependencies apparently.
This is really easy in Rust; surely OCaml can do this?
1 Answer 1
What you want is this:
(package
(name foo)
(depends
(linenoise (and (>= 1.1.0) (= :os "linux")))))
OPAM will convert :os to a OCaml value by the same name os in the OPAM source code. This will be whatever OPAM thinks your operating system is. Note this value can be "" in some cases so be careful.