Skip to content

Commit

Permalink
Merge pull request #144 from Peefy/test-cgo-zigcc-cross-compile
Browse files Browse the repository at this point in the history
test: cgo + zigcc cross compile
  • Loading branch information
Peefy authored Sep 14, 2024
2 parents ec2d9af + 306f4a6 commit cb06050
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.22
- uses: korandoru/setup-zig@v1
with:
zig-version: master
- name: Ready msys2
uses: msys2/setup-msys2@v2
with:
Expand All @@ -49,3 +46,36 @@ jobs:
if: matrix.os == 'windows-latest'
- name: Go code test
run: go test ./...

cross-compile-test:
runs-on: macos-12
defaults:
run:
working-directory: "go"
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22
- uses: korandoru/setup-zig@v1
with:
zig-version: master
- name: Set output
id: macos_sdk
run: echo "path=$(xcrun --show-sdk-path)" >> $GITHUB_OUTPUT
- name: Go cross compile test on Windows
run: |
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC='zig cc -target x86_64-windows-gnu' go build ./...
- name: Go cross compile test on Linux
run: |
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC='zig cc -target x86_64-linux-musl' go build ./...
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC='zig cc -target aarch64-linux-musl' go build ./...
- name: Go cross compile test on Macos
run: |
export SDK_PATH=$(xcrun --show-sdk-path)
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC='zig cc -target x86_64-macos-none -F'"${SDK_PATH}"'/System/Library/Frameworks' go build ./...
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC='zig cc -target aarch64-macos-none -F'"${SDK_PATH}"'/System/Library/Frameworks' go build ./...
env:
SDK_PATH: ${{ steps.macos_sdk.outputs.path }}
9 changes: 9 additions & 0 deletions go/plugin/plugin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdint.h>
#include <stdlib.h>

extern char *kcl_go_plugin_proxy_func(char *method, char *args_json,
char *kwargs_json);

uint64_t kcl_go_plugin_get_proxy_func_ptr() {
return (uint64_t)(kcl_go_plugin_proxy_func);
}
16 changes: 5 additions & 11 deletions go/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ package plugin
/*
#include <stdint.h>
#include <stdlib.h>
char* kcl_go_capi_InvokeJsonProxy(
char* method,
char* args_json,
char* kwargs_json
);
static uint64_t kcl_go_capi_getInvokeJsonProxyPtr() {
return (uint64_t)(kcl_go_capi_InvokeJsonProxy);
}
uint64_t kcl_go_plugin_get_proxy_func_ptr();
*/
import "C"
import (
Expand All @@ -26,8 +20,8 @@ import (

const CgoEnabled = true

//export kcl_go_capi_InvokeJsonProxy
func kcl_go_capi_InvokeJsonProxy(_method, _args_json, _kwargs_json *C.char) (result_json *C.char) {
//export kcl_go_plugin_proxy_func
func kcl_go_plugin_proxy_func(_method, _args_json, _kwargs_json *C.char) (result_json *C.char) {
var method, args_json, kwargs_json string

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

func GetInvokeJsonProxyPtr() uint64 {
ptr := uint64(C.kcl_go_capi_getInvokeJsonProxyPtr())
ptr := uint64(C.kcl_go_plugin_get_proxy_func_ptr())
return ptr
}

Expand Down

0 comments on commit cb06050

Please sign in to comment.