commit c4893559a9514c47e08ba0d38b7788d24cc63936 Author: Glenn Date: Fri Oct 27 09:01:37 2023 +0200 Initial import diff --git a/_attic/setup.sh b/_attic/setup.sh new file mode 100755 index 0000000..4be833f --- /dev/null +++ b/_attic/setup.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +set -e +set -u + +PROJECT_NAME=crystal-builder +WORKDIR="/$PROJECT_NAME" + +CDATE="$(date --rfc-3339=seconds |head -c19 |sed -e 's/[-:]//g' -e 's/ /-/')" +CNAME="" +CID="" + +crun() { + name="$1" + base="$2" + CNAME="$name-$CDATE" + CID="$(docker run -it \ + --rm \ + --name "$CNAME" \ + --detach \ + -v "./:$WORKDIR" \ + -w "$WORKDIR" \ + "$base" \ + sleep infinity)" + if [ -z "$CID" ]; then + >&2 echo "ERROR: Unable to run $name container ($CNAME)" + exit 1 + fi + +} + +cclean() { + >&2 printf "INFO: Cleaning containers... " + docker kill "$CID" > /dev/null + echo "done" +} +trap "cclean" EXIT + + +## 0. Run base image + +## 1. Install the latest crystal release +## Ref. https://crystal-lang.org/install/ +crun step1 debian:12 +docker exec -it "$CID" sh "$WORKDIR/setup/step1.sh" +docker commit "$CID" "$PROJECT_NAME:step1" +cclean + +## 2. Make sure a supported LLVM version is present in the path +## (When possible, use the latest supported version) +crun step1 "$PROJECT_NAME:step1" +cclean + +## 3. Make sure to install all the required libraries. You might also want to read the contributing guide. + +## 4. Clone the repository: git clone https://github.com/crystal-lang/crystal + +## 5. Run make to build your own version of the compiler. + +## 6. Run make std_spec compiler_spec to ensure all specs pass, and you’ve installed everything correctly. + +## 7. Use bin/crystal to run your crystal files. + + + diff --git a/docker/Dockerfile.phase1 b/docker/Dockerfile.phase1 new file mode 100644 index 0000000..f841c6f --- /dev/null +++ b/docker/Dockerfile.phase1 @@ -0,0 +1,31 @@ +FROM debian:12 + +WORKDIR /setup + +## 1. Install the latest crystal release +## Ref. https://crystal-lang.org/install/ +COPY setup/step1.sh /setup/step1.sh +RUN sh /setup/step1.sh + +## 2. Make sure a supported LLVM version is present in the path +## (When possible, use the latest supported version) +COPY setup/step2.sh /setup/step2.sh +RUN sh /setup/step2.sh + +## 3. Make sure to install all the required libraries. You might also want to read the contributing guide. +COPY setup/step3.sh /setup/step3.sh +RUN sh /setup/step3.sh + +## 4. Clone the repository: git clone https://github.com/crystal-lang/crystal +COPY setup/step4.sh /setup/step4.sh +RUN sh /setup/step4.sh + +## 5. Run make to build your own version of the compiler. +COPY setup/step5.sh /setup/step5.sh + +## 6. Run make std_spec compiler_spec to ensure all specs pass, and you’ve installed everything correctly. + +## 7. Use bin/crystal to run your crystal files. + + + diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..eaa6a30 --- /dev/null +++ b/run.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +set -eu + +# Prebuild for target architecture +# FIXME: auto-configure arch + keep the build phase out of image + +CRYSTAL_VOLUME="$(docker volume list --format json |jq -r -s '.[] | select(.Name == "crystal") | try(.Name)')" +if [ -n "$CRYSTAL_VOLUME" ]; then + docker volume rm crystal +fi +docker volume create crystal + +## 1. Install the latest crystal release +## 2. Make sure a supported LLVM version is present in the path +## 3. Make sure to install all the required libraries. You might also want to read the contributing guide. +## 4. Clone the repository: git clone https://github.com/crystal-lang/crystal +docker build -t crystal-builder:phase1 --file docker/Dockerfile.phase1 ./ + +## 5. Run make to build your own version of the compiler. +docker run -it --rm --name crystal-builder \ + -v crystal:/crystal \ + crystal-builder:phase1 \ + sh /setup/step5.sh + +# 5bis. Compile Crystal project statically for target architecture +docker run \ + --rm \ + --privileged \ + multiarch/qemu-user-static \ + --reset -p yes + +INSTALL_CRYSTAL=" \ + sed -i -e 's/Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/debian.sources \ + && echo 'deb http://deb.debian.org/debian unstable main' > /etc/apt/sources.list.d/sid.list \ + && echo 'deb-src http://deb.debian.org/debian unstable main' >> /etc/apt/sources.list.d/sid.list \ + && apt-get update \ + && apt-get install -y \ + g++ \ + libxml2-dev \ + llvm-dev \ + make \ + libssl-dev \ + libpcre3-dev \ + libyaml-dev \ + zlib1g-dev \ + dpkg-dev \ + && apt source crystal \ + && apt build-dep crystal \ + && ls -lF \ +" + +BUILD_COMMAND="sleep 1" + +docker run \ + -it \ + -v "crystal:/crystal" \ + -w /crystal \ + --rm \ + --platform linux/arm64 \ + "arm64v8/debian" \ + /bin/sh -c "$INSTALL_CRYSTAL && $BUILD_COMMAND && bash" + +## 6. Run make std_spec compiler_spec to ensure all specs pass, and you’ve installed everything correctly. +## 7. Use bin/crystal to run your crystal files. diff --git a/setup/step1.sh b/setup/step1.sh new file mode 100644 index 0000000..6615d22 --- /dev/null +++ b/setup/step1.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -eu + +echo "==== STEP 1 : Installing crystal" +echo "---- Installing prerequisites" +apt-get update +apt-get install -y \ + curl \ + gnupg2 + +REPOSITORY="Debian_12" +echo "deb http://download.opensuse.org/repositories/devel:/languages:/crystal/$REPOSITORY/ /" \ + | tee /etc/apt/sources.list.d/crystal.list + +curl -fsSL "https://download.opensuse.org/repositories/devel:/languages:/crystal/$REPOSITORY/Release.key" \ + | gpg --dearmor \ + | tee /etc/apt/trusted.gpg.d/crystal.gpg > /dev/null + +apt-get update +apt-get install -y crystal=1.10.1-1+2.1 + diff --git a/setup/step2.sh b/setup/step2.sh new file mode 100644 index 0000000..22b0542 --- /dev/null +++ b/setup/step2.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -eu + +echo "==== STEP 2 : Installing crystal" +echo "---- Installing prerequisites" +apt-get update +apt-get install -y llvm-dev + diff --git a/setup/step3.sh b/setup/step3.sh new file mode 100644 index 0000000..dd7aceb --- /dev/null +++ b/setup/step3.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +echo "==== STEP 3 : Installing all the libraries" +echo "---- Installing prerequisites" +apt-get install -y \ + automake \ + build-essential \ + git \ + libbsd-dev \ + libedit-dev \ + libevent-dev \ + libgmp-dev \ + libgmpxx4ldbl \ + libpcre3-dev \ + libssl-dev \ + libtool \ + libxml2-dev \ + libyaml-dev \ + lld \ + llvm \ + llvm-dev\ + libz-dev + +echo "---- SUCCESS" diff --git a/setup/step4.sh b/setup/step4.sh new file mode 100644 index 0000000..6ce2031 --- /dev/null +++ b/setup/step4.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +echo "==== STEP 4 : Clone the repository" +echo "---- Installing prerequisites" +apt-get install -y \ + git + +echo "---- Git clone" +rm -fr /crystal/src +git clone https://github.com/crystal-lang/crystal /crystal/src + +echo "---- SUCCESS" diff --git a/setup/step5.sh b/setup/step5.sh new file mode 100644 index 0000000..36dff59 --- /dev/null +++ b/setup/step5.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +echo "==== STEP 5 : Build your own version" +echo "---- Installing prerequisites" +apt-get install -y \ + make + +echo "---- Running make" +cd /crystal/src +make progress=1 target=aarch64-unknown-linux-gnu | tee make.log + +echo "---- SUCCESS"