Skip to content

Commit

Permalink
chore(*) install ngx_wasm_rs along with nginx
Browse files Browse the repository at this point in the history
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
  • Loading branch information
hishamhm committed Apr 13, 2023
1 parent e73565d commit 104038b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions auto/cargo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if [ $ngx_wasm_rc = 0 ]; then
if [ "$ngx_wasm_cargo_crate_type" = "cdylib" ]; then
ngx_feature_libs="\
-Wl,-rpath $ngx_wasm_cargo_target_dir \
-Wl,-rpath $NGX_PREFIX/lib \
-L$ngx_wasm_cargo_target_dir \
-l$ngx_wasm_cargo_lib_name"
else
Expand All @@ -41,6 +42,28 @@ if [ $ngx_wasm_rc = 0 ]; then
have=$d value=1 . auto/define
done

if [ "$ngx_wasm_cargo_crate_type" = "cdylib" ]; then
ngx_wasm_cargo_cdylib="$ngx_wasm_cargo_target_dir/lib$ngx_wasm_cargo_lib_name.so"
ngx_wasm_cargo_cdylibs="$ngx_wasm_cargo_cdylibs $ngx_wasm_cargo_cdylib"

if ! grep -q ngx_wasm_cargo_cdylib auto/install; then
cat << EOF >> auto/install

for ngx_wasm_cargo_cdylib in \$ngx_wasm_cargo_cdylibs
do

cat << END >> \$NGX_MAKEFILE

test -d '\\\$(DESTDIR)\$NGX_PREFIX/lib' \\
|| mkdir -p '\\\$(DESTDIR)\$NGX_PREFIX/lib'
cp \$ngx_wasm_cargo_cdylib '\\\$(DESTDIR)\$NGX_PREFIX/lib'
END

done
EOF
fi
fi

else
echo "$0: error: failed testing library $ngx_wasm_cargo_lib_name."
fi
Expand Down

0 comments on commit 104038b

Please sign in to comment.