refactor(build): add c-shared buildmode to wasm plugin compilation

This commit is contained in:
2026-01-07 18:49:14 -05:00
parent 2a0fa9ebf8
commit fff50da2b4
2 changed files with 15 additions and 15 deletions

View File

@@ -15,7 +15,7 @@ deps:
build:
@echo "Building WASM plugin..."
@GOOS=wasip1 GOARCH=wasm go build -o $(BUILD_DIR)/$(BINARY) .
@GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o $(BUILD_DIR)/$(BINARY) .
@echo "Built $(BUILD_DIR)/$(BINARY)"
sdk:

28
main.go
View File

@@ -205,25 +205,29 @@ func exec() int32 {
pdk.Log(pdk.LogInfo, "exec: executing action")
if !enclave.initialized {
pdk.SetError(errors.New("exec: database not initialized, call generate or load first"))
return 1
output := ExecOutput{Success: false, Error: "database not initialized, call generate or load first"}
pdk.OutputJSON(output)
return 0
}
var input ExecInput
if err := pdk.InputJSON(&input); err != nil {
pdk.SetError(fmt.Errorf("exec: failed to parse input: %w", err))
return 1
output := ExecOutput{Success: false, Error: fmt.Sprintf("failed to parse input: %s", err)}
pdk.OutputJSON(output)
return 0
}
if input.Filter == "" {
pdk.SetError(errors.New("exec: filter is required"))
return 1
output := ExecOutput{Success: false, Error: "filter is required"}
pdk.OutputJSON(output)
return 0
}
params, err := parseFilter(input.Filter)
if err != nil {
pdk.SetError(fmt.Errorf("exec: invalid filter: %w", err))
return 1
output := ExecOutput{Success: false, Error: fmt.Sprintf("invalid filter: %s", err)}
pdk.OutputJSON(output)
return 0
}
if input.Token != "" {
@@ -252,11 +256,7 @@ func exec() int32 {
Result: result,
}
if err := pdk.OutputJSON(output); err != nil {
pdk.SetError(fmt.Errorf("exec: failed to output result: %w", err))
return 1
}
pdk.OutputJSON(output)
pdk.Log(pdk.LogInfo, fmt.Sprintf("exec: completed %s on %s", params.Action, params.Resource))
return 0
}
@@ -266,7 +266,7 @@ func query() int32 {
pdk.Log(pdk.LogInfo, "query: resolving DID document")
if !enclave.initialized {
pdk.SetError(errors.New("query: database not initialized, call generate or load first"))
pdk.SetError(errors.New("database not initialized, call generate or load first"))
return 1
}