-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use cmake to build wasmtime-c-api #9031
Changes from all commits
94f2e34
c0c8d19
59692fa
5fe2ccd
274df2d
cacb0b7
837eb63
83f681a
a0fe133
7a7ae91
4a4ebc1
8250296
1c60a0c
6abfa1c
4c76047
27ab7be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,45 @@ | ||
use std::env; | ||
use std::process::Command; | ||
|
||
// WASMTIME_FEATURE_LIST | ||
const FEATURES: &[&str] = &[ | ||
"ASYNC", | ||
"PROFILING", | ||
"CACHE", | ||
"PARALLEL_COMPILATION", | ||
"WASI", | ||
"LOGGING", | ||
"DISABLE_LOGGING", | ||
"COREDUMP", | ||
"ADDR2LINE", | ||
"DEMANGLE", | ||
"THREADS", | ||
"GC", | ||
"CRANELIFT", | ||
"WINCH", | ||
]; | ||
// ... if you add a line above this be sure to change the other locations | ||
// marked WASMTIME_FEATURE_LIST | ||
|
||
fn main() { | ||
let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
println!("cargo:include={dir}/include"); | ||
println!("cargo:rerun-if-changed=cmake/features.cmake"); | ||
println!("cargo:rerun-if-changed=cmake/install-headers.cmake"); | ||
println!("cargo:rerun-if-changed=include"); | ||
|
||
let out_dir = std::env::var("OUT_DIR").unwrap(); | ||
let mut cmake = Command::new("cmake"); | ||
cmake.arg("-DWASMTIME_DISABLE_ALL_FEATURES=ON"); | ||
cmake.arg(format!("-DCMAKE_INSTALL_PREFIX={out_dir}")); | ||
for f in FEATURES { | ||
if env::var_os(format!("CARGO_FEATURE_{f}")).is_some() { | ||
cmake.arg(format!("-DWASMTIME_FEATURE_{f}=ON")); | ||
} | ||
} | ||
|
||
cmake.arg("-P").arg("cmake/install-headers.cmake"); | ||
|
||
let status = cmake.status().expect("failed to spawn `cmake`"); | ||
assert!(status.success()); | ||
|
||
println!("cargo:include={out_dir}/include"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
set(WASMTIME_FEATURES "--no-default-features") | ||
|
||
option(WASMTIME_DISABLE_ALL_FEATURES | ||
"disable all features by default instead of enabling them" | ||
OFF) | ||
|
||
macro(feature rust_name default) | ||
string(TOUPPER "wasmtime_feature_${rust_name}" cmake_name) | ||
string(REPLACE "-" "_" cmake_name ${cmake_name}) | ||
if(${default}) | ||
if(${WASMTIME_DISABLE_ALL_FEATURES}) | ||
set(feature_default OFF) | ||
else() | ||
set(feature_default ON) | ||
endif() | ||
else() | ||
set(feature_default OFF) | ||
endif() | ||
|
||
option(${cmake_name} "enable the Cargo feature ${rust_name}" ${feature_default}) | ||
|
||
if(${cmake_name}) | ||
list(APPEND WASMTIME_FEATURES "--features=${rust_name}") | ||
message(STATUS "Enabling feature ${rust_name}") | ||
endif() | ||
endmacro() | ||
|
||
# WASMTIME_FEATURE_LIST | ||
feature(profiling ON) | ||
feature(wat ON) | ||
feature(cache ON) | ||
feature(parallel-compilation ON) | ||
feature(wasi ON) | ||
feature(logging ON) | ||
feature(disable-logging OFF) | ||
feature(coredump ON) | ||
feature(addr2line ON) | ||
feature(demangle ON) | ||
feature(threads ON) | ||
feature(gc ON) | ||
feature(async ON) | ||
feature(cranelift ON) | ||
feature(winch ON) | ||
# ... if you add a line above this be sure to change the other locations | ||
# marked WASMTIME_FEATURE_LIST |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
include(${CMAKE_CURRENT_LIST_DIR}/features.cmake) | ||
|
||
if(WASMTIME_HEADER_DST) | ||
set(dst "${WASMTIME_HEADER_DST}") | ||
else() | ||
set(dst "${CMAKE_INSTALL_PREFIX}/include") | ||
endif() | ||
set(include_src "${CMAKE_CURRENT_LIST_DIR}/../include") | ||
|
||
message(STATUS "Installing: ${dst}/wasmtime/conf.h") | ||
file(READ "${include_src}/wasmtime/conf.h.in" conf_h) | ||
file(CONFIGURE OUTPUT "${dst}/wasmtime/conf.h" CONTENT "${conf_h}") | ||
file(INSTALL "${include_src}/" | ||
DESTINATION "${dst}" | ||
FILES_MATCHING REGEX "\\.hh?$") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,22 +11,22 @@ | |
* are three mechanisms for yielding control from wasm to the caller: fuel, | ||
* epochs, and async host functions. | ||
* | ||
* When WebAssembly is executed, a #wasmtime_call_future_t is returned. This | ||
* When WebAssembly is executed, a `wasmtime_call_future_t` is returned. This | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this was necessary at one stage of testing to appease doxygen. That being said I barely understanding doxygen and we could very well be holding doxygen wrong where this should work when it doesn't. |
||
* struct represents the state of the execution and each call to | ||
* #wasmtime_call_future_poll will execute the WebAssembly code on a separate | ||
* `wasmtime_call_future_poll` will execute the WebAssembly code on a separate | ||
* stack until the function returns or yields control back to the caller. | ||
* | ||
* It's expected these futures are pulled in a loop until completed, at which | ||
* point the future should be deleted. Functions that return a | ||
* #wasmtime_call_future_t are special in that all parameters to that function | ||
* `wasmtime_call_future_t` are special in that all parameters to that function | ||
* should not be modified in any way and must be kept alive until the future is | ||
* deleted. This includes concurrent calls for a single store - another function | ||
* on a store should not be called while there is a #wasmtime_call_future_t | ||
* on a store should not be called while there is a `wasmtime_call_future_t` | ||
* alive. | ||
* | ||
* As for asynchronous host calls - the reverse contract is upheld. Wasmtime | ||
* will keep all parameters to the function alive and unmodified until the | ||
* #wasmtime_func_async_continuation_callback_t returns true. | ||
* `wasmtime_func_async_continuation_callback_t` returns true. | ||
* | ||
*/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#ifndef WASMTIME_CONF_H | ||
#define WASMTIME_CONF_H | ||
|
||
// WASMTIME_FEATURE_LIST | ||
#cmakedefine WASMTIME_FEATURE_PROFILING | ||
#cmakedefine WASMTIME_FEATURE_WAT | ||
#cmakedefine WASMTIME_FEATURE_CACHE | ||
|
@@ -22,6 +23,8 @@ | |
#cmakedefine WASMTIME_FEATURE_ASYNC | ||
#cmakedefine WASMTIME_FEATURE_CRANELIFT | ||
#cmakedefine WASMTIME_FEATURE_WINCH | ||
// ... if you add a line above this be sure to change the other locations | ||
// marked WASMTIME_FEATURE_LIST | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you move this comment above the list (here and elsewhere), then you can avoid the duplicate nonce (less noise when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I like having this at the end because features are often added at the end and a comment only at the top might get missed. The amount of duplication here though is unfortunate across the codebase but that would probably be best fixed with a "tidy" script or something like that rather than relying on us humans to handle everything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just mean as a trivial way to halve the number of hits: no need to have the nonce both before and after the list; once is enough (no matter where). |
||
|
||
#if defined(WASMTIME_FEATURE_CRANELIFT) || defined(WASMTIME_FEATURE_WINCH) | ||
#define WASMTIME_FEATURE_COMPILER | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.