rescript-logger icon indicating copy to clipboard operation
rescript-logger copied to clipboard

Question: ppx arm64 on linux? (needed for docker on M1/M2 Mac)

Open reebalazs opened this issue 1 year ago • 9 comments

Hi, just upfront I'd like to say I really love this product, thanks for all the work you're putting into it.

Recently I started to dockerize an app, and realized that on an OSX M1/M2, I cannot compile the app with rescript inside a docker container.

The changelog says that in v4 the arm64 linux compiler is removed, so this is expected. By the way, I also fail to compile with v3 for different reason (complains about ninja.exe, I tried both in alpine and debian based containers and failed with both).

That said, I can live with this, as the most important thing is to compile on the target machine which is x64, and this is working. However for development and other purposes, it would be useful if I could build the docker image locally. So I wonder if this could be achieved somehow.

  • the arm64 linux target could be put back and supported again in a working way? All other ppx packages that my app depends on, work for me by the way.
  • maybe there is another way to successfully compile on arm64 linux? and if yes, maybe you can give me a hint how this is possible?

Thanks for your reply in advance!

reebalazs avatar Jun 07 '24 05:06 reebalazs

Ping again, as there has been no reply.

Would it be possible to create a rescript-logger-ppx-linux-arm64.exe binary?

reebalazs avatar Jan 10 '25 08:01 reebalazs

@reebalazs Sorry, I missed this issue. I removed this binary because it was too much of a hassle to maintain it. IIRC to make a release, I had to spin up EC2 instance, pull the repo, build the binary, copy it from the instance, and do the release.

Here is the script: https://github.com/shakacode/rescript-logger/blob/97b6027feb3285b112902b16db96f176da1176dd/scripts/build-linux-arm64.sh

I will happily add it back if CI supports this arch. I'm not sure if GitHub Actions added it or not.

alex35mil avatar Jan 10 '25 08:01 alex35mil

@alex35mil ah ok, great, thank you! I just did a quick research and I found https://github.com/actions/runner-images/issues/10820#issuecomment-2457197822 , according to this, it will land to the free plans in Q1 2025, so maybe soon-ish, but it's already available on Team accounts as of now.

reebalazs avatar Jan 10 '25 09:01 reebalazs

@reebalazs We're on some legacy plan atm. Not sure if it's available for us or not. It should be a matter of adding the runner to this matrix to check it. AFAICT it shouldn't require docker image update.

alex35mil avatar Jan 10 '25 09:01 alex35mil

@alex35mil I'm tempted to give it a try. Not sure when exactly though. I'll let you know if I have any success!

reebalazs avatar Jan 10 '25 13:01 reebalazs

@reebalazs I think you can try to add arm64 runner to the linked matrix and submit a pr. I can try it out some time next week.

alex35mil avatar Jan 10 '25 13:01 alex35mil

@alex35mil It seems that there is no arm64 linux runner available currently. The followings would be workarounds:

  • there are partner images available which could be used in self-hosted github plans (I don't want to try that)
  • one could use the macos arm64 runner, install docker (as the macos runner does not include docker), then move the entire build to the dockerfile (which means losing all the github actions), then when it's done with the build, take out the artifact from the container and use it to move forward.

I'm trying the docker solution now, which could work. I'll PR when done.

Somewhat confusing for me, that @greenlabs/ppx-spice only produces 3 exes (win, mac and linux), and it does seem to work in a linux arm64 container, so I wonder why is that working for spice without doing an arm64 linux build. But maybe I'm misunderstanding something.

reebalazs avatar Jan 11 '25 10:01 reebalazs

Done with the PR #43 , I've also tested it out. With a few caveats:

  • Your docker image should be used, but it needs to be built for the linux/arm64 platform, which it currently isn’t. As a workaround, I’m using the Alpine Node image and installing OCaml into it—whether that’s ideal or not.
  • The yarn cache is not handled (could be copied out of the container at the end of the build too...)
  • The lack of docker on the macos runners is a PITA and is the major cause for most of our problems. Installing docker is painful. It only seems to work with macos-13 and not with macos-14 which is fine for us. It takes about 5 minutes to set up docker, lol :)

In the end, I finally realized why ppx-spice can use the x64 image on arm64 processors—thanks to Rosetta! We could have simply added three lines to postinstall.js instead of building an arm64-specific version of the ppx. After all, requiring Rosetta is reasonable since most developers already have it installed. In that case, my efforts wouldn’t have been necessary… But hey, we now have the arm64 build!

reebalazs avatar Jan 11 '25 20:01 reebalazs

@alex35mil I've updated #43 with the now-public 'ubuntu-24.04-arm` runner. This makes things simpler than in the first version of my PR that still had to use a dockerfile for the build. :)

Also left more notes there. Most notably. I'd need you to build the alex35mil/alpine-ocaml-opam-node-yarn:alpine-3.19-ocaml-4.14-node-16.20-yarn-1.22-o5gm image also for platform linux/arm64/v8 . There is also an unrelated problem in the validate job that I had to work around.

reebalazs avatar Jan 19 '25 09:01 reebalazs