# Building for MacOS x86 and arm64 with setup-ocaml

**URL:** <https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257>\
**Category:** Ecosystem\
**Created:** [March 6, 2024, 4:11pm UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257 "2024-03-06T16:11:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grayswandyr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grayswandyr/32/94_2.png) [@grayswandyr](https://discuss.ocaml.org/u/grayswandyr)\
**Post date:** [March 6, 2024, 4:11pm UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257/1 "2024-03-06T16:11:38Z")

</div>

Owning solely a GNU/Linux machine, I currently build an executable for Linux x86-64, Windows and MacOS x86 using the [setup-ocaml GH CI facility](https://github.com/grayswandyr/electrod/blob/master/.github/workflows/binaries.yml) (many thanks to its authors). (To be able to build on all 3 platforms, I had to fix the version of packages in a way that works on all of them, which was a bit tedious and took some time, btw).

Users of my program who own a Mac M1/M2/M3 apparently can’t run the program. Is there a way to add MacOS arm64 as a 4th target?

---

<div class="post-metadata">

**Author:** ![lambda\_foo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lambda_foo/32/275_2.png) [@lambda\_foo](https://discuss.ocaml.org/u/lambda_foo)\
**Post date:** [March 6, 2024, 4:26pm UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257/2 "2024-03-06T16:26:01Z")

</div>

If you use `macos-14` you will pickup an ARM64/M1 worker. Confusingly `macos-latest` is x86\_64

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grayswandyr/32/94_2.png) [@grayswandyr](https://discuss.ocaml.org/u/grayswandyr)\
**Post date:** [March 6, 2024, 6:52pm UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257/3 "2024-03-06T18:52:10Z")

</div>

Thanks it works !  
Tiebreaker question: it seems like there also exists a possibility of “universal” binary for MacOS. Provided it’s the case, is there a way to build one with a MacOS target in setup-ocaml?

---

<div class="post-metadata">

**Author:** ![lambda\_foo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lambda_foo/32/275_2.png) [@lambda\_foo](https://discuss.ocaml.org/u/lambda_foo)\
**Post date:** [March 7, 2024, 8:06am UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257/4 "2024-03-07T08:06:08Z")

</div>

Not easily, it would require OCaml cross compilation to emit the x86/arm64 OCaml assembly.

---

<div class="post-metadata">

**Author:** ![WardBrian](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/wardbrian/32/3971_2.png) [@WardBrian](https://discuss.ocaml.org/u/WardBrian)\
**Post date:** [January 2, 2025, 8:23pm UTC](https://discuss.ocaml.org/t/building-for-macos-x86-and-arm64-with-setup-ocaml/14257/5 "2025-01-02T20:23:44Z")

</div>

> [@grayswandyr](#):
>
> Tiebreaker question: it seems like there also exists a possibility of “universal” binary for MacOS. Provided it’s the case, is there a way to build one with a MacOS target in setup-ocaml?

This thread seems to be at the top of search results for “ocaml universal binary”, so forgive the late bump.

I was recently looking into this question. It turns out this is relatively easy using [the `lipo` tool Apple provides](https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary#Update-the-Architecture-List-of-Custom-Makefiles) and something like github actions where you have access to multiple machines:

1. Build on an Intel Mac (github actions still has these under the `macos-13` label). Upload an artifact of the executable
2. Build on a Apple Silicon mac (gh actions `macos-14` or `macos-latest`). Upload an artifact of this executable
3. Now, on an Apple Silcon instance, download those artifacts and then run the `lipo` tool to combine the two. You now have a universal/fat binary, without ever needing to run a cross compiler
