Skip to content

Instantly share code, notes, and snippets.

@j8r
Last active October 13, 2024 08:40
Show Gist options
  • Save j8r/34f1a344336901960c787517b5b6d616 to your computer and use it in GitHub Desktop.
Save j8r/34f1a344336901960c787517b5b6d616 to your computer and use it in GitHub Desktop.
Compile a Crystal program to a statically linked arm64 binary
#!/bin/sh -eu
LOCAL_PROJECT_PATH=${1-$PWD}
BUILD_COMMAND="
shards build --static --release
chown 1000:1000 -R bin
"
INSTALL_CRYSTAL="
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >>/etc/apk/repositories
apk add --update --no-cache --force-overwrite \
crystal@edge \
g++ \
gc-dev \
libxml2-dev \
llvm10-dev \
llvm10-static \
make \
musl-dev \
openssl-dev \
openssl-libs-static \
pcre-dev \
shards@edge \
yaml-dev \
yaml-static \
zlib-dev \
zlib-static
"
# Compile Crystal project statically for arm64 (aarch64)
docker pull multiarch/qemu-user-static:register
docker run --rm --privileged multiarch/qemu-user-static:register --reset
docker run -it -v $LOCAL_PROJECT_PATH:/app -w /app --rm multiarch/alpine:aarch64-edge /bin/sh -c "$INSTALL_CRYSTAL; $BUILD_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment