Skip to content

Commit 8206ab3

Browse files
authored
Fix compilation problem with wasm plugin + Update the use of proxy-wasm library (#12222)
* Fix compilation problem with wasm plugin * Fix format error * Fix format error * Fix format error in cmake files * Fix engine requirement problem * Remove wamr fro fedora build for now * Fix fedora compile requirements * Turn off wamr engine support for experimental plugin * Fix typo * Fix another missing line * Enable wamr * Disable wamr because the fedora has an older version * wasmtime and wamr cannot be used together
1 parent afbb1f5 commit 8206ab3

25 files changed

Lines changed: 297 additions & 51 deletions

CMakePresets.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"CMAKE_COMPILE_WARNING_AS_ERROR": "OFF",
4848
"CMAKE_INSTALL_PREFIX": "/opt/ats",
4949
"BUILD_EXPERIMENTAL_PLUGINS": "ON",
50+
"ENABLE_WASM_WAMR": "OFF",
5051
"ENABLE_VERIFY_PLUGINS": "OFF"
5152
}
5253
},
@@ -58,6 +59,7 @@
5859
"ENABLE_AUTEST": "ON",
5960
"CMAKE_INSTALL_PREFIX": "/tmp/ts-autest",
6061
"BUILD_EXPERIMENTAL_PLUGINS": "ON",
62+
"ENABLE_WASM_WAMR": "OFF",
6163
"ENABLE_EXAMPLE": "ON"
6264
}
6365
},
@@ -106,6 +108,7 @@
106108
"CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
107109
"ENABLE_CCACHE": "ON",
108110
"BUILD_EXPERIMENTAL_PLUGINS": "ON",
111+
"ENABLE_WASM_WAMR": "OFF",
109112
"ENABLE_EXAMPLE": "ON",
110113
"CMAKE_INSTALL_PREFIX": "/tmp/ats"
111114
}
@@ -210,7 +213,8 @@
210213
"binaryDir": "${sourceDir}/build-${presetName}",
211214
"cacheVariables": {
212215
"CMAKE_INSTALL_PREFIX": "/tmp/ats",
213-
"BUILD_EXPERIMENTAL_PLUGINS": "ON"
216+
"BUILD_EXPERIMENTAL_PLUGINS": "ON",
217+
"ENABLE_WASM_WAMR": "OFF"
214218
}
215219
},
216220
{
@@ -391,6 +395,7 @@
391395
"cacheVariables": {
392396
"CMAKE_BUILD_TYPE": "Debug",
393397
"BUILD_EXPERIMENTAL_PLUGINS": "ON",
398+
"ENABLE_WASM_WAMR": "OFF",
394399
"ENABLE_EXAMPLE": "ON",
395400
"ENABLE_CCACHE": "OFF"
396401
}

cmake/ExperimentalPlugins.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,31 @@ auto_option(
115115
)
116116
auto_option(URL_SIG FEATURE_VAR BUILD_URL_SIG DEFAULT ${_DEFAULT})
117117
auto_option(
118-
WASM
118+
WASM_WAMR
119119
FEATURE_VAR
120-
BUILD_WASM
120+
BUILD_WASM_WAMR
121121
PACKAGE_DEPENDS
122122
wamr
123123
DEFAULT
124124
${_DEFAULT}
125125
)
126+
auto_option(
127+
WASM_WASMTIME
128+
FEATURE_VAR
129+
BUILD_WASM_WASMTIME
130+
PACKAGE_DEPENDS
131+
wasmtime
132+
DEFAULT
133+
${_DEFAULT}
134+
)
135+
auto_option(
136+
WASM_WASMEDGE
137+
FEATURE_VAR
138+
BUILD_WASM_WASMEDGE
139+
PACKAGE_DEPENDS
140+
wasmedge
141+
DEFAULT
142+
${_DEFAULT}
143+
)
126144

127145
unset(_DEFAULT)

cmake/Findwamr.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#
3030

3131
find_library(iwasm_LIBRARY NAMES iwasm)
32-
find_path(wamr_INCLUDE_DIR NAMES wasm_export.h)
32+
find_path(wamr_INCLUDE_DIR NAMES wasm_c_api.h)
3333

3434
include(FindPackageHandleStandardArgs)
3535
find_package_handle_standard_args(wamr REQUIRED_VARS iwasm_LIBRARY wamr_INCLUDE_DIR)

cmake/Findwasmedge.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#######################
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
4+
# agreements. See the NOTICE file distributed with this work for additional information regarding
5+
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License
12+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
# or implied. See the License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
#######################
17+
18+
# Findwasmedge.cmake
19+
#
20+
# This will define the following variables
21+
#
22+
# wasmedge_FOUND
23+
# wasmedge_LIBRARY
24+
# wasmedge_INCLUDE_DIR
25+
#
26+
# and the following imported targets
27+
#
28+
# wasmedge::wasmedge
29+
#
30+
31+
find_library(lwasmedge_LIBRARY NAMES wasmedge)
32+
find_path(wasmedge_INCLUDE_DIR NAMES wasmedge/wasmedge.h)
33+
34+
include(FindPackageHandleStandardArgs)
35+
find_package_handle_standard_args(wasmedge REQUIRED_VARS lwasmedge_LIBRARY wasmedge_INCLUDE_DIR)
36+
37+
if(wasmedge_FOUND)
38+
mark_as_advanced(wasmedge_FOUND wasmedge_LIBRARY)
39+
set(wasmedge_INCLUDE_DIRS ${wasmedge_INCLUDE_DIR})
40+
set(wasmedge_LIBRARY ${lwasmedge_LIBRARY})
41+
endif()
42+
43+
if(wasmedge_FOUND AND NOT TARGET wasmedge::wasmedge)
44+
add_library(wasmedge::wasmedge INTERFACE IMPORTED)
45+
target_include_directories(wasmedge::wasmedge INTERFACE ${wasmedge_INCLUDE_DIRS})
46+
target_link_libraries(wasmedge::wasmedge INTERFACE ${wasmedge_LIBRARY})
47+
endif()

cmake/Findwasmtime.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#######################
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
4+
# agreements. See the NOTICE file distributed with this work for additional information regarding
5+
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License
12+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
# or implied. See the License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
#######################
17+
18+
# Findwasmtime.cmake
19+
#
20+
# This will define the following variables
21+
#
22+
# wasmtime_FOUND
23+
# wasmtime_LIBRARY
24+
# wasmtime_INCLUDE_DIR
25+
#
26+
# and the following imported targets
27+
#
28+
# wasmtime::wasmtime
29+
#
30+
31+
find_library(lwasmtime_LIBRARY NAMES wasmtime)
32+
find_path(wasmtime_INCLUDE_DIR NAMES crates/c-api/include/wasm.h)
33+
34+
include(FindPackageHandleStandardArgs)
35+
find_package_handle_standard_args(wasmtime REQUIRED_VARS lwasmtime_LIBRARY wasmtime_INCLUDE_DIR)
36+
37+
if(wasmtime_FOUND)
38+
mark_as_advanced(wasmtime_FOUND wasmtime_LIBRARY)
39+
set(wasmtime_INCLUDE_DIRS ${wasmtime_INCLUDE_DIR})
40+
set(wasmtime_LIBRARY ${lwasmtime_LIBRARY})
41+
endif()
42+
43+
if(wasmtime_FOUND AND NOT TARGET wasmtime::wasmtime)
44+
add_library(wasmtime::wasmtime INTERFACE IMPORTED)
45+
target_include_directories(wasmtime::wasmtime INTERFACE ${wasmtime_INCLUDE_DIRS})
46+
target_link_libraries(wasmtime::wasmtime INTERFACE ${wasmtime_LIBRARY})
47+
endif()

doc/admin-guide/plugins/wasm.en.rst

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ How it Works
3939

4040
The plugin uses the library and header files from the Proxy-Wasm project.
4141

42-
* https://github.com/proxy-wasm/proxy-wasm-cpp-host/tree/b7e690703c7f26707438a2f1ebd7c197bc8f0296
42+
* https://github.com/proxy-wasm/proxy-wasm-cpp-host/tree/c4d7bb0fda912e24c64daf2aa749ec54cec99412
4343
* https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/tree/fd0be8405db25de0264bdb78fae3a82668c03782
4444

45-
Proxy-Wasm in turn uses an underlying WebAssembly runtime to execute the WebAssembly module. (Currently only WAMR and
46-
WasmEdge are supported)
45+
Proxy-Wasm in turn uses an underlying WebAssembly runtime to execute the WebAssembly module. (Currently only WAMR,
46+
Wasmtime and WasmEdge are supported)
4747

4848
The plugin creates a root context when ATS starts and a new context will be created out of the root context for each
4949
transaction. ATS plugin events will trigger the corresponding functions in the WebAssembly module to be executed through
@@ -61,9 +61,9 @@ Compiling the Plugin
6161

6262
::
6363

64-
wget https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-1.2.1.tar.gz
65-
tar zxvf WAMR-1.2.1.tar.gz
66-
cd wasm-micro-runtime-WAMR-1.2.1
64+
wget https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-2.1.1.tar.gz
65+
tar zxvf WAMR-2.1.1.tar.gz
66+
cd wasm-micro-runtime-WAMR-2.1.1
6767
cp core/iwasm/include/* /usr/local/include/
6868
cd product-mini/platforms/linux
6969
mkdir build
@@ -78,16 +78,13 @@ Compiling the Plugin
7878

7979
git clone https://github.com/bytecodealliance/wasmtime.git
8080
cd wasmtime/
81-
git checkout release-9.0.0
81+
git checkout release-24.0.0
8282
git submodule update --init
8383
cargo build
8484
cargo build --release --manifest-path crates/c-api/Cargo.toml
8585
sudo cp target/release/libwasmtime.so /usr/local/lib
86-
wget https://github.com/WebAssembly/wasm-c-api/archive/c9d31284651b975f05ac27cee0bab1377560b87e.tar.gz
87-
tar zxvf c9d31284651b975f05ac27cee0bab1377560b87e.tar.gz
88-
cd wasm-c-api-c9d31284651b975f05ac27cee0bab1377560b87e/
89-
sudo mkdir /usr/local/include/include/
90-
sudo cp include/wasm.h /usr/local/include/include/
86+
sudo mkdir -p /usr/local/include/crates/c-api/include/
87+
sudo cp crates/c-api/include/wasm.h /usr/local/include/crates/c-api/include/
9188

9289
**Install WasmEdge**
9390

plugins/experimental/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ endif()
116116
if(BUILD_URL_SIG)
117117
add_subdirectory(url_sig)
118118
endif()
119-
if(BUILD_WASM)
119+
if(BUILD_WASM_WAMR
120+
OR BUILD_WASM_WASMTIME
121+
OR BUILD_WASM_WASMEDGE
122+
)
120123
add_subdirectory(wasm)
121124
endif()

plugins/experimental/wasm/CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,26 @@
1818
add_subdirectory(lib)
1919

2020
add_atsplugin(wasm ats_context.cc ats_wasm.cc wasm_main.cc)
21-
target_link_libraries(wasm PRIVATE wasmlib wamr::wamr)
21+
22+
set(WASM_RUNTIME wasmlib)
23+
if(wamr_FOUND)
24+
list(APPEND WASM_RUNTIME wamr::wamr)
25+
elseif(wasmtime_FOUND)
26+
list(APPEND WASM_RUNTIME wasmtime::wasmtime)
27+
endif()
28+
if(wasmedge_FOUND)
29+
list(APPEND WASM_RUNTIME wasmedge::wasmedge)
30+
endif()
31+
32+
target_link_libraries(wasm PRIVATE ${WASM_RUNTIME})
33+
34+
if(wamr_FOUND)
35+
target_compile_options(wasm PRIVATE -DWAMR)
36+
elseif(wasmtime_FOUND)
37+
target_compile_options(wasm PRIVATE -DWASMTIME)
38+
endif()
39+
if(wasmedge_FOUND)
40+
target_compile_options(wasm PRIVATE -DWASMEDGE)
41+
endif()
42+
2243
verify_global_plugin(wasm)

plugins/experimental/wasm/lib/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ set(CC_FILES
2929
)
3030
if(wamr_FOUND)
3131
list(APPEND CC_FILES src/wamr/wamr.cc)
32+
elseif(wasmtime_FOUND)
33+
list(APPEND CC_FILES src/wasmtime/wasmtime.cc)
34+
endif()
35+
if(wasmedge_FOUND)
36+
list(APPEND CC_FILES src/wasmedge/wasmedge.cc)
3237
endif()
3338

3439
add_library(wasmlib STATIC ${CC_FILES})
3540
target_compile_options(wasmlib PUBLIC -Wno-unused-parameter)
3641
if(wamr_FOUND)
3742
target_compile_options(wasmlib PRIVATE -Wno-missing-field-initializers)
3843
target_link_libraries(wasmlib PUBLIC wamr::wamr)
44+
elseif(wasmtime_FOUND)
45+
target_link_libraries(wasmlib PUBLIC wasmtime::wasmtime)
46+
endif()
47+
if(wasmedge_FOUND)
48+
target_link_libraries(wasmlib PUBLIC wasmedge::wasmedge)
3949
endif()
4050

4151
target_include_directories(wasmlib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# WebAssembly for Proxies (C++ host implementation)
2+
3+
## How to Contribute
4+
5+
See [CONTRIBUTING](CONTRIBUTING.md).

0 commit comments

Comments
 (0)