Skip to content

Commit

Permalink
Add Linux ARM64 support to Go package
Browse files Browse the repository at this point in the history
This requires a Linux ARM64 runner to validate the package, which can
most easily be achieved by running a container on an m1 mac.
  • Loading branch information
Chris Connelly committed Mar 8, 2022
1 parent c8444e7 commit eb031d5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Linux (ARM musl)
host: ubuntu-latest
target: aarch64-unknown-linux-musl
flags: -C target-feature=-crt-static -C linker=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
static:
src: libpolar.a
dest: libpolar-Linux-arm.a
Expand Down Expand Up @@ -120,6 +121,12 @@ jobs:
toolchain: stable
override: true
target: ${{ matrix.build.target }}
# Awkwardly, rustup alone can't get us a cross-compiled Linux build
- name: Install C cross-compilation toolchain
if: matrix.build.target == 'aarch64-unknown-linux-musl'
run: |
curl -Lo /tmp/aarch64-linux-musl-cross.tgz https://musl.cc/aarch64-linux-musl-cross.tgz
cd /tmp && tar xzf /tmp/aarch64-linux-musl-cross.tgz
- name: Build release libraries
run: cargo build --release --target ${{ matrix.build.target }} -p polar-c-api
env:
Expand Down Expand Up @@ -177,6 +184,8 @@ jobs:
cp -r oso_static_library/polar.h languages/go/internal/ffi/native/polar.h
mkdir -p languages/go/internal/ffi/native/linux/amd64
cp -r oso_static_library/libpolar-musl.a languages/go/internal/ffi/native/linux/amd64/libpolar.a
mkdir -p languages/go/internal/ffi/native/linux/arm64
cp -r oso_static_library/libpolar-Linux-arm.a languages/go/internal/ffi/native/linux/arm64/libpolar.a
mkdir -p languages/go/internal/ffi/native/macos/amd64
cp -r oso_static_library/libpolar-macOS.a languages/go/internal/ffi/native/macos/amd64/libpolar.a
mkdir -p languages/go/internal/ffi/native/macos/arm64
Expand Down Expand Up @@ -508,6 +517,34 @@ jobs:
run: docker run --rm --env POLAR_IGNORE_NO_ALLOW_WARNING=1 -v `pwd`:/oso golang:${{ matrix.go-version }}-buster /bin/sh -c 'cd /oso && go test -v ./internal/host && cd tests && go test -v'
working-directory: go

validate_go_linux_arm:
name: Test go ${{ matrix.go-version }} on m1
needs: [build_go]
runs-on: [self-hosted, Linux, ARM64]
strategy:
matrix:
# go 1.16 is the earliest version supported on m1 (which is the easiest way to run ARM)
go-version: ["1.16", "1.17"]
steps:
- uses: actions/checkout@v2
- name: Set version env
id: version
run: echo "::set-output name=oso_version::$(cat VERSION)"
- name: Download go package from package run
uses: actions/download-artifact@v1
with:
name: go
- name: "test"
run: |
~/go/bin/go${{ matrix.go-version }} build
/usr/local/bin/docker run --rm --env POLAR_IGNORE_NO_ALLOW_WARNING=1 -v `pwd`:/oso tetafro/golang-gcc:${{ matrix.go-version }}-alpine /bin/sh -c 'cd /oso && go test -v ./internal/host && cd tests && go test -v'
working-directory: go
env:
POLAR_IGNORE_NO_ALLOW_WARNING: 1
CGO_ENABLED: 1
GOOS: linux
GOARCH: arm64

validate_go_macos_arm:
name: Test go ${{ matrix.go-version }} on m1
needs: [build_go]
Expand Down
2 changes: 2 additions & 0 deletions languages/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ copy_lib:
ifeq ($(UNAME_S),Linux)
ifeq ($(UNAME_M),x86_64)
cp ../../target/debug/libpolar.a internal/ffi/native/linux/amd64/
else
cp ../../target/debug/libpolar.a internal/ffi/native/linux/arm64/
endif
endif
ifeq ($(UNAME_S),Darwin)
Expand Down
1 change: 1 addition & 0 deletions languages/go/internal/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ffi
// #include <stdlib.h>
// #include "native/polar.h"
// #cgo linux,amd64 LDFLAGS: ${SRCDIR}/native/linux/amd64/libpolar.a -ldl -lm
// #cgo linux,arm64 LDFLAGS: ${SRCDIR}/native/linux/arm64/libpolar.a -ldl -lm
// #cgo darwin,amd64 LDFLAGS: ${SRCDIR}/native/macos/amd64/libpolar.a -ldl -lm
// #cgo darwin,arm64 LDFLAGS: ${SRCDIR}/native/macos/arm64/libpolar.a -ldl -lm
// #cgo windows,amd64 LDFLAGS: ${SRCDIR}/native/windows/libpolar.a -lm -lws2_32 -luserenv -lbcrypt
Expand Down
1 change: 1 addition & 0 deletions languages/go/internal/ffi/native/linux/arm64/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package arm64
1 change: 1 addition & 0 deletions languages/go/internal/ffi/native/linux/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package linux

import (
_ "github.com/osohq/go-oso/internal/ffi/native/linux/amd64"
_ "github.com/osohq/go-oso/internal/ffi/native/linux/arm64"
)

0 comments on commit eb031d5

Please sign in to comment.