Commit 52f7cc5
Changed files (17)
.github
workflows
internal
scripts
.github/workflows/go-test.yaml
@@ -17,6 +17,8 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: stable
+ - name: Build ffi
+ run: ./scripts/build-dynamic.sh
- name: Install dependencies
run: go get .
- name: Build
.github/workflows/release.yaml
@@ -5,28 +5,66 @@ on:
- "*"
permissions:
contents: write
- id-token: write
- attestations: write
jobs:
release-binary:
- runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ arch: [amd64, arm64]
+ exclude:
+ - os: windows-latest
+ arch: arm64
+ runs-on: ${{ (matrix.os == 'windows-latest' && 'ubuntu-latest') || matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
+ # --------- setup cross compilers ---------
+ - name: Install cross-compiler for linux/arm64
+ if: matrix.os == 'ubuntu-latest'
+ run: sudo apt-get install gcc-aarch64-linux-gnu
+ - name: Install cross-compiler for windows
+ if: matrix.os == 'windows-latest'
+ run: sudo apt-get install gcc-mingw-w64-x86-64
+ # --------- setup rust ---------
+ - name: Setup Rust
+ uses: actions-rust-lang/setup-rust-toolchain@v1
+ with:
+ toolchain: stable
+ - name: Add macOS Rust target
+ if: matrix.os == 'macos-latest'
+ run: |
+ rustup target add x86_64-apple-darwin
+ rustup target add aarch64-apple-darwin
+ - name: Add Windows Rust target
+ if: matrix.os == 'windows-latest'
+ run: |
+ rustup target add x86_64-pc-windows-gnu
+ - name: Setup cross toolchain
+ run: cargo install cross
+ # --------- setup go ---------
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
+ # --------- goreleaser ---------
+ - name: Set config file
+ id: config
+ run: |
+ if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
+ OS_NAME="linux"
+ elif [ "${{ matrix.os }}" = "macos-latest" ]; then
+ OS_NAME="darwin"
+ elif [ "${{ matrix.os }}" = "windows-latest" ]; then
+ OS_NAME="windows"
+ fi
+ echo "config_file=.goreleaser-${OS_NAME}-${{ matrix.arch }}.yaml" >> $GITHUB_OUTPUT
- name: Release
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
- args: release --clean --config .goreleaser.yaml
+ args: release --clean --config ${{ steps.config.outputs.config_file }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- - uses: actions/attest-build-provenance@v2
- with:
- subject-checksums: ./dist/checksums.txt
internal/get/sensors.go
@@ -3,6 +3,7 @@ package get
/*
#cgo linux LDFLAGS: ./lib/libsystem.so
#cgo darwin LDFLAGS: ./lib/libsystem.dylib
+#cgo windows LDFLAGS: ./lib/system.dll
#include "../../lib/system.h"
#include <stdlib.h>
*/
internal/get/system_info.go
@@ -3,6 +3,7 @@ package get
/*
#cgo linux LDFLAGS: ./lib/libsystem.so
#cgo darwin LDFLAGS: ./lib/libsystem.dylib
+#cgo windows LDFLAGS: ./lib/system.dll
#include "../../lib/system.h"
#include <stdlib.h>
*/
scripts/build-dynamic-ci-darwin-amd64.sh
@@ -0,0 +1,7 @@
+#!/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.dylib lib/
scripts/build-dynamic-ci-darwin-arm64.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+cd lib/system || exit
+cross build --release --target aarch64-apple-darwin
+cd ../..
+
+cp lib/system/target/aarch64-apple-darwin/release/libsystem.dylib lib/
scripts/build-dynamic-ci-linux-amd64.sh
@@ -0,0 +1,7 @@
+#!/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.so lib/
scripts/build-dynamic-ci-linux-arm64.sh
@@ -0,0 +1,7 @@
+#!/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.so lib/
scripts/build-dynamic-ci-windows-amd64.sh
@@ -0,0 +1,7 @@
+#!/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/system.dll lib/
scripts/build-dynamic-ci.sh.bak
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+cd lib/system || exit
+
+if [[ "$(uname)" == "Linux" ]]; then
+ cross build --release --target x86_64-unknown-linux-gnu
+ cross build --release --target aarch64-unknown-linux-gnu
+ cd ../..
+
+ cp lib/system/target/x86_64-unknown-linux-gnu/release/libsystem.so lib/
+ cp lib/system/target/aarch64-unknown-linux-gnu/release/libsystem.so lib/libsystem-aarch64.so
+elif [[ "$(uname)" == "Darwin" ]]; then
+ cp lib/system/target/release/libsystem.dylib lib/
+elif [[ "$(uname)" == "Windows" ]]; then
+ cp lib/system/target/release/libsystem.dll lib/
+fi
scripts/build-dynamic.sh
@@ -8,6 +8,8 @@ if [[ "$(uname)" == "Linux" ]]; then
cp lib/system/target/release/libsystem.so lib/
elif [[ "$(uname)" == "Darwin" ]]; then
cp lib/system/target/release/libsystem.dylib lib/
+elif [[ "$(uname)" == "Windows" ]]; then
+ cp lib/system/target/release/libsystem.dll lib/
fi
go build -ldflags="-r lib"
.goreleaser.yaml → .goreleaser-darwin-amd64.yaml
@@ -1,15 +1,16 @@
version: 2
+before:
+ hooks:
+ - ./scripts/build-dynamic-ci-darwin-amd64.sh
builds:
- - goos:
- - linux
+ - env:
+ - CGO_ENABLED=1
+ goos:
- darwin
- - windows
goarch:
- amd64
- - arm64
ldflags:
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: false
- name_template: "checksums.txt"
+ disable: true
\ No newline at end of file
.goreleaser-darwin-arm64.yaml
@@ -0,0 +1,16 @@
+version: 2
+before:
+ hooks:
+ - ./scripts/build-dynamic-ci-darwin-arm64.sh
+builds:
+ - env:
+ - CGO_ENABLED=1
+ goos:
+ - darwin
+ goarch:
+ - arm64
+ ldflags:
+ - -w -s
+ - -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
+checksum:
+ disable: true
\ No newline at end of file
.goreleaser-linux-amd64.yaml
@@ -0,0 +1,17 @@
+version: 2
+before:
+ hooks:
+ - ./scripts/build-dynamic-ci-linux-amd64.sh
+builds:
+ - env:
+ - CGO_ENABLED=1
+ - CC=gcc
+ goos:
+ - linux
+ goarch:
+ - amd64
+ ldflags:
+ - -w -s
+ - -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
+checksum:
+ disable: true
\ No newline at end of file
.goreleaser-linux-arm64.yaml
@@ -0,0 +1,17 @@
+version: 2
+before:
+ hooks:
+ - ./scripts/build-dynamic-ci-linux-arm64.sh
+builds:
+ - env:
+ - CGO_ENABLED=1
+ - CC=aarch64-linux-gnu-gcc
+ goos:
+ - linux
+ goarch:
+ - arm64
+ ldflags:
+ - -w -s
+ - -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
+checksum:
+ disable: true
\ No newline at end of file
.goreleaser-windows-amd64.yaml
@@ -0,0 +1,17 @@
+version: 2
+before:
+ hooks:
+ - ./scripts/build-dynamic-ci-windows-amd64.sh
+builds:
+ - env:
+ - CGO_ENABLED=1
+ - CC=x86_64-w64-mingw32-gcc
+ goos:
+ - windows
+ goarch:
+ - amd64
+ ldflags:
+ - -w -s
+ - -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
+checksum:
+ disable: true
\ No newline at end of file
Makefile
@@ -1,5 +1,5 @@
-build: build-static
- goreleaser release --skip publish --skip validate --skip archive --clean -f .goreleaser-linux.yaml
+build: build-dynamic
+ goreleaser build --clean --skip validate -f .goreleaser.yaml
test:
go test ./...