Does anyone deploy Crystal app on ARM based linux server? what is the deployment process like?

I do, AWS Graviton2 (t4g) and Graviton3 (m7g) and some Ampere Altra (no, not the full machine with 80 cores, only small VMs part of the huge machine) :grin:

Lot of other hosting companies are starting to show offerings using Ampere Altra, so things looks promising in that front! :blush:

Since I still use Intel/AMD for development, I use my own container based on musl (Alpine Linux) to build static versions of the applications to deliver them.

For that, I combine Crystal + zig cc and the static version of the libraries needed for aarch64 and use crystal build --cross-compile.

There are a few caveats:

  1. If your app depends on OpenSSL, you need to be careful as it will try to use pkg-config and point to your local version of OpenSSL instead of the target one (trick is to set PKG_CONFIG_LIBDIR and point to the cross-compilation pkgconfig directory for aarch64.
  2. Even that compiles successufly, there might be issues with OpenSSL across distros, as it will not be able to find /etc/ssl/certs in some or find other issues. so far (:crossed_fingers: ) static musl runs without issues on Ubuntu 22.04 LTS
  3. Multi-threading is a bit flaky at this stage (-Dpreview_mt), I don’t have concrete examples, but encountered random errors that are hard to reproduce.

I showed a little bit of this in a few videos here and here.

I’ve also prepacked a list of dependencies in magic-haversack repository, so you only need to download, extract and then combine with your local Crystal and zig compiler to produce those static binaries targeting aarch64-linux-musl.

I was hoping to do part 3 showing automated cross-compilation using GitHub Actions but got a bit trickier to generate MacOS binaries (due MacOSX SDK version mismatch). More to come on that at some point :sweat_smile:

Enjoy!

7 Likes