Skip to content

Commit 05b4cd5

Browse files
committed
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 <[email protected]>
1 parent 601b504 commit 05b4cd5

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

auto/help

+5
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ cat << END
7979
wasm OPTIONS configure WebAssembly module
8080
run "./configure wasm --help" to see available options
8181

82+
wasm-wasi-component OPTIONS
83+
configure WebAssembly Component Model module
84+
run "./configure wasm-wasi-component --help" to see
85+
available options
86+
8287
END

auto/modules/conf

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ case "$nxt_module" in
3737
. auto/modules/wasm
3838
;;
3939

40+
wasm-wasi-component)
41+
. auto/modules/wasm-wasi-component
42+
;;
43+
4044
*)
4145
echo
4246
echo $0: error: invalid module \"$nxt_module\".

auto/modules/wasm-wasi-component

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Copyright (C) Andrew Clayton
2+
# Copyright (C) F5, Inc.
3+
4+
5+
NXT_WCM_MODULE=wasm-wasi-component
6+
NXT_WCM_MOD_NAME=`echo $NXT_WCM_MODULE | tr '-' '_'`.unit.so
7+
8+
9+
shift
10+
11+
for nxt_option; do
12+
13+
case "$nxt_option" in
14+
-*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
15+
*) value="" ;;
16+
esac
17+
18+
case "$nxt_option" in
19+
20+
--help)
21+
cat << END
22+
23+
END
24+
exit 0
25+
;;
26+
27+
*)
28+
echo
29+
echo $0: error: invalid $NXT_WCM_MODULE option \"$nxt_option\"
30+
echo
31+
exit 1
32+
;;
33+
esac
34+
35+
done
36+
37+
38+
if [ ! -f $NXT_AUTOCONF_DATA ]; then
39+
echo
40+
echo Please run common $0 before configuring module \"$nxt_module\".
41+
echo
42+
exit 1
43+
fi
44+
45+
. $NXT_AUTOCONF_DATA
46+
47+
NXT_WCM_WASM_TOOLS_BIN=${NXT_WCM_WASM_TOOLS_BIN=}
48+
49+
50+
$echo "configuring $NXT_WCM_MODULE module"
51+
$echo "configuring $NXT_WCM_MODULE module ..." >> $NXT_AUTOCONF_ERR
52+
53+
$echo -n "looking for rust compiler ... "
54+
55+
if [ -z `which rustc 2>/dev/null` ]; then
56+
$echo "not found."
57+
exit 1;
58+
fi
59+
60+
$echo "found."
61+
62+
$echo -n "looking for cargo ... "
63+
64+
if [ -z `which cargo 2>/dev/null` ]; then
65+
$echo "not found."
66+
exit 1;
67+
fi
68+
69+
$echo "found."
70+
71+
72+
if grep ^$NXT_WCM_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
73+
$echo
74+
$echo $0: error: duplicate \"$NXT_WCM_MODULE\" module configured.
75+
$echo
76+
exit 1;
77+
fi
78+
79+
80+
$echo " + $NXT_WCM_MODULE module: $NXT_WCM_MOD_NAME"
81+
82+
83+
NXT_OS=$(uname -o)
84+
85+
if [ $NXT_OS = "Darwin" ]; then
86+
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'"
87+
else
88+
NXT_CARGO_CMD="cargo build --release --manifest-path src/wasm-wasi-component/Cargo.toml"
89+
fi
90+
91+
92+
cat << END >> $NXT_MAKEFILE
93+
94+
.PHONY: ${NXT_WCM_MODULE}
95+
.PHONY: ${NXT_WCM_MODULE}-install
96+
.PHONY: ${NXT_WCM_MODULE}-uninstall
97+
98+
all: ${NXT_WCM_MODULE}
99+
100+
${NXT_WCM_MODULE}: $NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME
101+
102+
$NXT_BUILD_DIR/lib/unit/modules/$NXT_WCM_MOD_NAME:
103+
make build/src/nxt_unit.o
104+
$NXT_CARGO_CMD
105+
106+
install: ${NXT_WCM_MODULE}-install
107+
108+
${NXT_WCM_MODULE}-install: ${NXT_WCM_MODULE} install-check
109+
install -d \$(DESTDIR)$NXT_MODULESDIR
110+
install -p src/wasm-wasi-component/target/release/libwasm_wasi_component.so \\
111+
\$(DESTDIR)$NXT_MODULESDIR/$NXT_WCM_MOD_NAME
112+
113+
uninstall: ${NXT_WCM_MODULE}-uninstall
114+
115+
${NXT_WCM_MODULE}-uninstall:
116+
rm -f \$(DESTDIR)$NXT_MODULESDIR/$NXT_WCM_MOD_NAME
117+
@rmdir -p \$(DESTDIR)$NXT_MODULESDIR 2>/dev/null || true
118+
119+
END

0 commit comments

Comments
 (0)