Skip to content

Commit

Permalink
refactor: client code (#384)
Browse files Browse the repository at this point in the history
* refactor: client code

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

* chore: bump kcl lib to v0.10.1-rc.3

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

---------

Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Sep 18, 2024
1 parent f633831 commit 6fc919c
Show file tree
Hide file tree
Showing 42 changed files with 1,549 additions and 11,916 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-file: go.mod

# 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-file: go.mod

- 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-file: go.mod

# Parallel tests
- run: go test ./...
- name: Go test
env:
CGO_ENABLED: ${{ matrix.cgo }}
run: go test ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ three = hello.add(1,2) # hello.add is written by Go
`
```

> Note: CGO is required when using plugins

## Documents

See the [KCL website](https://kcl-lang.io)
Expand Down
1 change: 0 additions & 1 deletion examples/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func main() {
// Note we use `native.MustRun` here instead of `kcl.MustRun`, because it needs the cgo feature.
yaml := kcl.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult()
fmt.Println(yaml)
}
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ require (
github.com/chai2010/protorpc v1.1.4
github.com/getkin/kin-openapi v0.127.0
github.com/goccy/go-yaml v1.12.0
github.com/gofrs/flock v0.12.1
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
github.com/iancoleman/strcase v0.3.0
github.com/julienschmidt/httprouter v1.3.0
github.com/mitchellh/mapstructure v1.5.0
github.com/powerman/rpc-codec v1.2.2
github.com/protocolbuffers/txtpbfmt v0.0.0-20240416193709-1e18ef0a7fdc
github.com/qri-io/jsonpointer v0.1.1
github.com/stretchr/testify v1.9.0
Expand All @@ -23,13 +21,14 @@ require (
google.golang.org/grpc v1.66.2
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
kcl-lang.io/lib v0.10.0
kcl-lang.io/lib v0.10.1-rc.3
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/ebitengine/purego v0.7.1 // indirect
github.com/emicklei/proto v1.13.2
github.com/fatih/color v1.15.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/chai2010/protorpc v1.1.4 h1:CTtFUhzXRoeuR7FtgQ2b2vdT/KgWVpCM+sIus8zJj
github.com/chai2010/protorpc v1.1.4/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
Expand All @@ -28,8 +30,6 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM=
github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
Expand Down Expand Up @@ -71,8 +71,6 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/powerman/rpc-codec v1.2.2 h1:BK0JScZivljhwW/vLLhZLtUgqSxc/CD3sHEs8LiwwKw=
github.com/powerman/rpc-codec v1.2.2/go.mod h1:3Qr/y/+u3CwcSww9tfJMRn/95lB2qUdUeIQe7BYlLDo=
github.com/protocolbuffers/txtpbfmt v0.0.0-20240416193709-1e18ef0a7fdc h1:DRZwH75/E4a2SOr7+gKZ99OEhmjzBzAhgyTnzo1TepY=
github.com/protocolbuffers/txtpbfmt v0.0.0-20240416193709-1e18ef0a7fdc/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/qri-io/jsonpointer v0.1.1 h1:prVZBZLL6TW5vsSB9fFHFAMBLI4b0ri5vribQlTJiBA=
Expand Down Expand Up @@ -115,5 +113,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 h1:VLwZTMfRZyaGfIJc8qxLn7bKr24PSgZLc3SxMRxUaN4=
kcl-lang.io/lib v0.10.0/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
kcl-lang.io/lib v0.10.1-rc.3 h1:+3sCOLV3ay9JHwvaZKOJgX9hwb2MO5OiGbAtsNLH5E4=
kcl-lang.io/lib v0.10.1-rc.3/go.mod h1:MfVEiCo3Yr6jZqwSo84WmjFZdqNRtXMbGtDwUM27kTY=
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.

13 changes: 0 additions & 13 deletions pkg/kcl/rpc_service.go

This file was deleted.

11 changes: 3 additions & 8 deletions pkg/kcl/service.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
//go:build !rpc && cgo
// +build !rpc,cgo

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 6fc919c

Please sign in to comment.