Skip to content

Commit cb06050

Browse files
authored
Merge pull request #144 from Peefy/test-cgo-zigcc-cross-compile
test: cgo + zigcc cross compile
2 parents ec2d9af + 306f4a6 commit cb06050

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

.github/workflows/go-test.yaml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ jobs:
3636
uses: actions/setup-go@v2
3737
with:
3838
go-version: 1.22
39-
- uses: korandoru/setup-zig@v1
40-
with:
41-
zig-version: master
4239
- name: Ready msys2
4340
uses: msys2/setup-msys2@v2
4441
with:
@@ -49,3 +46,36 @@ jobs:
4946
if: matrix.os == 'windows-latest'
5047
- name: Go code test
5148
run: go test ./...
49+
50+
cross-compile-test:
51+
runs-on: macos-12
52+
defaults:
53+
run:
54+
working-directory: "go"
55+
steps:
56+
- name: Git checkout
57+
uses: actions/checkout@v2
58+
- name: Set up Go
59+
uses: actions/setup-go@v2
60+
with:
61+
go-version: 1.22
62+
- uses: korandoru/setup-zig@v1
63+
with:
64+
zig-version: master
65+
- name: Set output
66+
id: macos_sdk
67+
run: echo "path=$(xcrun --show-sdk-path)" >> $GITHUB_OUTPUT
68+
- name: Go cross compile test on Windows
69+
run: |
70+
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC='zig cc -target x86_64-windows-gnu' go build ./...
71+
- name: Go cross compile test on Linux
72+
run: |
73+
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC='zig cc -target x86_64-linux-musl' go build ./...
74+
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC='zig cc -target aarch64-linux-musl' go build ./...
75+
- name: Go cross compile test on Macos
76+
run: |
77+
export SDK_PATH=$(xcrun --show-sdk-path)
78+
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos-none -F'"${SDK_PATH}"'/System/Library/Frameworks' go build ./...
79+
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC='zig cc -target aarch64-macos-none -F'"${SDK_PATH}"'/System/Library/Frameworks' go build ./...
80+
env:
81+
SDK_PATH: ${{ steps.macos_sdk.outputs.path }}

go/plugin/plugin.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
extern char *kcl_go_plugin_proxy_func(char *method, char *args_json,
5+
char *kwargs_json);
6+
7+
uint64_t kcl_go_plugin_get_proxy_func_ptr() {
8+
return (uint64_t)(kcl_go_plugin_proxy_func);
9+
}

go/plugin/plugin.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ package plugin
88
/*
99
#include <stdint.h>
1010
#include <stdlib.h>
11-
char* kcl_go_capi_InvokeJsonProxy(
12-
char* method,
13-
char* args_json,
14-
char* kwargs_json
15-
);
16-
static uint64_t kcl_go_capi_getInvokeJsonProxyPtr() {
17-
return (uint64_t)(kcl_go_capi_InvokeJsonProxy);
18-
}
11+
12+
uint64_t kcl_go_plugin_get_proxy_func_ptr();
1913
*/
2014
import "C"
2115
import (
@@ -26,8 +20,8 @@ import (
2620

2721
const CgoEnabled = true
2822

29-
//export kcl_go_capi_InvokeJsonProxy
30-
func kcl_go_capi_InvokeJsonProxy(_method, _args_json, _kwargs_json *C.char) (result_json *C.char) {
23+
//export kcl_go_plugin_proxy_func
24+
func kcl_go_plugin_proxy_func(_method, _args_json, _kwargs_json *C.char) (result_json *C.char) {
3125
var method, args_json, kwargs_json string
3226

3327
if _method != nil {
@@ -45,7 +39,7 @@ func kcl_go_capi_InvokeJsonProxy(_method, _args_json, _kwargs_json *C.char) (res
4539
}
4640

4741
func GetInvokeJsonProxyPtr() uint64 {
48-
ptr := uint64(C.kcl_go_capi_getInvokeJsonProxyPtr())
42+
ptr := uint64(C.kcl_go_plugin_get_proxy_func_ptr())
4943
return ptr
5044
}
5145

0 commit comments

Comments
 (0)