Dune build error on macOS

May I ask the Dune experts for assistance in tackling a build error on macOS. After a large commit, my project stopped building with the following error:

File "appkit/dune", line 1, characters 0-82:
1 | (library
2 |  (name appkit)
3 |  (public_name camlkit-gui.appkit)
4 |  (libraries foundation))
ar: @/var/folders/8d/j95p9rj549l7f42l5m7qxp500000gn/T/build_415557_dune/camlresp05230a: No such file or directory
File "_none_", line 1:
Error: Error while creating the library appkit/appkit.a

Same on two different Macs: Intel and Arm. But it builds on Linux (with the GNUstep library as a dependency). The build artifact is quite large (48M), so maybe I’m hitting a resource limit on macOS.
Here’s a link to the project: GitHub - dboris/camlkit: OCaml bindings to macOS Cocoa frameworks

Heads up to the Dune developers: after trimming down the bindings the project builds again with the library archive size ~25M. Looks like there is a Dune limit I have hit that manifests on macOS.

Note that if you are generating stuff it may not be dune but a compiler limit, as it accepts only reasonably generated sources. You should try to dig out the build logs and/or tell us if you are generating unwiedely stuff.

You are right. I found in the log a very long line calling ocamlopt.opt. It is 72K when saved as a file. Possibly the compiler has a limit which is different on macOS and Linux.

This is a bit cryptic and I’m a bit wild guessing but it looks like the compiler is calling ar with a response file that it failed to generate.

I’ve shared the line from the dune log that probably breaks ocamlopt here.

You can try to cut an paste that build invocation and add -verbose after ocamlopt.opt it shows the subtools it invokes.

(But probabely there’s too much stuff to ar here).

At least we got a ballpark estimate. Up to about 1000 modules compile fine. Above 1K, there is a problem, at least on macOS.

I stumbled on this issue by chance which seems related to your issue. I didn’t have the time to look at the resolution but you might dig something out of it.

1 Like

Thanks, that seems to be the issue. Pinging @nojb

Thanks for the ping. I confirm, that’s the issue. Unfortunately, the fix is only available in OCaml >= 5.1 if memory serves.

Cheers,
Nicolas

I was hitting it too with ocaml-terraform bindings (due to large amount of generated code) and the workaround is too use llvm-ar which supports response files.

1 Like

@andreypopp How did you set this up in dune?

just put a symlink to llvm-ar somewhere on PATH and have it named ar, for example

ln -s /opt/homebrew/Cellar/llvm/17.0.6_1/bin/llvm-ar $OPAM_SWITCH_PREFIX/bin/ar

so it’s not really in dune.

Please don’t show these things :–)

We already have enough bug reports in opam with people showing up with weird setups that have a mixture of C compilers installed in their environment which breaks everything.

I can confirm that this workaround works. It might be okey during development, but it’s not a sustainable solution if you plan to release your library. I ended up splitting my large library into two small ones instead.