chore: update API and common references

This commit is contained in:
Peter 2023-09-12 18:08:28 +02:00
parent 04644e99d9
commit 634d4eb441
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
3 changed files with 36 additions and 6 deletions

View file

@ -12,10 +12,11 @@ import (
)
var (
defaultRegistry = NewTypeRegistry()
startTaskWrapper = FuncExportWrapper[*remotev1.StartTaskRequest, *wasiv1.StartTaskResponse](StartTask)
inventoryWrapper = FuncExportWrapper[*wasiv1.PluginInventoryRequest, *wasiv1.PluginInventoryResponse](GetInventory)
helpForWrapper = FuncExportWrapper[*wasiv1.HelpRequest, *wasiv1.HelpResponse](HelpForModule)
defaultRegistry = NewTypeRegistry()
startTaskWrapper = FuncExportWrapper[*remotev1.StartTaskRequest, *wasiv1.StartTaskResponse](StartTask)
inventoryWrapper = FuncExportWrapper[*wasiv1.PluginInventoryRequest, *wasiv1.PluginInventoryResponse](GetInventory)
helpForWrapper = FuncExportWrapper[*wasiv1.HelpRequest, *wasiv1.HelpResponse](HelpForModule)
binaryNameWrapper = FuncExportWrapper[*wasiv1.BinaryNameRequest, *wasiv1.BinaryNameResponse](BinaryNameForModule)
)
func Register(cat Category, moduleName string, factory Factory) {
@ -106,6 +107,26 @@ func HelpForModule(helpRequest *wasiv1.HelpRequest) (*wasiv1.HelpResponse, error
return helpResponse, nil
}
func BinaryNameForModule(req *wasiv1.BinaryNameRequest) (*wasiv1.BinaryNameResponse, error) {
module := defaultRegistry.Get(req.ModuleReference.ModuleCategory, req.ModuleReference.ModuleType)
if module == nil {
return nil, errors.New("unknown module")
}
namer, ok := module.(BinaryNamer)
if !ok {
return new(wasiv1.BinaryNameResponse), nil
}
if err := protocol.Unmarshal(req.GetSpec(), module); err != nil {
return nil, err
}
return &wasiv1.BinaryNameResponse{
Name: namer.BinaryName(),
}, nil
}
//export /buildr.rpc.v1.WasiExecutorService/PluginInventory
func Inventory(ptr, size uint32) uint64 {
return inventoryWrapper.Call(ptr, size)
@ -120,3 +141,8 @@ func Run(ptr, size uint32) uint64 {
func HelpFor(ptr, size uint32) uint64 {
return helpForWrapper.Call(ptr, size)
}
//export /buildr.rpc.v1.WasiExecutorService/BinaryName
func BinaryNameFor(ptr, size uint32) uint64 {
return binaryNameWrapper.Call(ptr, size)
}

4
go.mod
View file

@ -3,8 +3,8 @@ module code.icb4dc0.de/buildr/wasi-module-sdk-go
go 1.21
require (
code.icb4dc0.de/buildr/api v0.0.0-20230905195458-e4d230e5c7fd
code.icb4dc0.de/buildr/common v0.0.0-20230905195627-a3d5bb4f1ee7
code.icb4dc0.de/buildr/api v0.0.0-20230912160519-4b705a6732bc
code.icb4dc0.de/buildr/common v0.0.0-20230912160755-da17cbfde028
)
require (

4
go.sum
View file

@ -1,7 +1,11 @@
code.icb4dc0.de/buildr/api v0.0.0-20230905195458-e4d230e5c7fd h1:N4WkVoqphjFXfFwfKpLcEtS5lBCfd9NVytUutiszQ90=
code.icb4dc0.de/buildr/api v0.0.0-20230905195458-e4d230e5c7fd/go.mod h1:eWSjeX25XbbNGKlxVoOf2a8V6xOCIaQh5W65T7nNcL8=
code.icb4dc0.de/buildr/api v0.0.0-20230912160519-4b705a6732bc h1:NpOz5K0Oo/WFWBRsBKf92MTX9iW+sqaImwMuU33z6/s=
code.icb4dc0.de/buildr/api v0.0.0-20230912160519-4b705a6732bc/go.mod h1:eWSjeX25XbbNGKlxVoOf2a8V6xOCIaQh5W65T7nNcL8=
code.icb4dc0.de/buildr/common v0.0.0-20230905195627-a3d5bb4f1ee7 h1:sqBO2IFI0Gs+FiM4kkQjj7QkC0p+AhJKqhCQqCEwlM4=
code.icb4dc0.de/buildr/common v0.0.0-20230905195627-a3d5bb4f1ee7/go.mod h1:biIRy/mBiVPAR/okWN5DFmB3Hnnxt2FP1Qswa4GBMeE=
code.icb4dc0.de/buildr/common v0.0.0-20230912160755-da17cbfde028 h1:12xr1rT8faxqY7QqI7Z4nlKw1UdQZNfAtv4FybTPtwk=
code.icb4dc0.de/buildr/common v0.0.0-20230912160755-da17cbfde028/go.mod h1:GMFttKFr14bCsjGHbq1tUCOuru7AqBkELvsk2Xhn0Bw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=