Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ jobs:
# Rust programs. Note that this only executes if the `determine` step told
# us to test the capi which is off-by-default for PRs.
- run: rustup target add wasm32-wasip2 # wasip2 target needed by example programs
- run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF
- run: cmake -Sexamples -Bexamples/build -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=ON
- run: cmake --build examples/build --config Debug
- run: cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build examples/build --config Debug --target RUN_TESTS
if: runner.os == 'Windows'
Expand Down
44 changes: 44 additions & 0 deletions crates/c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(wasmtime C)

set(WASMTIME_USER_CARGO_BUILD_OPTIONS "" CACHE STRING "Additional cargo flags (such as --features) to apply to the build command")
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(WASMTIME_ALWAYS_BUILD "If cmake should always invoke cargo to build wasmtime" ON)
option(WASMTIME_FASTEST_RUNTIME "Set flags designed to optimize runtime performance" OFF)
set(WASMTIME_TARGET "" CACHE STRING "Rust target to build for")
Expand Down Expand Up @@ -129,3 +130,46 @@ add_custom_target(headers-to-doc
-DWASMTIME_HEADER_DST=${CMAKE_BINARY_DIR}/include
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install-headers.cmake
DEPENDS ${headers})

if (NOT CMAKE_CXX_STANDARD)
message(STATUS "Cannot detect C++ Standard. Switching to C++17 by default !!")
set(CMAKE_CXX_STANDARD 17)
endif()
message(STATUS "CMAKE_CXX_STANDARD is ${CMAKE_CXX_STANDARD}")
if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 17)
message(FATAL_ERROR "WASMTIME_CPP library does not support ${CMAKE_CXX_STANDARD}")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED True)

option(ENABLE_CODE_ANALYSIS "Run code analysis" OFF)
message(STATUS "ENABLE_CODE_ANALYSIS ${ENABLE_CODE_ANALYSIS}")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()

add_library(wasmtime-cpp INTERFACE)
target_link_libraries(wasmtime-cpp INTERFACE wasmtime)
if (MSVC)
target_compile_options(wasmtime-cpp INTERFACE /DWASM_API_EXTERN= /DWASI_API_EXTERN=)
target_link_libraries(wasmtime-cpp INTERFACE ws2_32 bcrypt advapi32 userenv ntdll shell32 ole32)
else()
target_link_libraries(wasmtime-cpp INTERFACE stdc++ pthread)
endif()

target_include_directories(
wasmtime-cpp
INTERFACE
${PROJECT_SOURCE_DIR}/include)

if (BUILD_TESTS)
message(STATUS "Building tests")

enable_language(CXX)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)

enable_testing()
add_subdirectory(tests)
endif()
4 changes: 4 additions & 0 deletions crates/c-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ These commands will produce the following files:

* `artifacts/include/**.h`: Header files for working with Wasmtime.

## Using in a C++ Project

A header only C++ API is also offered as `wasmtime.hh`, which is built on top of the C API. Its located next to the C headers when you download a pre-built library, or when building from source. C++17 is required.

## Using in a Rust Project

If you have a Rust crate that contains bindings to a C or C++ library that uses Wasmtime, you can link the Wasmtime C API using Cargo.
Expand Down
11 changes: 8 additions & 3 deletions crates/c-api/doxygen.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,8 @@ INPUT_ENCODING = UTF-8
# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
# *.ucf, *.qsf and *.ice.

FILE_PATTERNS = *.h
FILE_PATTERNS = *.h \
*.hh

# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
Expand Down Expand Up @@ -924,7 +925,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*

EXCLUDE_PATTERNS =
EXCLUDE_PATTERNS = */wasm.hh

# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
Expand All @@ -944,7 +945,11 @@ EXCLUDE_SYMBOLS = assertions \
WASMTIME_CONFIG_PROP \
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP \
own \
wasm_*_enum
wasm_*_enum \
wasmtime::detail \
CASE_KIND_PRINT_NAME \
CASE_KIND_TO_C \
CASE_C_TO_KIND

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
Expand Down
Loading
Loading