35 lines
943 B
Go
35 lines
943 B
Go
|
package sdk
|
||
|
|
||
|
import (
|
||
|
"code.icb4dc0.de/buildr/wasi-module-sdk/internal/mem"
|
||
|
rpcv1 "code.icb4dc0.de/buildr/wasi-module-sdk/protocol/generated/rpc/v1"
|
||
|
"context"
|
||
|
"github.com/mailru/easyjson"
|
||
|
_ "github.com/tetratelabs/tinymem"
|
||
|
)
|
||
|
|
||
|
var defaultRegistry = NewTypeRegistry()
|
||
|
|
||
|
func Register(cat Category, moduleName string, factory Factory) {
|
||
|
defaultRegistry.Add(cat, moduleName, factory)
|
||
|
}
|
||
|
|
||
|
//export run
|
||
|
func Run(specPtr, specSize uint32) {
|
||
|
var startTask rpcv1.StartTaskRequest
|
||
|
|
||
|
if err := startTask.UnmarshalVT(mem.DataFromPtr(specPtr, specSize)); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
executor := NewExecutor(startTask.Buildr.Repo.Root, "", "")
|
||
|
reference := startTask.GetReference()
|
||
|
module := defaultRegistry.Get(Category(reference.GetModuleCategory()), reference.GetModuleType())
|
||
|
|
||
|
if err := easyjson.Unmarshal(startTask.RawTask, module); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
executor.Run(context.Background(), startTask.Reference.ModuleName, module)
|
||
|
}
|