Skip to content

Commit

Permalink
Refactor building of release runtimes
Browse files Browse the repository at this point in the history
This might still fail (sadly we can only figure that out by pushing the
changes), but it should hopefully resolve cross-compilation of the
runtime now requiring a full C toolchain due to the ring dependency.

Since Fedora doesn't provide cross-compilation toolchains for userspace,
we have to use Debian. Debian in turn doesn't allow installing musl for
AMD64 and ARM64 in parallel, so we need two different images.
  • Loading branch information
yorickpeterse committed Aug 14, 2024
1 parent 54e754d commit a2fd9c7
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 107 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ jobs:
uses: ./.github/workflows/container.yml
with:
name: 'fedora'
debian-amd64:
uses: ./.github/workflows/container.yml
with:
name: 'debian-amd64'
debian-arm64:
uses: ./.github/workflows/container.yml
with:
name: 'debian-arm64'
14 changes: 1 addition & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,7 @@ jobs:

runtimes:
name: Runtimes
runs-on: ubuntu-latest
container:
image: ghcr.io/inko-lang/ci:fedora
needs:
- tests
env:
RCLONE_S3_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_ACCESS_KEY_ID }}
RCLONE_S3_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }}
RCLONE_S3_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
steps:
- uses: actions/checkout@v4
- name: Upload runtimes
run: make runtimes
uses: ./.github/workflows/runtimes.yml

docs:
name: Documentation
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/runtimes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
name: Build runtimes
on:
workflow_call:
workflow_dispatch:

env:
CARGO_HOME: ${{ github.workspace }}/.cargo-home
# We set an explicit version to only install the components we need for CI.
RUSTUP_TOOLCHAIN: '1.78'

