Skip to content

Commit 7753465

Browse files
authored
Merge pull request #212 from klever-io/fix/cgo-vendor
add musl target to kos-go
2 parents 8e95eff + 65a4d9a commit 7753465

11 files changed

Lines changed: 194 additions & 92 deletions

File tree

.github/workflows/kos-go.yaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: KOS-Go Checks
2+
3+
on:
4+
push:
5+
paths:
6+
- 'packages/kos-go/kos_mobile/**'
7+
branches:
8+
- develop
9+
pull_request:
10+
branches:
11+
- develop
12+
13+
jobs:
14+
build-go-linux:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
24+
- name: Setup Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.21'
28+
29+
- name: RustUp
30+
uses: klever-io/kos-rs/.github/actions/rustup@develop
31+
with:
32+
with_cache: true
33+
34+
- name: Build Linux Go bindings
35+
run: make build-go
36+
37+
- name: Copy .so to Go package
38+
run: |
39+
mkdir -p packages/kos-go/kos_mobile/lib/linux-amd64
40+
cp target/release/libkos_mobile.so packages/kos-go/kos_mobile/lib/linux-amd64/
41+
42+
- name: Commit and push changes
43+
if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
44+
uses: stefanzweifel/git-auto-commit-action@v4
45+
with:
46+
commit_message: "Update Linux Go bindings library"
47+
file_pattern: "packages/kos-go/kos_mobile/lib/linux-amd64/libkos_mobile.so"
48+
49+
- name: Run Go tests
50+
run: |
51+
cd packages/kos-go
52+
make test
53+
54+
build-go-linux-musl:
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
with:
62+
submodules: recursive
63+
64+
- name: Setup Go
65+
uses: actions/setup-go@v5
66+
with:
67+
go-version: '1.21'
68+
69+
- name: RustUp
70+
uses: klever-io/kos-rs/.github/actions/rustup@develop
71+
with:
72+
with_cache: true
73+
74+
- name: Install musl tools
75+
run: sudo apt-get update && sudo apt-get install -y musl-tools
76+
77+
- name: Build Linux musl Go bindings
78+
run: |
79+
rustup target add x86_64-unknown-linux-musl
80+
make build-go-musl
81+
82+
- name: Copy .so to Go package
83+
run: |
84+
mkdir -p packages/kos-go/kos_mobile/lib/linux-amd64
85+
cp target/x86_64-unknown-linux-musl/release/libkos_mobile.so packages/kos-go/kos_mobile/lib/linux-musl-amd64/
86+
87+
- name: Commit and push changes
88+
if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
89+
uses: stefanzweifel/git-auto-commit-action@v4
90+
with:
91+
commit_message: "Update Linux musl Go bindings library"
92+
file_pattern: "packages/kos-go/kos_mobile/lib/linux-musl-amd64/libkos_mobile.so"
93+
94+
- name: Run Go tests
95+
run: |
96+
cd packages/kos-go
97+
make test-linux-musl
98+
99+
build-go-mac:
100+
runs-on: [ "macos-14" ]
101+
permissions:
102+
contents: write
103+
steps:
104+
- name: Checkout repository
105+
uses: actions/checkout@v4
106+
with:
107+
submodules: recursive
108+
109+
- name: Setup Go
110+
uses: actions/setup-go@v5
111+
with:
112+
go-version: '1.21'
113+
114+
- name: Install Rust toolchain
115+
shell: bash
116+
run: |
117+
set -e
118+
rustup component add --toolchain stable rustfmt clippy
119+
rustup default stable
120+
121+
- name: Setup protobuf
122+
run: brew install protobuf
123+
124+
- name: Build Mac Go bindings
125+
run: make build-go
126+
127+
- name: Copy dylib to Go package
128+
run: |
129+
mkdir -p packages/kos-go/kos_mobile/lib/darwin-aarch64
130+
cp target/release/libkos_mobile.dylib packages/kos-go/kos_mobile/lib/darwin-aarch64/
131+
132+
- name: Commit and push changes
133+
if: github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')
134+
uses: stefanzweifel/git-auto-commit-action@v4
135+
with:
136+
commit_message: "Update macOS Go bindings library"
137+
file_pattern: "packages/kos-go/kos_mobile/lib/darwin-aarch64/libkos_mobile.dylib"
138+
139+
- name: Run Go tests
140+
run: |
141+
cd packages/kos-go
142+
make test

