From 3aed80812e105cd99c43f11023012608aecd9f4a Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 25 Oct 2023 19:41:47 +0100 Subject: Add a component model example This adds the 'Hello World' example from here[0]. The runtime is in Rust and the component is in C. This requires some new tools - https://github.com/bytecodealliance/wit-bindgen - https://github.com/bytecodealliance/wasm-tools You can use the pre-built packages, once downloaded and untar'd, edit rust/hello_world/component/Makefile and adjust the paths for the above tools. To build the component with make you may need to specify where the WASI sysroot is $ make WASI_SYSROOT=/path/to/wasi-sysroot [0]: Signed-off-by: Andrew Clayton --- rust/hello_world/component/Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rust/hello_world/component/Makefile (limited to 'rust/hello_world/component/Makefile') diff --git a/rust/hello_world/component/Makefile b/rust/hello_world/component/Makefile new file mode 100644 index 0000000..a7f3f85 --- /dev/null +++ b/rust/hello_world/component/Makefile @@ -0,0 +1,27 @@ +# Look for wasi-sysroot in some common places, falling back +# to provided WASI_SYSROOT +ifneq ("$(wildcard /usr/wasm32-wasi)", "") + # Fedora + WASI_SYSROOT ?= /usr/wasm32-wasi +else ifneq ("$(wildcard /usr/local/share/wasi-sysroot)", "") + # FreeBSD + WASI_SYSROOT ?= /usr/local/share/wasi-sysroot +endif + +export WASI_SYSROOT + +CC = clang +CFLAGS = -Wall -Wextra --target=wasm32-wasi --sysroot=$(WASI_SYSROOT) +LDFLAGS = -Wl,--no-entry -mexec-model=reactor --rtlib=compiler-rt + +all: hello_world.wasm + +bindgen: + /home/andrew/src/c/wasm/wit-bindgen-v0.13.0-x86_64-linux/wit-bindgen c ../wit + +hello_world.wasm: bindgen my-component.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ hello_world.c hello_world_component_type.o my-component.c + /home/andrew/src/c/wasm/wasm-tools-1.0.48-x86_64-linux/wasm-tools component new hello_world.wasm -o hello_world-component.wasm + +clean: + rm -f hello_world* -- cgit