jobs:
linux-amd64:
name: Linux AMD64
runs-on: ubuntu-latest
container:
image: ghcr.io/inko-lang/ci:debian-amd64
steps:
- uses: actions/checkout@v4
- name: Build runtimes
run: bash ci/runtimes.sh amd64-linux
- uses: actions/upload-artifact@v4
with:
name: amd64-linux
path: tmp/runtimes/${{ github.ref_name }}/*.tar.gz
overwrite: true
retention-days: 2
compression-level: 0

linux-arm64:
name: Linux ARM64
runs-on: ubuntu-latest
container:
image: ghcr.io/inko-lang/ci:debian-arm64
steps:
- uses: actions/checkout@v4
- name: Build runtimes
run: bash ci/runtimes.sh arm64-linux
- uses: actions/upload-artifact@v4
with:
name: arm64-linux
path: tmp/runtimes/${{ github.ref_name }}/*.tar.gz
overwrite: true
retention-days: 2
compression-level: 0

macos-amd64:
name: macOS AMD64
runs-on: macos-12
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: ./ci/mac.sh
- name: Build runtimes
run: bash ci/runtimes.sh amd64-mac
- uses: actions/upload-artifact@v4
with:
name: amd64-mac
path: tmp/runtimes/${{ github.ref_name }}/*.tar.gz
overwrite: true
retention-days: 2
compression-level: 0

macos-arm64:
name: macOS ARM64
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: ./ci/mac.sh
- name: Build runtimes
run: bash ci/runtimes.sh arm64-mac
- uses: actions/upload-artifact@v4
with:
name: arm64-mac
path: tmp/runtimes/${{ github.ref_name }}/*.tar.gz
overwrite: true
retention-days: 2
compression-level: 0

freebsd-amd64:
name: FreeBSD AMD64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build runtimes
uses: cross-platform-actions/[email protected]
with:
operating_system: freebsd
version: '14.0'
memory: 8G
environment_variables: 'CARGO_HOME RUSTUP_HOME'
image_url: 'https://github.com/inko-lang/freebsd-builder/releases/download/v0.8.0/freebsd-14.0-x86-64.qcow2'
run: bash ci/runtimes.sh amd64-freebsd
- uses: actions/upload-artifact@v4
with:
name: amd64-freebsd
path: tmp/runtimes/${{ github.ref_name }}/*.tar.gz
overwrite: true
retention-days: 2
compression-level: 0

upload:
name: Upload runtimes
runs-on: ubuntu-latest
container:
image: ghcr.io/inko-lang/ci:fedora
env:
RCLONE_S3_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_ACCESS_KEY_ID }}
RCLONE_S3_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }}
RCLONE_S3_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
needs:
- linux-amd64
- linux-arm64
- macos-amd64
- macos-arm64
- freebsd-amd64
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: tmp/runtimes
merge-multiple: true
- name: Upload runtimes
run: rclone sync --dry-run --config rclone.conf --checksum --verbose tmp/runtimes "production:inko-releases/runtimes/${{ github.ref_name }}"
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,8 @@ std-docs/publish: std-docs/build
rclone sync --config rclone.conf --checksum --verbose \
std/build/idoc/public "production:${DOCS_BUCKET}/std/${DOCS_REF}"

runtimes:
bash scripts/runtimes.sh ${VERSION}

.PHONY: release/source release/manifest release/changelog release/versions
.PHONY: release/commit release/publish release/tag
.PHONY: build install clean runtimes
.PHONY: build install clean
.PHONY: docs/setup docs/build docs/watch docs/publish
.PHONY: std-docs/build std-docs/publish
25 changes: 25 additions & 0 deletions ci/docker/debian-amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM debian:12

ENV LLVM_VERSION 17
ENV RUST_VERSION 1.78

ENV PATH /opt/cargo/bin:$PATH
ENV CARGO_HOME /opt/cargo
ENV RUSTUP_HOME /opt/rustup

RUN apt update --quiet && apt install --quiet --yes curl build-essential tar git
RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
RUN /usr/bin/echo -e "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-$LLVM_VERSION main" \
> /etc/apt/sources.list.d/llvm$LLVM_VERSION.list

RUN apt update --quiet && apt install --quiet --yes \
llvm-$LLVM_VERSION llvm-$LLVM_VERSION-dev \
libstdc++-11-dev libclang-common-$LLVM_VERSION-dev zlib1g-dev \
libpolly-$LLVM_VERSION-dev libzstd-dev

RUN curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location \
--silent --show-error --fail "https://sh.rustup.rs" | \
sh -s -- --quiet -y --no-modify-path --profile minimal \
--component clippy,rustfmt --default-toolchain $RUST_VERSION

RUN apt install --quiet --yes musl-tools
26 changes: 26 additions & 0 deletions ci/docker/debian-arm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM debian:12

ENV LLVM_VERSION 17
ENV RUST_VERSION 1.78

ENV PATH /opt/cargo/bin:$PATH
ENV CARGO_HOME /opt/cargo
ENV RUSTUP_HOME /opt/rustup

RUN apt update --quiet && apt install --quiet --yes curl build-essential tar git
RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
RUN /usr/bin/echo -e "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-$LLVM_VERSION main" \
> /etc/apt/sources.list.d/llvm$LLVM_VERSION.list

RUN apt update --quiet && apt install --quiet --yes \
llvm-$LLVM_VERSION llvm-$LLVM_VERSION-dev \
libstdc++-11-dev libclang-common-$LLVM_VERSION-dev zlib1g-dev \
libpolly-$LLVM_VERSION-dev libzstd-dev

RUN curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location \
--silent --show-error --fail "https://sh.rustup.rs" | \
sh -s -- --quiet -y --no-modify-path --profile minimal \
--component clippy,rustfmt --default-toolchain $RUST_VERSION

RUN dpkg --add-architecture arm64 \
&& apt install --quiet --yes gcc-aarch64-linux-gnu musl-tools:arm64
2 changes: 1 addition & 1 deletion ci/docker/fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV CARGO_HOME /opt/cargo
RUN sudo dnf install --assumeyes --quiet gcc make tar git rustup rclone \
llvm$LLVM_VERSION llvm$LLVM_VERSION-devel \
llvm$LLVM_VERSION-static libstdc++-devel libstdc++-static \
libffi-devel zlib-devel musl-gcc
libffi-devel zlib-devel

RUN rustup-init --quiet -y --no-modify-path --profile minimal \
--component clippy,rustfmt --default-toolchain $RUST_VERSION
Expand Down
98 changes: 98 additions & 0 deletions ci/runtimes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

set -e

# The version of Rust to use.
RUST_VERSION='1.78'

# The directory to place the runtimes in.
DIR="tmp/runtimes"

function rustup_lib {
local home
local toolchain
home="$(rustup show home)"
toolchain="$(rustup show active-toolchain | awk '{print $1}')"

echo "${home}/toolchains/${toolchain}/lib/rustlib/${1}/lib/"
}

function build {
local rust_target
local inko_target
local out
local target_dir
rust_target="${1}"
inko_target="${2}"
out="${DIR}/${inko_target}.tar.gz"
target_dir="${DIR}/${inko_target}"

if [[ -f "${out}" ]]
then
return 0
fi

rustup target add "${rust_target}"
cargo build -p rt --release --target="${rust_target}"
mkdir -p "${target_dir}"
cp "target/${rust_target}/release/libinko.a" "${target_dir}"

if [[ "${rust_target}" == *-musl ]]
then
cp "$(rustup_lib "${rust_target}")/self-contained/libunwind.a" \
"${target_dir}"
fi

tar --directory "${DIR}" --create --gzip --file "${out}" "${inko_target}"
rm -rf "${target_dir}"
}

function install_rust {
curl --proto '=https' \
--tlsv1.2 \
--retry 10 \
--retry-connrefused \
--location \
--silent \
--show-error \
--fail "https://sh.rustup.rs" | \
sh -s -- --profile minimal -y --default-toolchain "${RUST_VERSION}"

export PATH="${CARGO_HOME}/bin:${PATH}"
}

function init_rust {
rustup-init --quiet -y --no-modify-path --profile minimal \
--default-toolchain $RUST_VERSION

export PATH="${CARGO_HOME}/bin:${PATH}"
}

mkdir -p "${DIR}"

case "$1" in
"amd64-linux")
build "x86_64-unknown-linux-gnu" "amd64-linux-gnu"
build "x86_64-unknown-linux-musl" "amd64-linux-musl"
;;
"arm64-linux")
build "aarch64-unknown-linux-gnu" "arm64-linux-gnu"
build "aarch64-unknown-linux-musl" "arm64-linux-musl"
;;
"amd64-mac")
init_rust
build "x86_64-apple-darwin" "amd64-mac-native"
;;
"arm64-mac")
init_rust
build "aarch64-apple-darwin" "arm64-mac-native"
;;
"amd64-freebsd")
install_rust
build "x86_64-unknown-freebsd" "amd64-freebsd-native"
;;
*)
echo "the architecture '$1' is invalid"
exit 1
;;
esac
8 changes: 4 additions & 4 deletions docs/source/setup/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ Debian 12:

```bash
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo add-apt-repository "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main"
echo -e "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list
sudo apt-get update
sudo apt-get install --yes git build-essential llvm-17 llvm-17-dev libstdc++-10-dev libclang-common-17-dev zlib1g-dev libpolly-17-dev libzstd-dev
sudo apt-get install --yes git build-essential llvm-17 llvm-17-dev libstdc++-11-dev libclang-common-17-dev zlib1g-dev libpolly-17-dev libzstd-dev
```

For older versions, refer to [LLVM's Debian/Ubuntu packages page][llvm-apt] and
Expand Down Expand Up @@ -291,9 +291,9 @@ For 23.10:

```bash
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo add-apt-repository "deb http://apt.llvm.org/mantic/ llvm-toolchain-mantic-17 main"
echo -e "deb http://apt.llvm.org/mantic/ llvm-toolchain-mantic-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list
sudo apt-get update
sudo apt-get install --yes rustc cargo git build-essential llvm-17 llvm-17-dev libstdc++-10-dev libclang-common-17-dev zlib1g-dev libpolly-17-dev libzstd-dev
sudo apt-get install --yes rustc cargo git build-essential llvm-17 llvm-17-dev libstdc++-11-dev libclang-common-17-dev zlib1g-dev libpolly-17-dev libzstd-dev
```

For older versions, refer to [LLVM's Debian/Ubuntu packages page][llvm-apt] and
Expand Down
Loading

0 comments on commit a2fd9c7

Please sign in to comment.