.github/workflows/pull-develop.yaml

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
- '**/*.md'
1818
- '.gitignore'
1919
- '.github/**'
20+
- 'packages/kos-go/kos_mobile/lib/**'
2021

2122
jobs:
2223
format:
@@ -66,72 +67,3 @@ jobs:
6667

6768
- name: Build
6869
run: make webpack-npm
69-
70-
build-go-linux:
71-
needs: [ format ]
72-
runs-on: ubuntu-latest
73-
steps:
74-
- name: Checkout repository
75-
uses: actions/checkout@v3
76-
with:
77-
submodules: recursive
78-
79-
- name: Setup Go
80-
uses: actions/setup-go@v4
81-
with:
82-
go-version: '1.21'
83-
84-
- name: RustUp
85-
uses: klever-io/kos-rs/.github/actions/rustup@develop
86-
with:
87-
with_cache: true
88-
89-
- name: Build Linux Go bindings
90-
run: make build-go
91-
92-
- name: Copy .so to Go package
93-
run: |
94-
mkdir -p packages/kos-go/kos_mobile/lib/linux-amd64
95-
cp target/release/libkos_mobile.so packages/kos-go/kos_mobile/lib/linux-amd64/
96-
97-
- name: Run Go tests
98-
run: |
99-
cd packages/kos-go
100-
make test
101-
102-
build-go-mac:
103-
needs: [ format ]
104-
runs-on: [ "macos-14" ]
105-
steps:
106-
- name: Checkout repository
107-
uses: actions/checkout@v3
108-
with:
109-
submodules: recursive
110-
111-
- name: Setup Go
112-
uses: actions/setup-go@v4
113-
with:
114-
go-version: '1.21'
115-
116-
- name: Install Rust toolchain
117-
shell: bash
118-
run: |
119-
set -e
120-
rustup component add --toolchain stable rustfmt clippy
121-
rustup default stable
122-
123-
- name: Setup protobuf
124-
run: brew install protobuf
125-
126-
- name: Build Mac Go bindings
127-
run: make build-go
128-
129-
- name: Copy dylib to Go package
130-
run: |
131-
mkdir -p packages/kos-go/kos_mobile/lib/darwin-aarch64
132-
cp target/release/libkos_mobile.dylib packages/kos-go/kos_mobile/lib/darwin-aarch64/
133-
134-
- name: Run Go tests
135-
run: |
136-
cd packages/kos-go
137-
make test

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ build-ios:
4545

4646
build-go:
4747
cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.4.0+v0.28.3 && \
48-
cargo build --release --package kos-mobile && uniffi-bindgen-go --library target/release/libkos_mobile.a --out-dir ./packages/kos-go
48+
cargo build --release --package kos-mobile && uniffi-bindgen-go --library target/release/libkos_mobile.a --out-dir ./packages/kos-go
49+
50+
build-go-musl:
51+
cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.4.0+v0.28.3 && \
52+
RUSTFLAGS="-C target-feature=-crt-static" cargo build --release --target x86_64-unknown-linux-musl --package kos-mobile && \
53+
uniffi-bindgen-go --library target/x86_64-unknown-linux-musl/release/libkos_mobile.a --out-dir ./packages/kos-go
4954

5055
test-ios: build-ios
5156
cd packages/kos-mobile/ios/framework/KOSMobile && xcodebuild \

packages/kos-go/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
bin

packages/kos-go/Makefile

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,25 @@ test-darwin-arm64:
104104
GOARCH=arm64 \
105105
go test $(TEST_FLAGS) ./...
106106

