Hello,
I’m trying to improve the portability of our Dune-based tool, which currently relies heavily on using Unix-like commands here and there, for instance:
(action (with-stdout-to config.ml (run sed -f config.sed config.ml.in)))
This action reads the content of a previously-produced file with sed commands (config.sed
), then applies them to a config.ml.in
file (which contains patterns in the form of @FOO@
, to be replaced by the sed
commands), producing a valid config.ml
file in the end, that is then compiled by Dune along with the rest of the code.
Obviously, this does not work as-is from Windows, since sed
does not exist (at least in my PowerShell-based setup).
In such cases, what is the recommended way to proceed in order to maximize portability among OSes? Here are a few possibilities I’ve considered:
- Write a mini sed-like tool in OCaml, use Dune to build it, then run it (maximally portable and flexible for our needs, but may require a lot of extra coding, and wheel-reinventing);
- Use the existing
sed.exe
from the opam-managed Cygwin installation (I’m not sure how to do it, that is, how to find its path and reference it from within the Dune file, and if there are cases where such an installation will not be available); - Require that the user sets up some environment variables (e.g.
$env:SED='path-to-sed.exe'
on PowerShell, andSED=/usr/bin/sed
on Unix) before runningdune build
(this seems equivalent to running amake
or./configure
script, so I’m not convinced this is a good idea).
If necessary, we can assume that users will follow our installation instructions, so if we tell them e.g. “use a PowerShell-based setup with a Cygwin managed by opam”, they will comply. So we can limit the different setups that we need to handle. This likely diminishes portability, but if it can keep things simpler, it’s fine for us.
Do you have any comments/experience on these approaches, or suggestions of a better way to ensure that such code can be built with Dune on Linux, macOS and Windows?