Commit 8e684dc
Changed files (21)
.github
workflows
internal
lib
system
scripts
.github/workflows/go-test.yaml
@@ -18,7 +18,7 @@ jobs:
with:
go-version: stable
- name: Build ffi
- run: ./scripts/build-dynamic.sh
+ run: ./scripts/build-static.sh
- name: Install dependencies
run: go get .
- name: Build
.github/workflows/release.yaml
@@ -3,11 +3,13 @@ on:
push:
tags:
- "*"
+# pull_request: # debug
permissions:
contents: write
jobs:
release-binary:
strategy:
+ fail-fast: false # debug
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [amd64, arm64]
@@ -66,5 +68,6 @@ jobs:
distribution: goreleaser
version: "~> v2"
args: release --clean --config ${{ steps.config.outputs.config_file }}
+ # args: build --skip validate --clean --config ${{ steps.config.outputs.config_file }} # debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
internal/get/sensors.go
@@ -1,9 +1,9 @@
package get
/*
-#cgo linux LDFLAGS: ./lib/libsystem.so
-#cgo darwin LDFLAGS: ./lib/libsystem.dylib
-#cgo windows LDFLAGS: ./lib/system.dll
+#cgo linux LDFLAGS: ./lib/libsystem.a -ldl
+#cgo darwin LDFLAGS: ./lib/libsystem.a -ldl -framework IOKit
+#cgo windows LDFLAGS: ./lib/libsystem.a
#include "../../lib/system.h"
#include <stdlib.h>
*/
internal/get/system_info.go
@@ -1,9 +1,9 @@
package get
/*
-#cgo linux LDFLAGS: ./lib/libsystem.so
-#cgo darwin LDFLAGS: ./lib/libsystem.dylib
-#cgo windows LDFLAGS: ./lib/system.dll
+#cgo linux LDFLAGS: ./lib/libsystem.a -ldl
+#cgo darwin LDFLAGS: ./lib/libsystem.a -ldl -framework IOKit
+#cgo windows LDFLAGS: ./lib/libsystem.a
#include "../../lib/system.h"
#include <stdlib.h>
*/
lib/system/Cargo.toml
@@ -3,7 +3,7 @@ name = "system"
version = "0.1.0"
[lib]
-crate-type = ["cdylib"]
+crate-type = ["staticlib"]
[dependencies]
battery = "0.7.8"
lib/.gitignore
@@ -1,3 +1,3 @@
target
-*.so
-*.dylib
+*.a
+*.lib
scripts/build-dynamic-ci.sh.bak
@@ -1,16 +0,0 @@
-#!/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
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-cd lib/system || exit
-cargo build --release
-cd ../..
-
-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"
scripts/build-dynamic-ci-darwin-amd64.sh → scripts/build-static-ci-darwin-amd64.sh
@@ -4,4 +4,4 @@ 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/
+cp lib/system/target/x86_64-apple-darwin/release/libsystem.a lib/
scripts/build-dynamic-ci-darwin-arm64.sh → scripts/build-static-ci-darwin-arm64.sh
@@ -4,4 +4,4 @@ cd lib/system || exit
cross build --release --target aarch64-apple-darwin
cd ../..
-cp lib/system/target/aarch64-apple-darwin/release/libsystem.dylib lib/
+cp lib/system/target/aarch64-apple-darwin/release/libsystem.a lib/
scripts/build-dynamic-ci-linux-amd64.sh → scripts/build-static-ci-linux-amd64.sh
@@ -4,4 +4,4 @@ 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/
+cp lib/system/target/x86_64-unknown-linux-gnu/release/libsystem.a lib/
scripts/build-dynamic-ci-linux-arm64.sh → scripts/build-static-ci-linux-arm64.sh
@@ -4,4 +4,4 @@ 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/
+cp lib/system/target/aarch64-unknown-linux-gnu/release/libsystem.a lib/
scripts/build-dynamic-ci-windows-amd64.sh → scripts/build-static-ci-windows-amd64.sh
@@ -4,4 +4,4 @@ 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/
+cp lib/system/target/x86_64-pc-windows-gnu/release/libsystem.a lib/
scripts/build-static.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+cd lib/system || exit
+cargo build --release
+cd ../..
+
+cp lib/system/target/release/libsystem.a lib/
+
+go build -ldflags="-extldflags=-static"
.goreleaser-darwin-amd64.yaml
@@ -1,7 +1,7 @@
version: 2
before:
hooks:
- - ./scripts/build-dynamic-ci-darwin-amd64.sh
+ - ./scripts/build-static-ci-darwin-amd64.sh
builds:
- env:
- CGO_ENABLED=1
@@ -10,7 +10,8 @@ builds:
goarch:
- amd64
ldflags:
+ - -linkmode 'external'
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: true
\ No newline at end of file
+ disable: true
.goreleaser-darwin-arm64.yaml
@@ -1,7 +1,7 @@
version: 2
before:
hooks:
- - ./scripts/build-dynamic-ci-darwin-arm64.sh
+ - ./scripts/build-static-ci-darwin-arm64.sh
builds:
- env:
- CGO_ENABLED=1
@@ -10,7 +10,8 @@ builds:
goarch:
- arm64
ldflags:
+ - -linkmode 'external'
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: true
\ No newline at end of file
+ disable: true
.goreleaser-linux-amd64.yaml
@@ -1,17 +1,17 @@
version: 2
before:
hooks:
- - ./scripts/build-dynamic-ci-linux-amd64.sh
+ - ./scripts/build-static-ci-linux-amd64.sh
builds:
- env:
- CGO_ENABLED=1
- - CC=gcc
goos:
- linux
goarch:
- amd64
ldflags:
+ - -linkmode 'external' -extldflags '-static'
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: true
\ No newline at end of file
+ disable: true
.goreleaser-linux-arm64.yaml
@@ -1,7 +1,7 @@
version: 2
before:
hooks:
- - ./scripts/build-dynamic-ci-linux-arm64.sh
+ - ./scripts/build-static-ci-linux-arm64.sh
builds:
- env:
- CGO_ENABLED=1
@@ -11,7 +11,8 @@ builds:
goarch:
- arm64
ldflags:
+ - -linkmode 'external' -extldflags '-static'
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: true
\ No newline at end of file
+ disable: true
.goreleaser-windows-amd64.yaml
@@ -1,7 +1,7 @@
version: 2
before:
hooks:
- - ./scripts/build-dynamic-ci-windows-amd64.sh
+ - ./scripts/build-static-ci-windows-amd64.sh
builds:
- env:
- CGO_ENABLED=1
@@ -11,7 +11,8 @@ builds:
goarch:
- amd64
ldflags:
+ - -linkmode 'external' -extldflags '-static -lntdll -lsetupapi'
- -w -s
- -X github.com/kahnwong/swissknife/cmd.version={{.Version}}
checksum:
- disable: true
\ No newline at end of file
+ disable: true
.pre-commit-config.yaml
@@ -30,7 +30,7 @@ repos:
hooks:
- id: go-build
name: go-build
- entry: "make build-dynamic"
+ entry: "make build-static"
language: system
types: [go]
pass_filenames: false
Makefile
@@ -1,8 +1,8 @@
-build: build-dynamic
- goreleaser build --clean --skip validate -f .goreleaser.yaml
+build: build-static
+ goreleaser build --clean --skip validate -f .goreleaser-linux-amd64.yaml
test:
go test ./...
-build-dynamic:
- ./scripts/build-dynamic.sh
+build-static:
+ ./scripts/build-static.sh