Initial import

This commit is contained in:
Glenn Y. Rolland 2023-10-27 09:01:37 +02:00
commit c4893559a9
8 changed files with 246 additions and 0 deletions

65
_attic/setup.sh Executable file
View file

@ -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 youve installed everything correctly.
## 7. Use bin/crystal to run your crystal files.

31
docker/Dockerfile.phase1 Normal file
View file

@ -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 youve installed everything correctly.
## 7. Use bin/crystal to run your crystal files.

65
run.sh Executable file
View file

@ -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 youve installed everything correctly.
## 7. Use bin/crystal to run your crystal files.

22
setup/step1.sh Normal file
View file

@ -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

9
setup/step2.sh Normal file
View file

@ -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

26
setup/step3.sh Normal file
View file

@ -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"

14
setup/step4.sh Normal file
View file

@ -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"

14
setup/step5.sh Normal file
View file

@ -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"