Building in Network-less Environment + Dune Env Issues

I’m currently trying to package my application that depends on many opam dependencies to an Ubuntu PPA. Importantly, Ubuntu PPA’s require sending source that are then built on their own machines to host on the PPA. These build environments however are network-less, thus making installing opam dependencies difficult.
I’ve observed that other ocaml-based applications include their opam dependencies in the Build-Depends so that they are included within os-level installations when building, but this can not be applied here because there are many opam dependencies that are not available in the official apt repositories, such as mrmime among others. To solve this, I have turned to a way to host the sources of necessary packages locally within the package, following the process of the shell script provided here:

This has been largely helpful, and am now able to compile all of the necessary opam dependencies in the networkless environment. However, there now appears to be an issue with dune:

opam exec --verbose --switch=opampack --root=/build/pkg_name-ver/opampack/opamroot -- dune build --root=/build/pkg_name-ver --no-config --verbose
Shared cache: disabled
Shared cache location: /nonexistent/.cache/dune/db
Workspace root: /build/pkg_name-ver
Auto-detected concurrency: 2
Dune context:
 { name = "default"
 ; kind = "default"
 ; profile = Dev
 ; merlin = true
 ; fdo_target_exe = None
 ; build_dir = In_build_dir "default"
 ; instrument_with = []
 }
File "opampack/opamroot/opampack/bin/dune", line 1, characters 0-0:
Error: Invalid dune file
make[1]: *** [debian/rules:42: pkg-opam-install] Error 1
make[1]: Leaving directory '/build/pkg_name-ver'
make: *** [debian/rules:6: build] Error 2
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

There is a dune and a dune-project within the project root directory and it appears that the opam exec command is working correctly because it is able to find the correct dune binary that was built.
I can’t make heads or tails of this error. It is currently informing me that the dune binary (found at opampack/opamroot/opampack/bin/dune) is an invalid dune file (which makes sense because it’s a binary) but it shouldn’t be searching there for a dune file. Rather, it should just be checking the current directory which does have a dune file.
Does anyone know how to fix this dune error or at least if I’m interpreting it incorrectly? Alternatively, is there a more elegant approach to packaging software with opam dependencies such that it builds in a network-less environment?

Can you name the dune executable something different? Eg dune.exe

1 Like