Skip to content

Commit

Permalink
refactor: cgo usage and runtime code
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Sep 14, 2024
1 parent 28a0266 commit 6cb6ced
Show file tree
Hide file tree
Showing 35 changed files with 1,540 additions and 10,812 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main_darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
os: [ macos-12, macos-13, macos-13-xlarge, macos-14 ]
cgo: [ '1', '0' ]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
Expand All @@ -22,5 +23,7 @@ jobs:
with:
go-version: 1.22

# Parallel tests
- run: go test ./...
- name: Go test
env:
CGO_ENABLED: ${{ matrix.cgo }}
run: go test ./...
10 changes: 5 additions & 5 deletions .github/workflows/main_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-latest ]
cgo: [ '1', '0' ]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
Expand All @@ -21,11 +22,10 @@ jobs:
with:
go-version: 1.22

- name: CGO_ENABLED=0 go test
run: CGO_ENABLED=0 go test ./...

- name: CGO_ENABLED=1 go test
run: CGO_ENABLED=1 go test ./...
- name: Go test
env:
CGO_ENABLED: ${{ matrix.cgo }}
run: go test ./...

- run: go test -v -coverprofile=profile.cov ./...
- uses: shogo82148/actions-goveralls@v1
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/main_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ on:
- "releases/*"
jobs:
build-and-test:
runs-on: windows-2019
strategy:
matrix:
os: [ windows-latest, windows-2019 ]
cgo: [ '1', '0' ]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
uses: actions/checkout@v4
Expand All @@ -17,5 +21,7 @@ jobs:
with:
go-version: 1.22

# Parallel tests
- run: go test ./...
- name: Go test
env:
CGO_ENABLED: ${{ matrix.cgo }}
run: go test ./...
11 changes: 0 additions & 11 deletions kcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kcl-go/pkg/loader"
"kcl-lang.io/kcl-go/pkg/parser"
"kcl-lang.io/kcl-go/pkg/runtime"
"kcl-lang.io/kcl-go/pkg/tools/format"
"kcl-lang.io/kcl-go/pkg/tools/lint"
"kcl-lang.io/kcl-go/pkg/tools/list"
Expand Down Expand Up @@ -71,16 +70,6 @@ type (
ParseProgramResult = parser.ParseProgramResult
)

// InitKclvmPath init kclvm path.
func InitKclvmPath(kclvmRoot string) {
runtime.InitKclvmRoot(kclvmRoot)
}

// InitKclvmRuntime init kclvm process.
func InitKclvmRuntime(n int) {
runtime.InitRuntime(n)
}

// MustRun is like Run but panics if return any error.
func MustRun(path string, opts ...Option) *KCLResultList {
return kcl.MustRun(path, opts...)
Expand Down
17 changes: 0 additions & 17 deletions kcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ package kcl_test

import (
"bytes"
"flag"
"os"
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"
"testing"

Expand All @@ -25,21 +23,6 @@ import (
"kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
)

const tEnvNumCpu = "KCL_GO_API_TEST_NUM_CPU"

func TestMain(m *testing.M) {
flag.Parse()

if s := os.Getenv(tEnvNumCpu); s != "" {
if x, err := strconv.Atoi(s); err == nil {
println(tEnvNumCpu, "=", s)
kcl.InitKclvmRuntime(x)
}
}

os.Exit(m.Run())
}

func TestStreamResult(t *testing.T) {
file, err := filepath.Abs("./testdata/stream/one_stream.k")
if err != nil {
Expand Down
85 changes: 0 additions & 85 deletions pkg/3rdparty/dlopen/dlopen_unix.go

This file was deleted.

51 changes: 0 additions & 51 deletions pkg/3rdparty/dlopen/dlopen_windws.go

This file was deleted.

7 changes: 5 additions & 2 deletions pkg/kcl/rpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

package kcl

import "kcl-lang.io/kcl-go/pkg/service"
import (
"kcl-lang.io/kcl-go/pkg/service"
"kcl-lang.io/lib/go/api"
)

// Service returns the interaction interface between KCL Go SDK and KCL Rust core.
// When `go build tags=rpc` is opened, use the default RPC interaction logic to avoid CGO usage.
// When closed, use CGO and dynamic libraries to interact.
func Service() service.KclvmService {
func Service() api.ServiceClient {
return service.NewKclvmServiceClient()
}
6 changes: 3 additions & 3 deletions pkg/kcl/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
package kcl

import (
"kcl-lang.io/kcl-go/pkg/native"
"kcl-lang.io/kcl-go/pkg/service"
"kcl-lang.io/lib/go/api"
"kcl-lang.io/lib/go/native"
)

// Service returns the interaction interface between KCL Go SDK and KCL Rust core.
// When `go build tags=rpc` is opened, use the default RPC interaction logic to avoid CGO usage.
// When closed, use CGO and dynamic libraries to interact.
func Service() service.KclvmService {
func Service() api.ServiceClient {
return native.NewNativeServiceClient()
}
90 changes: 0 additions & 90 deletions pkg/native/cgo.go

This file was deleted.

Loading

0 comments on commit 6cb6ced

Please sign in to comment.