From 4e6d7e87685c30a62a654fc91e271d34dd642202 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Tue, 6 Feb 2024 04:20:16 +0000 Subject: Wasm-wc: Wire it up to the build system Et voila... $ ./configure wasm-wasi-component configuring wasm-wasi-component module Looking for rust compiler ... found. Looking for cargo ... found. + wasm-wasi-component module: wasm_wasi_component.unit.so $ make install test -d /opt/unit/sbin || install -d /opt/unit/sbin install -p build/sbin/unitd /opt/unit/sbin/ test -d /opt/unit/state || install -d /opt/unit/state test -d /opt/unit || install -d /opt/unit test -d /opt/unit || install -d /opt/unit test -d /opt/unit/share/man/man8 || install -d /opt/unit/sh man/man8 install -p -m644 build/share/man/man8/unitd.8 /opt/unit/share/ma n8/ make build/src/nxt_unit.o make[1]: Entering directory '/home/andrew/src/unit' make[1]: 'build/src/nxt_unit.o' is up to date. make[1]: Leaving directory '/home/andrew/src/unit' cargo build --release --manifest-path src/wasm-wasi-component/Cargo.toml Finished release [optimized] target(s) in 0.55s install -d /opt/unit/modules install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \ /opt/unit/modules/wasm_wasi_component.unit.so Signed-off-by: Andrew Clayton --- auto/modules/wasm-wasi-component | 119 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 auto/modules/wasm-wasi-component (limited to 'auto/modules/wasm-wasi-component') diff --git a/auto/modules/wasm-wasi-component b/auto/modules/wasm-wasi-component new file mode 100644 index 00000000..1ec5841c --- /dev/null +++ b/auto/modules/wasm-wasi-component @@ -0,0 +1,119 @@ +# Copyright (C) Andrew Clayton +# Copyright (C) F5, Inc. + + +NXT_WCM_MODULE=wasm-wasi-component +NXT_WCM_MOD_NAME=`echo $NXT_WCM_MODULE | tr '-' '_'`.unit.so + + +shift + +for nxt_option; do + + case "$nxt_option" in + -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) value="" ;; + esac + + case "$nxt_option" in + + --help) + cat << END + +END + exit 0 + ;; + + *) + echo + echo $0: error: invalid $NXT_WCM_MODULE option \"$nxt_option\" + echo + exit 1 + ;; + esac + +done + + +if [ ! -f $NXT_AUTOCONF_DATA ]; then + echo + echo Please run common $0 before configuring module \"$nxt_module\". + echo + exit 1 +fi + +. $NXT_AUTOCONF_DATA + +NXT_WCM_WASM_TOOLS_BIN=${NXT_WCM_WASM_TOOLS_BIN=} + + +$echo "configuring $NXT_WCM_MODULE module" +$echo "configuring $NXT_WCM_MODULE module ..." >> $NXT_AUTOCONF_ERR + +$echo -n "looking for rust compiler ... " + +if [ -z `which rustc 2>/dev/null` ]; then + $echo "not found." + exit 1; +fi + +$echo "found." + +$echo -n "looking for cargo ... " + +if [ -z `which cargo 2>/dev/null` ]; then + $echo "not found." + exit 1; +fi + +$echo "found." + + +if grep ^$NXT_WCM_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then + $echo + $echo $0: error: duplicate \"$NXT_WCM_MODULE\" module configured. + $echo + exit 1; +fi + + +$echo " + $NXT_WCM_MODULE module: $NXT_WCM_MOD_NAME" + + +NXT_OS=$(uname -o) + +if [ $NXT_OS = "Darwin" ]; then + NXT_CARGO_CMD="cargo rustc --release --manifest-path src/wasm-wasi-component/Cargo.toml -- --emit link=target/release/libwasm_wasi_component.so -C link-args='-undefined dynamic_lookup'" +else + NXT_CARGO_CMD="cargo build --release --manifest-path src/wasm-wasi-component/Cargo.toml" +fi + + +cat << END >> $NXT_MAKEFILE + +.PHONY: ${NXT_WCM_MODULE} +.PHONY: ${NXT_WCM_MODULE}-install +.PHONY: ${NXT_WCM_MODULE}-uninstall + +all: ${NXT_WCM_MODULE} + +${NXT_WCM_MODULE}: $NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME + +$NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME: + make build/src/nxt_unit.o + $NXT_CARGO_CMD + +install: ${NXT_WCM_MODULE}-install + +${NXT_WCM_MODULE}-install: ${NXT_WCM_MODULE} install-check + install -d \$(DESTDIR)$NXT_MODULESDIR + install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \\ + \$(DESTDIR)$NXT_MODULESDIR/$NXT_WCM_MOD_NAME + +uninstall: ${NXT_WCM_MODULE}-uninstall + +${NXT_WCM_MODULE}-uninstall: + rm -f \$(DESTDIR)$NXT_MODULESDIR/$NXT_WCM_MOD_NAME + @rmdir -p \$(DESTDIR)$NXT_MODULESDIR 2>/dev/null || true + +END -- cgit From 7b13c30604952059c337b8c6afa588fdb5b8895a Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 22 Feb 2024 01:24:11 +0000 Subject: Wasm-wc: Add nxt_unit.o as a dependency in the auto script Rather than calling make itself to build nxt_unit.o make nxt_unit.o a dependency of the main module build target. Reported-by: Konstantin Pavlov Signed-off-by: Andrew Clayton --- auto/modules/wasm-wasi-component | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'auto/modules/wasm-wasi-component') diff --git a/auto/modules/wasm-wasi-component b/auto/modules/wasm-wasi-component index 1ec5841c..52ea3428 100644 --- a/auto/modules/wasm-wasi-component +++ b/auto/modules/wasm-wasi-component @@ -99,8 +99,7 @@ all: ${NXT_WCM_MODULE} ${NXT_WCM_MODULE}: $NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME -$NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME: - make build/src/nxt_unit.o +$NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME: build/src/nxt_unit.o $NXT_CARGO_CMD install: ${NXT_WCM_MODULE}-install -- cgit From d54af163c46bffd1bea0c2b544e412b5d628ec80 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 22 Feb 2024 02:24:36 +0000 Subject: Wasm-wc: Use the cargo build output as the make target dependency cargo build creates the language module under src/wasm-wasi-component/target/release/libwasm_wasi_component.so and not build/lib/unit/modules/wasm_wasi_component.unit.so which is what we were using as a target dependency in the Makefile which doesn't exist so this resulted in the following $ make wasm-wasi-component-install cargo build --release --manifest-path src/wasm-wasi-component/Cargo.toml Finished release [optimized] target(s) in 0.17s install -d /opt/unit/modules install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \ /opt/unit/modules/wasm_wasi_component.unit.so I.e it wanted to rebuild the module, after this patch we get the more correct $ make wasm-wasi-component-install install -d /opt/unit/modules install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \ /opt/unit/modules/wasm_wasi_component.unit.so This is all a little ugly because we're fighting against cargo wanting to do its own thing and this wasm-wasi-component language module build process is likely going to get some re-working anyway, so this will do for now. Reported-by: Konstantin Pavlov Signed-off-by: Andrew Clayton --- auto/modules/wasm-wasi-component | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'auto/modules/wasm-wasi-component') diff --git a/auto/modules/wasm-wasi-component b/auto/modules/wasm-wasi-component index 52ea3428..bfb6ffcb 100644 --- a/auto/modules/wasm-wasi-component +++ b/auto/modules/wasm-wasi-component @@ -5,6 +5,8 @@ NXT_WCM_MODULE=wasm-wasi-component NXT_WCM_MOD_NAME=`echo $NXT_WCM_MODULE | tr '-' '_'`.unit.so +NXT_WCM_MOD_CARGO="src/wasm-wasi-component/target/release/libwasm_wasi_component.so" + shift @@ -97,16 +99,16 @@ cat << END >> $NXT_MAKEFILE all: ${NXT_WCM_MODULE} -${NXT_WCM_MODULE}: $NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME +${NXT_WCM_MODULE}: ${NXT_WCM_MOD_CARGO} -$NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME: build/src/nxt_unit.o +${NXT_WCM_MOD_CARGO}: build/src/nxt_unit.o $NXT_CARGO_CMD install: ${NXT_WCM_MODULE}-install ${NXT_WCM_MODULE}-install: ${NXT_WCM_MODULE} install-check install -d \$(DESTDIR)$NXT_MODULESDIR - install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \\ + install -p ${NXT_WCM_MOD_CARGO} \\ \$(DESTDIR)$NXT_MODULESDIR/$NXT_WCM_MOD_NAME uninstall: ${NXT_WCM_MODULE}-uninstall -- cgit