diff --git a/Makefile b/Makefile index f7715a40b..be3f5a415 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,7 @@ $(GOX): .PHONY: build-cross build-cross: $(GOX) clean $(SRC) $(ASSETS) $(WEB_ASSETS) - CGO_ENABLED=0 $(GOX) -parallel=3 -output="$(DISTDIR)/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' -ldflags '$(LDFLAGS)' . + CGO_ENABLED=1 $(GOX) -parallel=3 -output="$(DISTDIR)/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' -ldflags '$(LDFLAGS)' . .PHONY: dist dist: clean build-cross ## Build distribution diff --git a/go.mod b/go.mod index f140ca795..1423fdabd 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/pkg/errors v0.9.1 github.com/qri-io/starlib v0.5.0 + github.com/second-state/WasmEdge-go v0.13.0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cast v1.4.1 github.com/spf13/cobra v1.6.1 @@ -184,7 +185,6 @@ require ( github.com/robfig/cron v1.2.0 // indirect github.com/russross/blackfriday v1.6.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/second-state/WasmEdge-go v0.13.0 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/spf13/afero v1.8.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/transformer/external/wasmtransformer.go b/transformer/external/wasmtransformer.go index 225c42501..9215e2d66 100644 --- a/transformer/external/wasmtransformer.go +++ b/transformer/external/wasmtransformer.go @@ -20,6 +20,7 @@ import ( "encoding/binary" "encoding/json" "fmt" + "path/filepath" "sort" "strings" @@ -58,7 +59,7 @@ func (t *WASM) Init(tc transformertypes.Transformer, env *environment.Environmen t.Env = env t.WASMConfig = &WASMYamlConfig{} if err := common.GetObjFromInterface(t.Config.Spec.Config, t.WASMConfig); err != nil { - return fmt.Errorf("unable to load config for Transformer %+v into %T . Error: %q", t.Config.Spec.Config, t.WASMConfig, err) + return fmt.Errorf("unable to load config for Transformer %+v into %T . Error: %w", t.Config.Spec.Config, t.WASMConfig, err) } return nil @@ -99,7 +100,7 @@ func (t *WASM) DirectoryDetect(dir string) (map[string][]transformertypes.Artifa memData[len(dir)] = 0 directoryDetectOutput, dderr := vm.Execute("directoryDetect", dirPointer) if dderr != nil { - err = fmt.Errorf("failed to execute directoryDetect in the wasm module. Error : %s", dderr.Error()) + err = fmt.Errorf("failed to execute directoryDetect in the wasm module. Error : %w", dderr) return nil, err } directoryDetectOutputPointer := directoryDetectOutput[0].(int32) @@ -203,7 +204,10 @@ func (t *WASM) Transform(newArtifacts []transformertypes.Artifact, alreadySeenAr } logrus.Debug(string(memData)) var output transformertypes.TransformOutput - json.Unmarshal(memData, &output) + err = json.Unmarshal(memData, &output) + if err != nil { + return nil, nil, fmt.Errorf("failed to unmarshal transformer output: %w", err) + } pathMappings = append(pathMappings, output.PathMappings...) createdArtifacts = append(createdArtifacts, output.CreatedArtifacts...) return pathMappings, createdArtifacts, err @@ -221,7 +225,7 @@ func (t *WASM) initVm(preopens []string) (*wasmedge.VM, error) { preopens, ) - err := vm.LoadWasmFile(t.WASMConfig.WASMModule) + err := vm.LoadWasmFile(filepath.Join(t.Env.GetEnvironmentContext(), t.WASMConfig.WASMModule)) if err != nil { return nil, err }