Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/compose/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SHELL:=/usr/bin/env bash
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SERVER_COMPONENT_NAME := server.component.wasm
GO_COMPONENT_NAME := add.wasm
SERVER_COMPONENT_NAME := frontend.wasm
GO_COMPONENT_NAME := service.wasm
SERVER_COMPONENT_PATH := $(ROOT_DIR)/app-js/$(SERVER_COMPONENT_NAME)
GO_COMPONENT_PATH := $(ROOT_DIR)/service-go/$(GO_COMPONENT_NAME)
COMPOSED_COMPONENT_PATH := $(ROOT_DIR)/composed.wasm
Expand All @@ -19,23 +19,23 @@ build: build-js build-go build-compose ## Run all build steps.
.PHONY: build-js
build-js: ## Build the JavaScript component.
$(info "Building JavaScript Component...")
@cd "$(ROOT_DIR)/app-js" && npm install && npm run build
@cd "$(ROOT_DIR)/app-js" && npm install && COMPONENT_NAME=frontend.wasm npm run build

.PHONY: build-go
build-go: ## Build the Go component.
$(info "Building Golang Component...")
@cd $(ROOT_DIR)/service-go && go generate && tinygo build -target=wasip2 -o add.wasm --wit-package ./wit --wit-world adder service.go
@cd $(ROOT_DIR)/service-go && go generate && tinygo build -target=wasip2 -o service.wasm --wit-package ./wit --wit-world backend service.go

.PHONY: build-compose
build-compose: ## Compose the microservice app with the constituent components.
$(info "Fusing components together with wac...")
# @wac plug --plug $(GO_COMPONENT_PATH) -o composed.wasm $(SERVER_COMPONENT_PATH)
wac compose --dep example:math=$(GO_COMPONENT_PATH) --dep example:server=$(SERVER_COMPONENT_PATH) -o composed.wasm compose.wac
wac compose --dep example:service=$(GO_COMPONENT_PATH) --dep example:server=$(SERVER_COMPONENT_PATH) -o composed.wasm compose.wac

.PHONY: run
run: ## Run the microservice app after build.
$(info "Running Component Application Using Wasmtime...")
wasmtime serve -S cli $(COMPOSED_COMPONENT_PATH)
wasmtime serve -S cli --env OPENAI_API_KEY="$${OPENAI_API_KEY}" $(COMPOSED_COMPONENT_PATH)

.PHONY: build-and-run
build-and-run: build run ## Build and run the microservice app.
Expand Down
1 change: 1 addition & 0 deletions apps/compose/app-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
3 changes: 2 additions & 1 deletion apps/compose/app-js/componentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { componentize } from "@bytecodealliance/componentize-js";
// AoT compilation makes use of weval (https://github.com/bytecodealliance/weval)
const enableAot = process.env.ENABLE_AOT == "1";

const jsSource = await readFile("server.js", "utf8");
const jsSource = await readFile("./dist/index.js", "utf8");

const { component } = await componentize(jsSource, {
witPath: resolve("wit"),
debug: true,
enableAot,
});

Expand Down
Loading