Skip to content

Commit

Permalink
chore: bump kcl lib version to v0.10.0-alpha.1 and sync the C API in …
Browse files Browse the repository at this point in the history
…the native client

Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 24, 2024
1 parent 63b4a9e commit fb28233
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
kcl-lang.io/kpm v0.9.2
kcl-lang.io/lib v0.9.3
kcl-lang.io/lib v0.10.0-alpha.1
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,8 @@ k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrD
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kcl-lang.io/kpm v0.9.2 h1:TNQLFWEYj9MEFZXpHGhp4/PHAv3eBogOjpYDyMIFZsU=
kcl-lang.io/kpm v0.9.2/go.mod h1:4HTbPhB4DVtkamnIv5lrRcHtCVwzp4Pf/b+d3TN4nzs=
kcl-lang.io/lib v0.9.3 h1:Mlr+H0oaxujUQi6QD6eP+Fbi1waVsRWXddIzQhddK+Y=
kcl-lang.io/lib v0.9.3/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
kcl-lang.io/lib v0.10.0-alpha.1 h1:GMVB75Pc1W29gcl1WlVgdgUscH6h+d9No0fzBH0rNYg=
kcl-lang.io/lib v0.10.0-alpha.1/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo=
oras.land/oras-go v1.2.5/go.mod h1:PuAwRShRZCsZb7g8Ar3jKKQR/2A/qN+pkYxIOd/FAoo=
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=
Expand Down
40 changes: 36 additions & 4 deletions kclvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,39 @@ func TestGetSchemaType(t *testing.T) {
}

func TestGetSchemaTypeMapping(t *testing.T) {
result, err := kcl.GetSchemaTypeMapping("test.k", "schema Person:\n name: str", "")
result, err := kcl.GetSchemaTypeMapping("test.k", "schema Person:\n name: str\n\nschema Sub(Person):\n count: int\n", "")
if err != nil {
t.Fatal(err)
}
personSchema := gpyrpc.KclType{
Filename: "test.k",
PkgPath: "__main__",
Type: "schema",
SchemaName: "Person",
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
},
},
Required: []string{"name"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
}
assert2.Equal(t, map[string]*gpyrpc.KclType{
"Person": {
"Person": &personSchema,
"Sub": {
Filename: "test.k",
PkgPath: "__main__",
Type: "schema",
SchemaName: "Person",
SchemaName: "Sub",
BaseSchema: &personSchema,
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Expand All @@ -400,8 +423,17 @@ func TestGetSchemaTypeMapping(t *testing.T) {
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
},
"count": {
Type: "int",
Line: 2,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
},
},
Required: []string{"name"},
Required: []string{"count", "name"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Expand Down
6 changes: 3 additions & 3 deletions pkg/native/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void kclvm_service_free_string(void *f,const char * res) {
free_string = (void (*)(const char *))f;
return free_string(res);
}
const char* kclvm_service_call_with_length(void *f,kclvm_service* c,const char * method,const char * args,size_t * result_len){
const char* kclvm_service_call_with_length(void *f,kclvm_service* c,const char * method,const char * args,size_t args_len,size_t * result_len){
const char* (*service_call_with_length)(kclvm_service*,const char *,const char *,size_t *);
service_call_with_length = (const char* (*)(kclvm_service*,const char *,const char *,size_t *))f;
return service_call_with_length(c,method,args,result_len);
Expand Down Expand Up @@ -75,7 +75,7 @@ func KclvmServiceFreeString(str *C.char) {

// KclvmServiceCall calls kclvm service by c api
// args should be serialized as protobuf byte stream
func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char) (*C.char, C.size_t) {
func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char, args_len C.size_t) (*C.char, C.size_t) {
const fnName = "kclvm_service_call_with_length"

serviceCall, err := lib.GetSymbolPointer(fnName)
Expand All @@ -85,6 +85,6 @@ func KclvmServiceCall(serv *C.kclvm_service, method *C.char, args *C.char) (*C.c
}

var size C.size_t = C.SIZE_MAX
buf := C.kclvm_service_call_with_length(serviceCall, serv, method, args, &size)
buf := C.kclvm_service_call_with_length(serviceCall, serv, method, args, args_len, &size)
return buf, size
}
2 changes: 1 addition & 1 deletion pkg/native/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func cApiCall[I interface {

defer C.free(unsafe.Pointer(cIn))

cOut, cOutSize := KclvmServiceCall(c.client, cCallName, cIn)
cOut, cOutSize := KclvmServiceCall(c.client, cCallName, cIn, C.size_t(len(inBytes)))

defer KclvmServiceFreeString(cOut)

Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/kclvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"kcl-lang.io/kcl-go/pkg/env"
"kcl-lang.io/kcl-go/pkg/logger"
"kcl-lang.io/kcl-go/pkg/path"
"kcl-lang.io/lib"
"kcl-lang.io/lib/go/install"
)

func init() {
Expand Down Expand Up @@ -46,7 +46,7 @@ func installKclArtifact() {
logger.GetLogger().Warningf("install kclvm failed: %s", err.Error())
}
// Install lib
err = lib.InstallKclvm(path)
err = install.InstallKclvm(path)
if err != nil {
logger.GetLogger().Warningf("install kclvm failed: %s", err.Error())
}
Expand Down

0 comments on commit fb28233

Please sign in to comment.