Skip to content

Commit

Permalink
refactor: cgo usage and runtime code (#379)
Browse files Browse the repository at this point in the history
* refactor: cgo usage and runtime code

Signed-off-by: peefy <xpf6677@163.com>

* chore: remove windows-2019 tests

Signed-off-by: peefy <xpf6677@163.com>

---------

Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Sep 14, 2024
1 parent 28a0266 commit cc2c515
Show file tree
Hide file tree
Showing 39 changed files with 1,544 additions and 13,197 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 ]
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 ./...
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
google.golang.org/grpc v1.66.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
kcl-lang.io/lib v0.10.0-rc.1
kcl-lang.io/lib v0.10.0-rc.2
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
kcl-lang.io/lib v0.10.0-rc.1 h1:HRHMW2ane3mjKMVBUQQVvln9Z7FDkUJVXRWEVXPtP+w=
kcl-lang.io/lib v0.10.0-rc.1/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
kcl-lang.io/lib v0.10.0-rc.2 h1:zMiwQVKzKqLD0gRPuKdDgX0MzbcWe8a+IlsXhhWeUvk=
kcl-lang.io/lib v0.10.0-rc.2/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
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()
}
Loading

0 comments on commit cc2c515

Please sign in to comment.