Commit 51c957a

Karn Wong <[email protected]>
2025-09-27 09:14:34
ci: use arg for build script tag: v0.9.0
1 parent a62839f
.github/workflows/go-test.yaml
@@ -17,6 +17,8 @@ jobs:
         uses: actions/setup-go@v6
         with:
           go-version: stable
+      - name: Setup cross toolchain
+        run: cargo install cross
       - name: Build ffi
         run: ./scripts/build-static.sh
       - name: Install dependencies
.github/workflows/release.yaml
@@ -3,7 +3,7 @@ on:
   push:
     tags:
       - "*"
-#  pull_request: # debug
+      # pull_request: # debug
 permissions:
   contents: write
   id-token: write
scripts/build-static-ci-darwin-amd64.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cross build --release --target x86_64-apple-darwin
-cd ../..
-
-cp lib/system/target/x86_64-apple-darwin/release/libsystem.a lib/
scripts/build-static-ci-darwin-arm64.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cross build --release --target aarch64-apple-darwin
-cd ../..
-
-cp lib/system/target/aarch64-apple-darwin/release/libsystem.a lib/
scripts/build-static-ci-linux-amd64.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cross build --release --target x86_64-unknown-linux-gnu
-cd ../..
-
-cp lib/system/target/x86_64-unknown-linux-gnu/release/libsystem.a lib/
scripts/build-static-ci-linux-arm64.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cross build --release --target aarch64-unknown-linux-gnu
-cd ../..
-
-cp lib/system/target/aarch64-unknown-linux-gnu/release/libsystem.a lib/
scripts/build-static-ci-windows-amd64.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cross build --release --target x86_64-pc-windows-gnu
-cd ../..
-
-cp lib/system/target/x86_64-pc-windows-gnu/release/libsystem.a lib/
scripts/build-static-ci.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+cd lib/system || exit
+cross build --release --target "$TARGET"
+cd ../..
+
+cp "lib/system/target/$TARGET/release/libsystem.a" lib/
scripts/build-static.sh
@@ -1,9 +1,21 @@
 #!/bin/bash
 
+# build static lib
+if [[ $(uname -s) == 'Linux' ]]; then
+	TARGET="x86_64-unknown-linux-gnu"
+elif [[ $(uname -s) == 'Darwin' ]]; then
+	TARGET="aarch64-apple-darwin"
+fi
+
 cd lib/system || exit
-cargo build --release
-cd ../..
+cross build --release --target "$TARGET"
 
-cp lib/system/target/release/libsystem.a lib/
+cd ../..
+cp "lib/system/target/$TARGET/release/libsystem.a" lib/
 
-go build -ldflags="-extldflags=-static"
+# build go binary
+if [[ $(uname -s) == 'Linux' ]]; then
+	go build -ldflags="-extldflags=-static"
+elif [[ $(uname -s) == 'Darwin' ]]; then
+	CGO_ENABLED=1 go build -ldflags="-s -w -linkmode 'external'" .
+fi
.goreleaser-darwin-amd64.yaml
@@ -1,7 +1,9 @@
 version: 2
+env:
+  - TARGET=x86_64-apple-darwin
 before:
   hooks:
-    - ./scripts/build-static-ci-darwin-amd64.sh
+    - ./scripts/build-static-ci.sh
 builds:
   - env:
       - CGO_ENABLED=1
.goreleaser-darwin-arm64.yaml
@@ -1,7 +1,9 @@
 version: 2
+env:
+  - TARGET=aarch64-apple-darwin
 before:
   hooks:
-    - ./scripts/build-static-ci-darwin-arm64.sh
+    - ./scripts/build-static-ci.sh
 builds:
   - env:
       - CGO_ENABLED=1
.goreleaser-linux-amd64.yaml
@@ -1,7 +1,9 @@
 version: 2
+env:
+  - TARGET=x86_64-unknown-linux-gnu
 before:
   hooks:
-    - ./scripts/build-static-ci-linux-amd64.sh
+    - ./scripts/build-static-ci.sh
 builds:
   - env:
       - CGO_ENABLED=1
.goreleaser-linux-arm64.yaml
@@ -1,7 +1,9 @@
 version: 2
+env:
+  - TARGET=aarch64-unknown-linux-gnu
 before:
   hooks:
-    - ./scripts/build-static-ci-linux-arm64.sh
+    - ./scripts/build-static-ci.sh
 builds:
   - env:
       - CGO_ENABLED=1
.goreleaser-windows-amd64.yaml
@@ -1,7 +1,9 @@
 version: 2
+env:
+  - TARGET=x86_64-pc-windows-gnu
 before:
   hooks:
-    - ./scripts/build-static-ci-windows-amd64.sh
+    - ./scripts/build-static-ci.sh
 builds:
   - env:
       - CGO_ENABLED=1
Makefile
@@ -3,7 +3,3 @@ build:
 
 test:
 	go test ./...
-
-build-darwin:
-	./scripts/build-static-ci-darwin-arm64.sh
-	CGO_ENABLED=1 go build -ldflags="-s -w -linkmode 'external'" .