package sdk import ( "context" "encoding/json" _ "github.com/tetratelabs/tinymem" "code.icb4dc0.de/buildr/wasi-module-sdk-go/mem" rpcv1 "code.icb4dc0.de/buildr/wasi-module-sdk-go/protocol/generated/rpc/v1" ) var defaultRegistry = NewTypeRegistry() func Register(cat Category, moduleName string, factory Factory) { defaultRegistry.Add(cat, moduleName, factory) } //go:wasmimport inventory func Inventory() uint64 { var inventory rpcv1.PluginInventory for _, t := range defaultRegistry.List() { inventory.Modules = append(inventory.Modules, &rpcv1.ModuleReference{ ModuleCategory: t.Category.String(), ModuleType: t.Type, }) } data, err := inventory.MarshalVT() if err != nil { panic(err) } return mem.UnifyPtrSize(mem.DataToUnmanagedPtr(data)) } //go:wasmimport 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, startTask.Buildr.OutDir, startTask.Buildr.BinDir) reference := startTask.GetReference().GetModule() module := defaultRegistry.Get(Category(reference.GetModuleCategory()), reference.GetModuleType()) if err := json.Unmarshal(startTask.RawTask, module); err != nil { panic(err) } executor.Run(context.Background(), module) }