Distributing OCaml binaries for MacOS

Hello!

I have a question: how do you distribute OCaml binaries for MacOS?

Until now, I’ve used GitHub Actions to build a binary on a Mac machine, and then just distribute that. (Just like this topic suggests)
But apparently, it’s linking against some HOMEBREW libraries. Some user might not have them, some users might have them installed elsewhere… (See for instance this issue).

Do you just put the homebrew installation as a prerequesite?
Or do you manage to static link in Mac (I haven’t had success in this despite some nice help, but I’m a beginner in this. If you know how to do this, that would be great!)

Thanks in advance!

1 Like

Hi :slightly_smiling_face:

OSnap does build a statically linked binary for mac. As far as I remember, you have to tell dune to link to the static libraries (.a files). OSnap does this with libspng and libz here: OSnap/lib/OSnap_Diff/config/discover.ml at master · eWert-Online/OSnap · GitHub. This produces link flags which you can then use in dune files: OSnap/lib/OSnap_Diff/png/dune at master · eWert-Online/OSnap · GitHub (You need dune-configurator for that)

Hope that helps :slightly_smiling_face:

2 Likes

Thanks a lot! Yes, that does help :slight_smile:

See my, and others’ comments here for some more advice:

1 Like

If you are interested in building universal or ‘fat’ binaries, this other thread may be useful as well:

1 Like

@eWert-Online I tried something similar to your example (passing -cclib <path to .a>) but the homebrew dynamic library is still picked, according to otool… I’ll continue to try to understand why.

Thanks @WardBrian and @JohnWhitington for your help too!

Actually, I’m fine with anything that is easy to install for mac users, reliable and low-effort for me. I’m always surprised how difficult distributing binaries is!
I’ll look into your suggestion but it seems it’s bundling two binaries for two architecture. If those binaries depend on Homebrew libraries that are not installed (or not at the expected path), I’ll still have the same problem.

Thanks! I’m not familiar with what are XCode, SDK, but this also seems to be about running on old OS, not ditching Homebrew requirement. Interesting though!