Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit c3bb729

Browse files
authored
Bind the new *_unchecked function APIs (#17)
This commit binds two new APIs added to `wasmtime`'s C API recently: * `wasmtime_func_new_unchecked` * `wamstime_func_call_unchecked` These two functions are a more accelerated path of invoking a WebAssembly function and having a WebAssembly function call the host. The new APIs are generally unsafe but with the C++ bindings added here they should at least be type-safe. The goal was to add APIs similar to the Rust crate's `Func::wrap` and `Func::typed` for statically-typed function calls. Overall the performance here worked out great in that it's on-par with C and as expected from the PR adding the `*_unchecked` variants. This is, however, basically my first foray into templated functions in C++ and wow is this a lot more complicated than I thought that it would be. Some extra eyes on this would be appreciated to see if I've missed something or if the design could be simplified.
1 parent 40fc6f8 commit c3bb729

File tree

8 files changed

+786
-45
lines changed

8 files changed

+786
-45
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v2
2727
- run: sudo apt-get update -y && sudo apt-get install -y libclang1-9 libclang-cpp9
28-
- run: curl -L https://doxygen.nl/files/doxygen-1.9.1.linux.bin.tar.gz | tar xzf -
29-
- run: echo "`pwd`/doxygen-1.9.1/bin" >> $GITHUB_PATH
28+
- run: curl -L https://doxygen.nl/files/doxygen-1.9.2.linux.bin.tar.gz | tar xzf -
29+
- run: echo "`pwd`/doxygen-1.9.2/bin" >> $GITHUB_PATH
3030
- run: doxygen doxygen.conf
3131
- run: tar czf html.tar.gz html
3232
- uses: actions/upload-artifact@v2

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
1414
option(ENABLE_CODE_ANALYSIS "Run code analysis" OFF)
1515
message(STATUS "ENABLE_CODE_ANALYSIS ${ENABLE_CODE_ANALYSIS}")
1616

17+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
18+
add_compile_options (-fdiagnostics-color=always)
19+
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
20+
add_compile_options (-fcolor-diagnostics)
21+
endif ()
22+
1723
add_library(wasmtime-cpp INTERFACE ${CMAKE_SOURCE_DIR}/include/wasmtime.hh)
1824
target_link_libraries(wasmtime-cpp INTERFACE wasmtime)
1925
if (MSVC)

doxygen.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ WARNINGS = YES
810810
# will automatically be disabled.
811811
# The default value is: YES.
812812

813-
WARN_IF_UNDOCUMENTED = YES
813+
WARN_IF_UNDOCUMENTED = NO
814814

815815
# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
816816
# potential errors in the documentation, such as not documenting some parameters
@@ -1886,7 +1886,7 @@ PDF_HYPERLINKS = YES
18861886
# The default value is: YES.
18871887
# This tag requires that the tag GENERATE_LATEX is set to YES.
18881888

1889-
USE_PDFLATEX = YES
1889+
USE_PDFLATEX = NO
18901890

18911891
# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
18921892
# command to the generated LaTeX files. This will instruct LaTeX to keep running

examples/hello.cc

+2-8
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@ int main() {
3131

3232
// Our wasm module we'll be instantiating requires one imported function.
3333
// the function takes no parameters and returns no results. We create a host
34-
// implementation of that function here, and the `caller` parameter here is
35-
// used to get access to our original `MyState` value.
34+
// implementation of that function here.
3635
std::cout << "Creating callback...\n";
37-
FuncType ty({}, {});
38-
Func host_func(store, ty, [](auto caller, auto args, auto results) -> auto {
36+
Func host_func = Func::wrap(store, []() {
3937
std::cout << "Calling back...\n";
40-
(void) caller;
41-
(void) args;
42-
(void) results;
43-
return std::monostate();
4438
});
4539

4640
// Once we've got that all set up we can then move to the instantiation

0 commit comments

Comments
 (0)