diff --git a/Makefile b/Makefile index af90bbb..2689647 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -.PHONY: all generate build build-debug build-opt test test-cover test-plugin test-browser lint fmt vet clean tidy deps verify serve help +.PHONY: all generate build build-debug build-opt test test-cover test-plugin lint fmt vet clean tidy deps verify serve help MODULE := enclave BINARY := enclave.wasm -BUILD_DIR := build +BUILD_DIR := example all: generate build @@ -10,15 +10,12 @@ generate: @sqlc generate build: - @mkdir -p $(BUILD_DIR) @GOOS=wasip1 GOARCH=wasm go build -o $(BUILD_DIR)/$(BINARY) . build-debug: - @mkdir -p $(BUILD_DIR) @GOOS=wasip1 GOARCH=wasm go build -gcflags="all=-N -l" -o $(BUILD_DIR)/$(BINARY) . build-opt: - @mkdir -p $(BUILD_DIR) @GOOS=wasip1 GOARCH=wasm go build -ldflags="-s -w" -o $(BUILD_DIR)/$(BINARY) . @wasm-opt -Os $(BUILD_DIR)/$(BINARY) -o $(BUILD_DIR)/$(BINARY) @@ -32,13 +29,9 @@ test-cover: test-plugin: @extism call $(BUILD_DIR)/$(BINARY) generate --input '{"credential":"dGVzdA=="}' --wasi -test-browser: build - @echo "Open http://localhost:8080/example/ in your browser" - @python3 -m http.server 8080 - serve: build @echo "Open http://localhost:8080/example/ in your browser" - @python3 -m http.server 8080 + @python3 -m http.server 8080 -d example lint: @golangci-lint run ./... @@ -51,7 +44,7 @@ vet: @go vet ./... clean: - @rm -rf $(BUILD_DIR) + @rm -f $(BUILD_DIR)/$(BINARY) @rm -f coverage.out coverage.html tidy: @@ -78,8 +71,7 @@ help: @echo " test - Run tests" @echo " test-cover - Run tests with coverage" @echo " test-plugin - Test plugin with Extism CLI" - @echo " test-browser- Build and serve for browser testing" - @echo " serve - Start local server for example/" + @echo " serve - Build and serve example/ for browser testing" @echo " lint - Run golangci-lint" @echo " fmt - Format code" @echo " vet - Run go vet" diff --git a/build/enclave.wasm b/build/enclave.wasm deleted file mode 100755 index e27fb2f..0000000 Binary files a/build/enclave.wasm and /dev/null differ diff --git a/example/test.js b/example/test.js index 91126c3..9537320 100644 --- a/example/test.js +++ b/example/test.js @@ -1,4 +1,4 @@ -import createPlugin from 'https://esm.sh/@extism/extism@1.0.0/dist/browser/mod.js'; +import createPlugin from '@extism/extism'; let plugin = null; let generatedDatabase = null; @@ -35,7 +35,14 @@ async function loadPlugin() { log('Loading enclave.wasm...'); try { - plugin = await createPlugin('../build/enclave.wasm', { + const wasmUrl = new URL('./enclave.wasm', window.location.href).href; + log(`WASM URL: ${wasmUrl}`); + + const manifest = { + wasm: [{ url: wasmUrl }] + }; + + plugin = await createPlugin(manifest, { useWasi: true, logger: console });