Kong / ngx_wasm_module

Nginx + WebAssembly
Apache License 2.0
79 stars 7 forks source link

Build Wasmer with LLVM support #271

Open thibaultcha opened 1 year ago

thibaultcha commented 1 year ago

See thread at: https://github.com/Kong/ngx_wasm_module/pull/265

thibaultcha commented 1 year ago

Patch from the chore/local-builds-llvm branch which I am deleting (stale):

From 6f017b8a8084cefdad8d278109c4919d0920f7fd Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Wed, 19 Apr 2023 13:55:49 -0300
Subject: [PATCH] chore(*) enable LLVM in Wasmer build

---
 t/01-wasm/directives/002-compiler_directive.t |  1 -
 t/10-build/002-runtime_linking.t              |  2 +-
 util/runtimes/wasmer.sh                       | 22 +++++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/t/01-wasm/directives/002-compiler_directive.t b/t/01-wasm/directives/002-compiler_directive.t
index 304fc626..2362b745 100644
--- a/t/01-wasm/directives/002-compiler_directive.t
+++ b/t/01-wasm/directives/002-compiler_directive.t
@@ -113,7 +113,6 @@ qr/\[info\] .*? \[wasm\] using wasmer with compiler: "singlepass"/

 === TEST 8: compiler directive - wasmer 'llvm'
---- SKIP
 --- skip_eval: 4: $::nginxV !~ m/wasmer/
 --- main_config
     wasm {
diff --git a/t/10-build/002-runtime_linking.t b/t/10-build/002-runtime_linking.t
index 98165846..52328c32 100644
--- a/t/10-build/002-runtime_linking.t
+++ b/t/10-build/002-runtime_linking.t
@@ -53,7 +53,7 @@ libwee8

 === TEST 4: build with statically linked runtime - wasmtime, wasmer
 --- skip_eval: 4: !( $ENV{NGX_WASM_RUNTIME} eq 'wasmtime' || $ENV{NGX_WASM_RUNTIME} eq 'wasmer' ) || $ENV{NGX_WASM_RUNTIME_DIR} eq '' || $ENV{NGX_WASM_RUNTIME} eq ''
---- build eval: qq{NGX_WASM_RUNTIME_INC="$ENV{NGX_WASM_RUNTIME_DIR}/include" NGX_WASM_RUNTIME_LD_OPT="$ENV{NGX_WASM_RUNTIME_DIR}/lib/lib$ENV{NGX_WASM_RUNTIME}.a -lm -ldl -lpthread" make}
+--- build eval: qq{NGX_WASM_RUNTIME_INC="$ENV{NGX_WASM_RUNTIME_DIR}/include" NGX_WASM_RUNTIME_LD_OPT="$ENV{NGX_WASM_RUNTIME_DIR}/lib/lib$ENV{NGX_WASM_RUNTIME}.a -lm -ldl -lpthread -lstdc++" make}
 --- no_grep_libs eval
 [
     qr/libwasmtime/,
diff --git a/util/runtimes/wasmer.sh b/util/runtimes/wasmer.sh
index 9086c82b..92d00e5f 100755
--- a/util/runtimes/wasmer.sh
+++ b/util/runtimes/wasmer.sh
@@ -110,6 +110,28 @@ build_wasmer() {
                 rm -rf target
             fi

+patch -p0 << EOF
+diff --git Makefile Makefile
+index 0123ebf7c9..1998f7ce07 100644
+--- Makefile
++++ Makefile
+@@ -260,11 +260,9 @@ comma := ,
+ compiler_features := --features \$(subst \$(space),\$(comma),\$(compilers)),wasmer-artifact-create,static-artifact-create,wasmer-artifact-load,static-artifact-load
+ capi_compilers_engines_exclude :=
+
+-# Define the compiler Cargo features for the C API. It always excludes
+-# LLVM for the moment because it causes the linker to fail since LLVM is not statically linked.
+-# TODO: Reenable LLVM in C-API
+-capi_compiler_features := --features \$(subst \$(space),\$(comma),\$(filter-out llvm, \$(compilers))),wasmer-artifact-create,static-artifact-create,wasmer-artifact-load,static-artifact-load
+-capi_compilers_engines_exclude += llvm-universal
++# Define the compiler Cargo features for the C API.
++capi_compiler_features := --features \$(subst \$(space),\$(comma),\$(compilers)),wasmer-artifact-create,static-artifact-create,wasmer-artifact-load,static-artifact-load
++capi_compilers_engines_exclude +=
+
+ # We exclude singlepass-universal because it doesn't support multivalue (required in wasm-c-api tests)
+ capi_compilers_engines_exclude += singlepass-universal
+EOF
+
             RUSTFLAGS=$NGX_BUILD_WASMER_RUSTFLAGS \
             ENABLE_LLVM=1 \
                 make build-capi