forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cmake compatibility to c-api (bytecodealliance#4369)
* Add cmake compatibility to c-api * Add CMake documentation to wasmtime.h * Add CMake instructions in examples * Modify CI for CMake support * Use correct rust in CI * Trigger build * Refactor run-examples * Reintroduce example_to_run in run-examples * Replace run-examples crate with cmake * Fix markdown formatting in examples readme * Fix cmake test quotes * Build rust wasm before cmake tests * Pass CTEST_OUTPUT_ON_FAILURE * Another cmake test * Handle os differences in cmake test * Fix bugs in memory and multimemory examples
- Loading branch information
1 parent
35b750a
commit 2ba3025
Showing
25 changed files
with
244 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ foo | |
.cargo | ||
publish | ||
vendor | ||
examples/build |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) | ||
|
||
if (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
set(WASMTIME_BUILD_TYPE_FLAG "--release") | ||
set(WASMTIME_BUILD_TYPE "release") | ||
else() | ||
set(WASMTIME_BUILD_TYPE "debug") | ||
endif() | ||
|
||
if (BUILD_SHARED_LIBS) | ||
# Copy shared library into build directory | ||
if(WIN32) | ||
set(WASMTIME_INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/wasmtime.dll | ||
${CMAKE_BINARY_DIR}) | ||
elseif(APPLE) | ||
set(WASMTIME_INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.dylib | ||
${CMAKE_BINARY_DIR}) | ||
else() | ||
set(WASMTIME_INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.so | ||
${CMAKE_BINARY_DIR}) | ||
endif() | ||
endif() | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add( | ||
wasmtime-crate | ||
DOWNLOAD_COMMAND "" | ||
CONFIGURE_COMMAND "" | ||
INSTALL_COMMAND "${WASMTIME_INSTALL_COMMAND}" | ||
BUILD_COMMAND cargo build ${WASMTIME_BUILD_TYPE_FLAG} | ||
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR} | ||
BUILD_ALWAYS ON) | ||
add_library(wasmtime INTERFACE) | ||
add_dependencies(wasmtime wasmtime-crate) | ||
|
||
if (BUILD_SHARED_LIBS) | ||
if(WIN32) | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/wasmtime.dll.lib) | ||
elseif(APPLE) | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.dylib) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") | ||
else() | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.so) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") | ||
endif() | ||
else() | ||
if(WIN32) | ||
target_compile_options(wasmtime INTERFACE -DWASM_API_EXTERN= -DWASI_API_EXTERN=) | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/wasmtime.lib | ||
ws2_32 advapi32 userenv ntdll shell32 ole32 bcrypt) | ||
elseif(APPLE) | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.a) | ||
else() | ||
target_link_libraries(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/${WASMTIME_BUILD_TYPE}/libwasmtime.a | ||
pthread dl m) | ||
endif() | ||
endif() | ||
|
||
target_include_directories(wasmtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/wasm-c-api/include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(wasmtime-examples) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../crates/c-api ${CMAKE_CURRENT_BINARY_DIR}/wasmtime) | ||
|
||
function(CREATE_TARGET TARGET TARGET_PATH) | ||
add_executable(wasmtime-${TARGET} ${TARGET_PATH}) | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
target_compile_options(wasmtime-${TARGET} PRIVATE -Wall -Wextra -Wno-deprecated-declarations) | ||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
target_compile_options(wasmtime-${TARGET} PRIVATE /W3) | ||
endif() | ||
|
||
set_target_properties(wasmtime-${TARGET} PROPERTIES | ||
OUTPUT_NAME wasmtime-${TARGET} | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:> | ||
CXX_VISIBILITY_PRESET hidden | ||
POSITION_INDEPENDENT_CODE ON) | ||
|
||
target_include_directories(wasmtime-${TARGET} PUBLIC wasmtime) | ||
target_link_libraries(wasmtime-${TARGET} PUBLIC wasmtime) | ||
add_test(NAME ${TARGET}-c COMMAND $<TARGET_FILE:wasmtime-${TARGET}> WORKING_DIRECTORY ../..) | ||
endfunction() | ||
|
||
function(CREATE_RUST_TEST EXAMPLE) | ||
if(ARGC GREATER 1) | ||
add_test(NAME ${EXAMPLE}-rust COMMAND cargo run --example ${EXAMPLE} --features ${ARGV1} WORKING_DIRECTORY ../..) | ||
else() | ||
add_test(NAME ${EXAMPLE}-rust COMMAND cargo run --example ${EXAMPLE} WORKING_DIRECTORY ../..) | ||
endif() | ||
endfunction() | ||
function(CREATE_RUST_WASM EXAMPLE TARGET) | ||
execute_process(COMMAND cargo build -p example-${EXAMPLE}-wasm --target ${TARGET}) | ||
endfunction() | ||
|
||
# Enable testing | ||
enable_testing() | ||
|
||
# Add all examples | ||
create_target(externref externref.c) | ||
create_target(fib-debug fib-debug/main.c) | ||
create_target(fuel fuel.c) | ||
create_target(gcd gcd.c) | ||
create_target(hello hello.c) | ||
create_target(interrupt interrupt.c) | ||
create_target(linking linking.c) | ||
create_target(memory memory.c) | ||
create_target(multi multi.c) | ||
create_target(multimemory multimemory.c) | ||
create_target(serialize serialize.c) | ||
create_target(threads threads.c) | ||
create_target(wasi wasi/main.c) | ||
|
||
# Add rust tests | ||
create_rust_wasm(fib-debug wasm32-unknown-unknown) | ||
create_rust_wasm(tokio wasm32-wasi) | ||
create_rust_wasm(wasi wasm32-wasi) | ||
create_rust_test(epochs) | ||
create_rust_test(externref) | ||
create_rust_test(fib-debug) | ||
create_rust_test(fuel) | ||
create_rust_test(gcd) | ||
create_rust_test(hello) | ||
create_rust_test(interrupt) | ||
create_rust_test(linking) | ||
create_rust_test(memory) | ||
create_rust_test(multi) | ||
create_rust_test(multimemory) | ||
create_rust_test(serialize) | ||
create_rust_test(threads) | ||
create_rust_test(wasi) | ||
create_rust_test(tokio wasmtime-wasi/tokio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.