OCaml for ARM MacOS

,

I think it’s possible to use Corellium iPhone emulation for development. Many projects and researchers rely on it. For example, Go language uses it for CI.

Another alternative is to run iOS in QEMU as it had been told already:

They published the source code at GitHub:

Hope that helps.

1 Like

At the platform state of the union, they announced that they will send Pr for the Mac ARM support to many oss projects.

Would be nice to find a way to have OCaml on the list

2 Likes

10 days? :innocent: The OCaml ARM64 code generator is in very good shape already, and the recent pull request Add support to iOS / Mac ARM64 by EduardoRFS · Pull Request #9699 · ocaml/ocaml · GitHub adds iOS ARM64 support, which should not be very far from macOS ARM64 support.

However, I would really like to have SSH access to one of those MacMini ARM64 development platforms. That would speed up porting and testing tremendously. Emulators and jailbreaked phones are a pain.

17 Likes

I don’t have such a box, so I can only ask around on Twitter — feel free to retweet for reach or make a better tweet https://twitter.com/Blaisorblade/status/1275840699477434369

1 Like

So, while we’re on the topic of ARM, android also uses ARM. How hard is it to produce binaries for that as well?

If someone started a crowdfunding compain to get the box I would definitely back it.

5 Likes

@bluddy not hard, Android needs some patches after Android 5.0, I have it setup for ARM64 and x86_64 at my personal project, also got iOS x86_64 and ARM64.

I have a tooling to cross compile almost anything with esy, similar to ocaml-cross but more versatile and works with essentially any dune package not using cstubs(you need a patch for that). It was working with OCaml 4.08

The patches itself, not great yet, but will open a PR in the future. Also I want to get x86 PIC to work(Android requires that), which is a lot harder than iOS and Android ARM.

5 Likes

The emulator after you get to work is actually nice, works exactly like any VM, SSH and all, if you guys are okay with that I can setup the CI using it.

But also, maybe trying to give Corellium a try? I’m not a huge fan o Go but if they’re using as a CI it’s probably reliable.

Technically even the ABI of the mac ARM is the same as iOS so I would bet 99% is similar, probably same linker, same kernel. But would be great to have the real thing running as there is a lot of small limitations(like stack_size)

3 Likes

By the way, just an update from Aleph Security - they added KVM acceleration for iOS emulation if it’s running on ARMv8 board: https://alephsecurity.com/2020/07/19/xnu-qemu-kvm/

1 Like

That’s amazing, I had started to look on that, but not a lot of spare time, will try to see if it can runs the macOS ARM, as the kernel is really similar

News, now that M1 is out?

OCaml 4.12 will have full native code macOS/ARM support. The first alpha is due out any day now, and the ecosystem tools will be ready on the day of its release as well, thanks to the OCaml readiness team’s efforts

13 Likes

@Blaisorblade currently with my backport to OCaml 4.10 everything is working, a couple of months ago I did bootstrap opam using it.

This one,

2 Likes

@EduardoRFS that’s very useful indeed! If you’re able to open a PR against ocaml/ocaml's branch 4.10 with just the code generator backport (and not the iOS-related changes), that would be useful for Homebrew’s macOS OCaml for a month or so until we get 4.12.0 out of the door.

I don’t have a lot of spare time right know, but I opened the PR, left the iOS changes as they’re quite small and I don’t have a macOS ARM box to test right know.

But backporting to 4.11 is easier, as there is no conflict, if you want to try is the same 3 commits on this PR

2 Likes

OCaml 4.12 from trunk builds fine on ARM macOS for me, and I can build all my software, including mixed C/OCaml DLLs and other exotic things.

For those interested in timings, “make -j9 world.opt” for OCaml runs in 1m6s.

8 Likes

I’ve never built ocaml or opam from source. Do you think you can give me the idiot-proof guide for getting this up an running on my ARM-based mac?

This might help
Opam: Release 2.0.7 · ocaml/opam · GitHub

And latest release of Ocaml 4.10 and the beta 4.12 has support for MacOSX/Arm64

It’s quite easy to get up to speed using the precompiled OPAM binary for macOS/ARM64.

  • Download opam-2.0.7-arm64-macos.

  • Move it to some directory in your PATH, rename it to opam, and make it executable. From a Terminal window:

mv ~/Downloads/opam-2.0.7-arm64-macos /usr/local/bin/opam
chmod +x /usr/local/bin/opam
  • Try to execute it: opam init. You will be blocked by the macOS security checks, as the binary is not signed.

  • Open Preferences / Security and Privacy. There should be a notice “opam was blocked because…” and an “Allow Anyway” button. Click on that button.

  • Try again to execute opam init. You will be blocked again, but now there is an “Open” button. Click on that button. opam init should run and install the OCaml 4.10.2 compiler.

  • From now on, you can run opam without being blocked. Use this freedom to opam install the packages you need.

  • Some packages that depend on external C libraries may fail to install because these C libraries are not available. Normally we would rely on Homebrew or MacPorts to provide these C libraries, but these package collections are still being ported to macOS/ARM64.

As a reward for these minor inconveniences, you’ll get excellent performance running OCaml software such as Coq. Single-core performance on a MacBook Air M1 is 20% better than the best x86 workstation I have access to.

16 Likes

I noticed that opam 2.08 is now available for ARM Macs using Homebrew, and I was able to confirm on my machine.

brew install opam away :slight_smile:

5 Likes