Skip to content

Commit

Permalink
Linux/macOS arm64 support (#15)
Browse files Browse the repository at this point in the history
ref #8 , needs test
  • Loading branch information
timzaak authored Jun 16, 2023
1 parent 0a7c28e commit ccf9bd7
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/client_build_arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: fornet arm64 client build
# run at self-hosted mac min M2
on:
workflow_dispatch:
inputs:
version:
required: true
description: "version to release"
env:
REGISTRY: ghcr.io
jobs:
docker-and-linux:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
with:
submodules: true
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to GithubPackages
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: build and push docker image
uses: docker/build-push-action@v2
with:
context: .
#platforms: linux/amd64,linux/arm64
push: true
file: command/docker/client/client.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.REGISTRY }}/fornetcode/fornet:${{github.event.inputs.version}}, ${{ env.REGISTRY }}/fornetcode/fornet:latest
- name: copy binary from docker to release directory
run: |
mkdir -p release
docker run --rm -v ./release:/release ${{ env.REGISTRY }}/fornetcode/fornet:${{github.event.inputs.version}} cp /bin/fornet:/release/ && cp /bin/fornet-cli:/release
cd release && tar -czvf release/fornet-linux-aarch64.tar.gz ./fornet ./fornet-cli && rm fornet && rm fornet-cli
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
path: release/*
if-no-files-found: error

mac:
strategy:
max-parallel: 1
fail-fast: true
matrix:
settings:
- host: self-hosted
target: aarch64-apple-darwin
build: make release-mac-aarch64

runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.settings.target }}
profile: minimal
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
client/target/
key: ${{ matrix.settings.host }}-${{ matrix.settings.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ matrix.settings.host }}-cargo-${{ matrix.settings.target }}
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- name: Build
run: ${{ matrix.settings.build }}

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
path: release/*
if-no-files-found: error
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is for .github/workflows.
.PHONY: release-mac-x86_64, release-mac-aarch64, release-linux, release-backend
.PHONY: release-mac-x86_64, release-mac-aarch64, release-linux, release-backend, release-linux-aarch64

#base_dir := $(shell pwd)

Expand All @@ -19,14 +19,23 @@ release-mac-x86_64:
release-mac-aarch64:
mkdir protoc && cd protoc && wget https://github.com/protocolbuffers/protobuf/releases/download/v21.9/protoc-21.9-osx-aarch_64.zip && unzip protoc-21.9-osx-aarch_64.zip && sudo cp bin/protoc /usr/local/bin
cp -r protoc/include/* protobuf/
mkdir -p release
mkdir -p release
cd client && cargo build --release --target=aarch64-apple-darwin
strip client/target/aarch64-apple-darwin/release/fornet
otool -L client/target/aarch64-apple-darwin/release/fornet
strip client/target/aarch64-apple-darwin/release/fornet-cli
otool -L client/target/aarch64-apple-darwin/release/fornet-cli
tar -C client/target/aarch64-apple-darwin/release/ -czvf release/fornet-mac-aarch64.tar.gz ./fornet ./fornet-cli

# This is for self-hosted arm64-linux
release-linux-aarch64:
cd client && cargo build --release
strip client/target/aarch64-unknown-linux-gnu/release/fornet
strip client/target/aarch64-unknown-linux-gnu/release/fornet-cli
tar -C client/target/aarch64-unknown-linux-gnu/release/ -czvf release/fornet-linux-x86_64.tar.gz ./fornet ./fornet-cli



release-linux:
mkdir protoc && cd protoc && wget https://github.com/protocolbuffers/protobuf/releases/download/v21.9/protoc-21.9-linux-x86_64.zip && unzip protoc-21.9-linux-x86_64.zip && sudo cp bin/protoc /usr/bin
cp -r protoc/include/* protobuf/
Expand All @@ -37,6 +46,7 @@ release-linux:
strip client/target/x86_64-unknown-linux-gnu/release/fornet-cli
tar -C client/target/x86_64-unknown-linux-gnu/release/ -czvf release/fornet-linux-x86_64.tar.gz ./fornet ./fornet-cli


release-backend:
cd admin-web && npm ci && npm run build:prod && cd ../
cp -r admin-web/build/ command/docker/backend/web
Expand Down

0 comments on commit ccf9bd7

Please sign in to comment.