diff --git a/Makefile b/Makefile index e52b97b..f08ed28 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -.PHONY: all init generate build build-wasm test test-cover lint fmt vet clean tidy help +.PHONY: all generate build build-debug build-opt test test-cover test-plugin lint fmt vet clean tidy deps verify help MODULE := enclave -BINARY := enclave +BINARY := enclave.wasm BUILD_DIR := build +TINYGO_FLAGS := -target=wasip1 -scheduler=none -gc=leaking all: generate build @@ -11,11 +12,16 @@ generate: build: @mkdir -p $(BUILD_DIR) - @go build -o $(BUILD_DIR)/$(BINARY) ./... + @tinygo build $(TINYGO_FLAGS) -o $(BUILD_DIR)/$(BINARY) . -build-wasm: +build-debug: @mkdir -p $(BUILD_DIR) - @GOOS=js GOARCH=wasm go build -o $(BUILD_DIR)/$(BINARY).wasm ./... + @tinygo build $(TINYGO_FLAGS) -no-debug=false -o $(BUILD_DIR)/$(BINARY) . + +build-opt: + @mkdir -p $(BUILD_DIR) + @tinygo build $(TINYGO_FLAGS) -opt=2 -o $(BUILD_DIR)/$(BINARY) . + @wasm-opt -Os $(BUILD_DIR)/$(BINARY) -o $(BUILD_DIR)/$(BINARY) test: @go test -v ./... @@ -24,6 +30,9 @@ test-cover: @go test -coverprofile=coverage.out ./... @go tool cover -html=coverage.out -o coverage.html +test-plugin: + @extism call $(BUILD_DIR)/$(BINARY) generate --input '{}' --wasi + lint: @golangci-lint run ./... @@ -45,21 +54,30 @@ deps: @go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest @go install mvdan.cc/gofumpt@latest + @echo "Install TinyGo: https://tinygo.org/getting-started/install/" + @echo "Install Extism CLI: https://extism.org/docs/install" verify: fmt vet lint test help: - @echo "Available targets:" - @echo " init - Initialize Go module" + @echo "Motr Enclave - Extism Plugin (TinyGo/wasip1)" + @echo "" + @echo "Build targets:" + @echo " build - Build WASM plugin with TinyGo" + @echo " build-debug - Build with debug symbols" + @echo " build-opt - Build optimized (requires wasm-opt)" + @echo "" + @echo "Development targets:" @echo " generate - Run sqlc to generate Go code" - @echo " build - Build binary" - @echo " build-wasm - Build WASM binary" - @echo " test - Run tests" + @echo " test - Run tests with Go" @echo " test-cover - Run tests with coverage" + @echo " test-plugin - Test plugin with Extism CLI" @echo " lint - Run golangci-lint" @echo " fmt - Format code" @echo " vet - Run go vet" + @echo " verify - Run fmt, vet, lint, and test" + @echo "" + @echo "Utility targets:" @echo " clean - Remove build artifacts" @echo " tidy - Run go mod tidy" @echo " deps - Install development dependencies" - @echo " verify - Run fmt, vet, lint, and test" diff --git a/go.mod b/go.mod index 2c713f3..b3fa137 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module enclave go 1.25.5 + +require github.com/extism/go-pdk v1.1.3 // indirect