Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cgo + zigcc cross compile #144

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading