Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action for building and release #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: build static binary
on:
workflow_dispatch:
push:
branches:
- master
tags:
- '*'
pull_request:
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build
run: |
docker buildx build --platform "linux/amd64,linux/arm64" --file Dockerfile.build.static --output out .
mv out/**/dog_* out/
rm -r out/linux*
- name: Upload to artifact
uses: actions/upload-artifact@v3
with:
name: binary_linux
path: ./out/dog_*
build-macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Dependencies
run: |
rustup target add aarch64-apple-darwin
- name: Build
run: |
cargo build --target=aarch64-apple-darwin
cargo build --target=x86_64-apple-darwin
mkdir out
mv -v target/aarch64-apple-darwin/debug/dog out/dog_darwin_arm64
mv -v target/x86_64-apple-darwin/debug/dog out/dog_darwin_x86_64
- name: Upload to artifact
uses: actions/upload-artifact@v3
with:
name: binary_macos
path: ./out/*
build-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup rust
run: |
rustup target add aarch64-pc-windows-msvc
- name: Build
run: |
cargo build --target x86_64-pc-windows-msvc
cargo build --target aarch64-pc-windows-msvc
mkdir out
move target\x86_64-pc-windows-msvc\debug\dog.exe out\dog_windows_x86_64.exe
move target\aarch64-pc-windows-msvc\debug\dog.exe out\dog_windows_arm64.exe
- name: Upload to artifact
uses: actions/upload-artifact@v3
with:
name: binary_windows
path: ./out/*

release:
runs-on: ubuntu-latest
needs:
- build-linux
- build-windows
- build-macos
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
path: ./artifacts
- name: organize files
run: |
tree artifacts
mkdir out
mv -v artifacts/**/dog_* out/
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: ./out/dog_*
15 changes: 15 additions & 0 deletions Dockerfile.build.static
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:3.18 as build

COPY ./ /source
WORKDIR /source

RUN apk update && \
apk add rustup git gcc lld openssl1.1-compat-dev openssl1.1-compat-libs-static && \
rustup-init -y && \
source "$HOME/.cargo/env" && \
RUSTFLAGS="-C link-args=-fuse-ld=lld" cargo build && \
strip target/debug/dog

FROM scratch AS export-stage
ARG TARGETARCH
COPY --from=build /source/target/debug/dog ./dog_linux_$TARGETARCH