diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a163953 --- /dev/null +++ b/.github/workflows/build.yml @@ -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_* \ No newline at end of file diff --git a/Dockerfile.build.static b/Dockerfile.build.static new file mode 100644 index 0000000..e88cd0f --- /dev/null +++ b/Dockerfile.build.static @@ -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 \ No newline at end of file