107-
.PHONY: build-all
108-
build-all: build-linux-amd64 build-darwin-arm64
109-
@echo "Built all platforms"
110-
111-
.PHONY: test-all
112-
test-all:
113-
@echo "Testing all available platforms..."
114-
@if [ -d "kos_mobile/lib/linux-amd64" ]; then \
115-
echo "Testing Linux AMD64..."; \
116-
$(MAKE) test-linux-amd64; \
117-
fi
118-
@if [ -d "kos_mobile/lib/darwin-aarch64" ]; then \
119-
echo "Testing Darwin ARM64..."; \
120-
$(MAKE) test-darwin-arm64; \
121-
fi
107+
.PHONY: build-linux-musl
108+
build-linux-musl:
109+
LD_LIBRARY_PATH=$(PWD)/kos_mobile/lib/linux-amd64 \
110+
CGO_ENABLED=1 \
111+
CGO_LDFLAGS="-lm" \
112+
GOOS=linux \
113+
GOARCH=amd64 \
114+
GOFLAGS="-tags=musl" \
115+
go build $(BUILD_FLAGS) -o bin/kos-linux-musl ./...
116+
117+
.PHONY: test-linux-musl
118+
test-linux-musl:
119+
LD_LIBRARY_PATH=$(PWD)/kos_mobile/lib/linux-amd64 \
120+
CGO_ENABLED=1 \
121+
CGO_LDFLAGS="-lm" \
122+
GOOS=linux \
123+
GOARCH=amd64 \
124+
GOFLAGS="-tags=musl" \
125+
go test $(TEST_FLAGS) ./...
122126

123127
.PHONY: check-lib
124128
check-lib:
@@ -143,10 +147,10 @@ help:
143147
@echo " check-lib - Verify library exists for current platform"
144148
@echo ""
145149
@echo "Cross-platform targets:"
146-
@echo " build-all - Build for all platforms"
147150
@echo " build-linux-amd64 - Build for Linux AMD64"
151+
@echo " build-linux-musl - Build for Linux with musl"
148152
@echo " build-darwin-arm64 - Build for macOS ARM64"
149-
@echo " test-all - Test all available platforms"
150153
@echo " test-linux-amd64 - Test Linux AMD64"
154+
@echo " test-linux-musl - Test Linux with musl"
151155
@echo " test-darwin-amd64 - Test macOS AMD64"
152156
@echo " test-darwin-arm64 - Test macOS ARM64"

packages/kos-go/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
55
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
66
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
78
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
89
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
910
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.test
2+
3+
*.out
4+
coverage.*
5+
*.coverprofile
6+
profile.cov
7+
8+
vendor/
9+
10+
go.work
11+
go.work.sum
12+
13+
.env
14+
15+
.idea/
16+
.vscode/

packages/kos-go/kos_mobile/cgo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package kos_mobile
22

33
/*
4-
#cgo CFLAGS: -I.
5-
#cgo linux LDFLAGS: -L./lib/linux-amd64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/linux-amd64
6-
#cgo darwin,amd64 LDFLAGS: -L./lib/darwin-amd64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/darwin-amd64
7-
#cgo darwin,arm64 LDFLAGS: -L./lib/darwin-aarch64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/darwin-aarch64
8-
4+
#cgo CFLAGS: -I. -I${SRCDIR}
5+
#cgo linux,!musl LDFLAGS: -L${SRCDIR}/lib/linux-amd64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/linux-amd64
6+
#cgo linux,musl LDFLAGS: -L${SRCDIR}/lib/linux-musl-amd64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/linux-musl-amd64
7+
#cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/darwin-amd64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/darwin-amd64
8+
#cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/lib/darwin-aarch64 -lkos_mobile -Wl,-rpath,${SRCDIR}/lib/darwin-aarch64
99
#include "kos_mobile.h"
1010
#include <stdlib.h>
1111
*/
-27.7 KB
Binary file not shown.
2.52 KB
Binary file not shown.

0 commit comments

Comments
 (0)