From 5e61692ee56711b4c78d95375ba4bbb58b24d62f Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Wed, 8 Jan 2025 15:23:28 +0100 Subject: [PATCH] Building on Linux arm64 (#2) --- .github/workflows/build.yml | 58 ++++++++++++++++++------------------- build.sh | 23 ++++++++++++--- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3a6caf4..3ab81b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,8 +16,27 @@ on: - "docs/**" jobs: - build-macos: - runs-on: macos-latest + build: + strategy: + matrix: + target: + - arch: amd64 + os: linux + runs-on: ubuntu-latest + ext: so + - arch: arm64 + os: linux + runs-on: [self-hosted, Linux, ARM64] + ext: so + - arch: arm64 + os: macos + runs-on: macos-latest + ext: dylib + - arch: amd64 + os: macos + runs-on: macos-latest + ext: dylib + runs-on: ${{ matrix.target.runs-on }} steps: - uses: actions/checkout@v4 - name: Setup Go @@ -28,38 +47,15 @@ jobs: - name: Build run: | ./build.sh - - name: Archive libgoast library (amd64) + - name: Archive libgoast library (${{ matrix.target.arch }}) uses: actions/upload-artifact@v4 with: - name: libgoast-amd64.dylib - path: libgoast-amd64.dylib - - name: Archive libgoast library (arm64) - uses: actions/upload-artifact@v4 - with: - name: libgoast-arm64.dylib - path: libgoast-arm64.dylib - build-linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache-dependency-path: go.sum - - name: Build - run: | - ./build.sh - - name: Archive libgoast library (amd64) - uses: actions/upload-artifact@v4 - with: - name: libgoast-amd64.so - path: libgoast-amd64.so + name: libgoast-${{ matrix.target.arch }}.${{ matrix.target.ext }} + path: libgoast-${{ matrix.target.arch }}.${{ matrix.target.ext }} publish: runs-on: ubuntu-latest needs: - - build-macos - - build-linux + - build if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') && !contains(github.ref, 'alpha') steps: - name: Determine Version @@ -89,6 +85,10 @@ jobs: with: name: libgoast-amd64.so path: . + - uses: actions/download-artifact@v4 + with: + name: libgoast-arm64.so + path: . - name: Create Release id: create_release uses: softprops/action-gh-release@v2 diff --git a/build.sh b/build.sh index 4d9bc42..7f83425 100755 --- a/build.sh +++ b/build.sh @@ -1,16 +1,31 @@ #!/bin/bash -ARCH=`uname -s | tr '[:upper:]' '[:lower:]'` +OS=`uname -s | tr '[:upper:]' '[:lower:]'` +ARCH=`arch` -if [ $ARCH == "darwin" ] +if [ $OS == "darwin" ] then EXTENSION="dylib" else EXTENSION="so" fi -CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o libgoast-amd64.${EXTENSION} lib.go +echo "Building on $OS for $ARCH" -if [ $ARCH == "darwin" ] +if [ $OS == "darwin" ] then CGO_ENABLED=1 GOARCH=arm64 go build -buildmode=c-shared -o libgoast-arm64.${EXTENSION} lib.go + CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o libgoast-amd64.${EXTENSION} lib.go +fi + +if [ $OS == "linux" ] +then + if [ $ARCH == "aarch64" ] + then + CGO_ENABLED=1 GOARCH=arm64 go build -buildmode=c-shared -o libgoast-arm64.${EXTENSION} lib.go + fi + + if [ $ARCH == "x86_64" ] + then + CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o libgoast-amd64.${EXTENSION} lib.go + fi fi