Commit f27fec3

Karn Wong <[email protected]>
2025-07-28 07:18:06
fix: use dynamic linking to prevent errors on darwin/arm64
1 parent afc00b7
internal/get/sensors.go
@@ -1,7 +1,8 @@
 package get
 
 /*
-#cgo LDFLAGS: ./lib/libsystem.a -ldl
+#cgo linux LDFLAGS: ./lib/libsystem.so
+#cgo darwin LDFLAGS: ./lib/libsystem.dylib
 #include "../../lib/system.h"
 #include <stdlib.h>
 */
internal/get/system_info.go
@@ -1,7 +1,8 @@
 package get
 
 /*
-#cgo LDFLAGS: ./lib/libsystem.dylib
+#cgo linux LDFLAGS: ./lib/libsystem.so
+#cgo darwin LDFLAGS: ./lib/libsystem.dylib
 #include "../../lib/system.h"
 #include <stdlib.h>
 */
lib/system/Cargo.toml
@@ -3,7 +3,7 @@ name = "system"
 version = "0.1.0"
 
 [lib]
-crate-type = ["staticlib"]
+crate-type = ["cdylib"]
 
 [dependencies]
 battery = "0.7.8"
lib/.gitignore
@@ -1,2 +1,3 @@
 target
-*.a
\ No newline at end of file
+*.so
+*.dylib
scripts/build-dynamic.sh
@@ -0,0 +1,13 @@
+#!/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/
+fi
+
+go build -ldflags="-r lib"
scripts/build-static.sh
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-cd lib/system
-cargo build --release
-cd ../..
-
-cp lib/system/target/release/libsystem.a lib/
.pre-commit-config.yaml
@@ -24,6 +24,8 @@ repos:
       - id: go-vet
       - id: golangci-lint
       - id: yamlfmt
+      - id: shellcheck
+      - id: shfmt
   - repo: local
     hooks:
       - id: go-build
@@ -32,4 +34,4 @@ repos:
         language: system
         types: [go]
         pass_filenames: false
-        require_serial: true
\ No newline at end of file
+        require_serial: true
Makefile
@@ -4,5 +4,5 @@ build: build-static
 test:
 	go test ./...
 
-build-static:
-	./scripts/build-static.sh
+build-dynamic:
+	./scripts/build-dynamic.sh