Skip to content
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
91 changes: 86 additions & 5 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,98 @@ jobs:
test:
strategy:
matrix:
os: [macos-13, macos-13, macos-13-xlarge, macos-14, macos-latest, ubuntu-22.04, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
include:
# macOS Intel/ARM configurations

- os: macos-13
runner: macos-13
cgo_enabled: 0

- os: macos-13-xlarge
runner: macos-13
cgo_enabled: 0

- os: macos-14
runner: macos-14
cgo_enabled: 0

- os: macos-latest
runner: macos-latest
cgo_enabled: 0

# Ubuntu configurations

- os: ubuntu-22.04
runner: ubuntu-22.04
cgo_enabled: 0

- os: ubuntu-latest
runner: ubuntu-latest
cgo_enabled: 0

# Windows configurations

- os: windows-latest
runner: windows-latest
cgo_enabled: 0

# Alpine Linux container configurations
- os: alpine-latest
runner: ubuntu-latest # Host runner for the container
container: golang:1.23-alpine3.19
cgo_enabled: 1

runs-on: ${{ matrix.runner }}
container: ${{ matrix.container }}
defaults:
run:
working-directory: "go"

steps:
- name: Git checkout
uses: actions/checkout@v6
- name: Set up Go

- name: Set up Go (non-musl)
if: matrix.container == null
uses: actions/setup-go@v6
with:
go-version: 1.23
- name: Go code test
run: go test ./...
cache: true

- name: Install musl dependencies (Alpine container)
if: matrix.container != null
run: |
apk add --no-cache \
musl-dev \
gcc \
git \
make

- name: Go mod tidy
run: go mod tidy

- name: Setup build tags for Alpine
if: matrix.container != null
run: |
echo "GO_BUILD_TAGS=musl netgo static osusergo" >> $GITHUB_ENV
echo "GO_LDFLAGS=-linkmode external -extldflags '-static'" >> $GITHUB_ENV

- name: Go code test (CGO_ENABLED=${{ matrix.cgo_enabled }})
if: matrix.os != 'windows-latest'
run: |
if [ -n "${{ matrix.container }}" ]; then
BUILD_TAGS="$GO_BUILD_TAGS"
EXTRA_LDFLAGS="$GO_LDFLAGS"
fi

CGO_ENABLED=${{ matrix.cgo_enabled }} \
go test ./... -v \
-tags="${BUILD_TAGS}" \
-ldflags="${EXTRA_LDFLAGS}"
env:
CGO_LDFLAGS: ${{ matrix.cgo_enabled == '1' && '-static' || '' }}

- name: Go code test (CGO_ENABLED=${{ matrix.cgo_enabled }}) on Windows
if: matrix.os == 'windows-latest'
run: |
go test ./... -v
1 change: 0 additions & 1 deletion go/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

!lib/**/*.dylib
!lib/**/*.dll
!lib/**/*.lib
Expand Down
29 changes: 29 additions & 0 deletions go/include/kcl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _KCL_H
#define _KCL_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef uintptr_t KclServiceHandle;

KclServiceHandle kcl_service_new(uint64_t plugin_agent);
void kcl_service_delete(KclServiceHandle svc);
uint8_t* kcl_service_call_with_length(
KclServiceHandle svc,
const char* method,
const char* args,
uint32_t args_len,
uint32_t* out_len
);
void kcl_free(uint8_t* ptr, uint32_t len);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* _KCL_H */
8 changes: 0 additions & 8 deletions go/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package install
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"

Expand All @@ -12,13 +11,6 @@ import (

const KCL_VERSION = "v0.12.1"

func findPath(name string) string {
if path, err := exec.LookPath(name); err == nil {
return path
}
return ""
}

func getVersion() string {
return fmt.Sprintf("%s-%s-%s", KCL_VERSION, runtime.GOOS, runtime.GOARCH)
}
Expand Down
51 changes: 0 additions & 51 deletions go/install/install_bin_unix.go

This file was deleted.

38 changes: 0 additions & 38 deletions go/install/install_bin_windows.go

This file was deleted.

Binary file added go/lib/linux-musl-amd64/libkcl.a
Binary file not shown.
Binary file added go/lib/linux-musl-arm64/libkcl.a
Binary file not shown.
63 changes: 0 additions & 63 deletions go/native/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,18 @@ package native
import (
"bytes"
"errors"
"runtime"
"strings"
"sync"
"unsafe"

"github.com/ebitengine/purego"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"kcl-lang.io/lib/go/api"
"kcl-lang.io/lib/go/plugin"
)

var libInit sync.Once

var (
client *NativeServiceClient
lib uintptr
serviceNew func(uint64) uintptr
serviceDelete func(uintptr)
serviceCall func(uintptr, string, string, uint, *uint) uintptr
free func(uintptr, uint)
)

type validator interface {
Validate() error
}

type NativeServiceClient struct {
svc uintptr
}

func initClient(pluginAgent uint64) {
libInit.Do(func() {
lib, err := loadServiceNativeLib()
if err != nil {
panic(err)
}
purego.RegisterLibFunc(&serviceNew, lib, "kcl_service_new")
purego.RegisterLibFunc(&serviceDelete, lib, "kcl_service_delete")
purego.RegisterLibFunc(&serviceCall, lib, "kcl_service_call_with_length")
purego.RegisterLibFunc(&free, lib, "kcl_free")
client = new(NativeServiceClient)
client.svc = serviceNew(pluginAgent)
runtime.SetFinalizer(client, func(x *NativeServiceClient) {
if x != nil {
x.Close()
}
})
})
}

func NewNativeServiceClient() api.ServiceClient {
return NewNativeServiceClientWithPluginAgent(plugin.GetInvokeJsonProxyPtr())
}

func NewNativeServiceClientWithPluginAgent(pluginAgent uint64) *NativeServiceClient {
initClient(pluginAgent)
return client
}

func (x *NativeServiceClient) Close() {
serviceDelete(x.svc)
closeLibrary(lib)
}

func cApiCall[I interface {
*TI
proto.Message
Expand Down Expand Up @@ -131,16 +78,6 @@ func (c *NativeServiceClient) ExecProgram(in *api.ExecProgramArgs) (*api.ExecPro
return cApiCall[*api.ExecProgramArgs, *api.ExecProgramResult](c, "KclService.ExecProgram", in)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.12.1.
func (c *NativeServiceClient) BuildProgram(in *api.BuildProgramArgs) (*api.BuildProgramResult, error) {
return cApiCall[*api.BuildProgramArgs, *api.BuildProgramResult](c, "KclService.BuildProgram", in)
}

// Depreciated: Please use the env.EnableFastEvalMode() and c.ExecutProgram method and will be removed in v0.12.1.
func (c *NativeServiceClient) ExecArtifact(in *api.ExecArtifactArgs) (*api.ExecProgramResult, error) {
return cApiCall[*api.ExecArtifactArgs, *api.ExecProgramResult](c, "KclService.ExecArtifact", in)
}

func (c *NativeServiceClient) ParseFile(in *api.ParseFileArgs) (*api.ParseFileResult, error) {
return cApiCall[*api.ParseFileArgs, *api.ParseFileResult](c, "KclService.ParseFile", in)
}
Expand Down
2 changes: 1 addition & 1 deletion go/native/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ n = Name {name = "name"}` // Sample KCL source code
}
}

func ParseFileASTJson(filename string, src interface{}) (result string, err error) {
func ParseFileASTJson(filename string, src any) (result string, err error) {
var code string
if src != nil {
switch src := src.(type) {
Expand Down
Loading
Loading