Skip to content

Commit

Permalink
add hacky Linux/ARM64 cross-compilation support
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej committed Jun 7, 2024
1 parent 68df37e commit 906a7de
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 123 deletions.
236 changes: 125 additions & 111 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-latest
# - macos-latest
steps:
- uses: actions/cache@v4
with:
Expand Down Expand Up @@ -56,133 +56,147 @@ jobs:
- name: Install ccache, ninja (macOS)
run: brew install ccache ninja
if: matrix.os == 'macos-latest'
- name: Install ccache, ninja (Linux)
run: sudo apt install ccache ninja-build
- name: Install build dependencies (Linux)
run: |
sudo apt install ccache ninja-build gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
rustup target add aarch64-unknown-linux-gnu
if: matrix.os == 'ubuntu-latest'
- name: Build
run: NINJA_FLAGS=-v make package LLVM_CMAKE_FLAGS=-DLLVM_CCACHE_BUILD=ON
run: NINJA_FLAGS=-v make package LLVM_CMAKE_FLAGS=-DLLVM_CCACHE_BUILD=ON DEB_ARCH=amd64 TAR_MACHINE=linux-amd64
shell: bash
- name: Run the testsuite
run: NINJA_FLAGS=-v make check RUNTIME=wasmtime
- name: Cross-compile for ARM64
# Hacktastic cross-compilation step: build and install an ARM64 LLVM,
# reusing everything else we built using the native toolchain. Once
# GitHub provides ARM64 runners to open source projects (planned for
# second half of 2024) we'll be able to build natively and avoid this
# mess.
run: |
rm -r build/llvm build/llvm.BUILT
NINJA_FLAGS=-v make build/llvm.BUILT LLVM_CMAKE_FLAGS="-DLLVM_CCACHE_BUILD=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_CROSSCOMPILING=True -DCMAKE_CXX_FLAGS=-march=armv8-a -DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_SYSTEM_NAME=Linux -DLLVM_HOST_TRIPLE=aarch64-linux-gnu"
cargo install wasm-component-ld@0.5.0 --root "$(pwd)/build/install/opt/wasi-sdk" --target aarch64-unknown-linux-gnu
./deb_from_installation.sh "$(pwd)/dist" "$(./version.py)" "$(pwd)/build/install/opt/wasi-sdk" "arm64"
./tar_from_installation.sh "$(pwd)/dist" "$(./version.py)" "$(pwd)/build/install/opt/wasi-sdk" "linux-arm64"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
# Upload the dist folder. Give it a name according to the OS it was built for.
name: ${{ format( 'dist-{0}', matrix.os) }}
path: dist

winbuild:
name: Windows Build
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- arch: x64
sys: clang64
env: clang-x86_64
- arch: x86
sys: clang32
env: clang-i686
steps:
- uses: actions/cache@v4
with:
path: ~/AppData/Local/ccache
key: 0-${{ format( 'cache-windows-latest-{0}', matrix.arch) }}-${{ github.run_id }}
restore-keys: |
0-${{ format( 'cache-windows-latest-{0}', matrix.arch) }}
- uses: msys2/setup-msys2@v2
with:
install: >-
base-devel
git
mingw-w64-${{ matrix.env }}-ccache
mingw-w64-${{ matrix.env }}-cmake
mingw-w64-${{ matrix.env }}-ninja
mingw-w64-${{ matrix.env }}-toolchain
msystem: ${{ matrix.sys }}
update: true
release: false
path-type: inherit
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --tags --force
name: Force-fetch tags to work around actions/checkout#290
- run: git submodule update --init --depth 32 --jobs 3
- name: Build
shell: msys2 {0}
run: |
make package LLVM_CMAKE_FLAGS=-DLLVM_CCACHE_BUILD=ON
make check
- name: Does it work sans msys2?
run: |
C:\wasi-sdk\bin\clang.exe --version
C:\wasi-sdk\bin\llvm-ar.exe --version
C:\wasi-sdk\bin\wasm-ld.exe --version
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
# Upload the dist folder. Give it a name according to the OS it was built for.
name: ${{ format( 'dist-windows-latest-{0}', matrix.arch) }}
path: dist
# winbuild:
# name: Windows Build
# runs-on: windows-latest
# strategy:
# fail-fast: false
# matrix:
# include:
# - arch: x64
# sys: clang64
# env: clang-x86_64
# - arch: x86
# sys: clang32
# env: clang-i686
# steps:
# - uses: actions/cache@v4
# with:
# path: ~/AppData/Local/ccache
# key: 0-${{ format( 'cache-windows-latest-{0}', matrix.arch) }}-${{ github.run_id }}
# restore-keys: |
# 0-${{ format( 'cache-windows-latest-{0}', matrix.arch) }}
# - uses: msys2/setup-msys2@v2
# with:
# install: >-
# base-devel
# git
# mingw-w64-${{ matrix.env }}-ccache
# mingw-w64-${{ matrix.env }}-cmake
# mingw-w64-${{ matrix.env }}-ninja
# mingw-w64-${{ matrix.env }}-toolchain
# msystem: ${{ matrix.sys }}
# update: true
# release: false
# path-type: inherit
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - run: git fetch --tags --force
# name: Force-fetch tags to work around actions/checkout#290
# - run: git submodule update --init --depth 32 --jobs 3
# - name: Build
# shell: msys2 {0}
# run: |
# make package LLVM_CMAKE_FLAGS=-DLLVM_CCACHE_BUILD=ON
# make check
# - name: Does it work sans msys2?
# run: |
# C:\wasi-sdk\bin\clang.exe --version
# C:\wasi-sdk\bin\llvm-ar.exe --version
# C:\wasi-sdk\bin\wasm-ld.exe --version
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# # Upload the dist folder. Give it a name according to the OS it was built for.
# name: ${{ format( 'dist-windows-latest-{0}', matrix.arch) }}
# path: dist

dockerbuild:
name: Docker Build
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v4
with:
path: ~/.ccache
key: 0-cache-ubuntu-bionic-${{ github.run_id }}
restore-keys: |
0-cache-ubuntu-bionic
# dockerbuild:
# name: Docker Build
# runs-on: ubuntu-latest
# steps:
# - uses: actions/cache@v4
# with:
# path: ~/.ccache
# key: 0-cache-ubuntu-bionic-${{ github.run_id }}
# restore-keys: |
# 0-cache-ubuntu-bionic

- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --tags --force
name: Force-fetch tags to work around actions/checkout#290
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - run: git fetch --tags --force
# name: Force-fetch tags to work around actions/checkout#290

- run: git submodule update --init --depth 32 --jobs 3
# - run: git submodule update --init --depth 32 --jobs 3

- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# - uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
# - uses: docker/setup-qemu-action@v2
# - uses: docker/setup-buildx-action@v2

- uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
# - uses: docker/metadata-action@v4
# id: meta
# with:
# images: ghcr.io/${{ github.repository }}
# tags: |
# type=schedule
# type=ref,event=branch
# type=ref,event=tag
# type=ref,event=pr
# type=sha

- name: Run docker_build script
run: ./docker_build.sh
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
# Upload the dist folder. Give it a name according to the OS it was built for.
name: dist-ubuntu-bionic
path: dist
# - name: Run docker_build script
# run: ./docker_build.sh
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# # Upload the dist folder. Give it a name according to the OS it was built for.
# name: dist-ubuntu-bionic
# path: dist

- name: Build and push wasi-sdk docker image
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Build and push wasi-sdk docker image
# uses: docker/build-push-action@v3
# with:
# context: .
# file: docker/Dockerfile
# push: ${{ github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch' }}
# platforms: linux/amd64,linux/arm64
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ package: build/package.BUILT

build/package.BUILT: build strip
mkdir -p dist
./deb_from_installation.sh $(shell pwd)/dist "$(VERSION)" "$(BUILD_PREFIX)"
./tar_from_installation.sh "$(shell pwd)/dist" "$(VERSION)" "$(BUILD_PREFIX)"
./deb_from_installation.sh $(shell pwd)/dist "$(VERSION)" "$(BUILD_PREFIX)" "$(DEB_ARCH)"
./tar_from_installation.sh "$(shell pwd)/dist" "$(VERSION)" "$(BUILD_PREFIX)" "$(TAR_MACHINE)"
touch build/package.BUILT

.PHONY: default clean build strip package check
8 changes: 6 additions & 2 deletions deb_from_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ else
INSTALL_DIR=/opt/wasi-sdk
fi

if [ -n "$4" ]; then
ARCH="$4"
else
ARCH=$(dpkg --print-architecture)
fi

if [ ! -d $INSTALL_DIR ] ; then
echo "Directory $INSTALL_DIR doesn't exist. Nothing to copy from."
exit 1
fi

ARCH=$(dpkg --print-architecture)

rm -rf build/pkg
mkdir -p build/pkg/opt
mkdir -p build/pkg/DEBIAN
Expand Down
20 changes: 12 additions & 8 deletions tar_from_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ else
INSTALL_DIR=/opt/wasi-sdk
fi

case "$(uname -s)" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=macos;;
CYGWIN*) MACHINE=cygwin;;
MINGW*) MACHINE=mingw;;
MSYS*) MACHINE=msys;; #MSYS_NT-10.0-19043
*) MACHINE="UNKNOWN"
esac
if [ -n "$4" ]; then
MACHINE="$4"
else
case "$(uname -s)" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=macos;;
CYGWIN*) MACHINE=cygwin;;
MINGW*) MACHINE=mingw;;
MSYS*) MACHINE=msys;; #MSYS_NT-10.0-19043
*) MACHINE="UNKNOWN"
esac
fi

if [ ! -d $INSTALL_DIR ] ; then
echo "Directory $INSTALL_DIR doesn't exist. Nothing to copy from."
Expand Down

0 comments on commit 906a7de

Please sign in to comment.