Skip to content
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

Add Cranelift and Winch features to the C API #8661

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions crates/c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ 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 also change:
#
# crates/c-api/include/wasmtime/conf.h.in
Expand Down
4 changes: 3 additions & 1 deletion crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ doctest = false
env_logger = { workspace = true, optional = true }
anyhow = { workspace = true }
once_cell = { workspace = true }
wasmtime = { workspace = true, features = ['cranelift', 'runtime', 'gc', 'std'] }
wasmtime = { workspace = true, features = ['runtime', 'gc', 'std'] }
wasmtime-c-api-macros = { workspace = true }
log = { workspace = true }
tracing = { workspace = true }
Expand Down Expand Up @@ -51,6 +51,8 @@ addr2line = ["wasmtime/addr2line"]
demangle = ["wasmtime/demangle"]
threads = ["wasmtime/threads"]
gc = ["wasmtime/gc"]
cranelift = ['wasmtime/cranelift']
winch = ['wasmtime/winch']
# ... if you add a line above this be sure to also change:
#
# crates/c-api/artifact/Cargo.toml
4 changes: 4 additions & 0 deletions crates/c-api/artifact/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ default = [
'demangle',
'threads',
'gc',
'cranelift',
'winch',
# ... if you add a line above this be sure to also change:
#
# crates/c-api/CMakeLists.txt
Expand All @@ -50,5 +52,7 @@ demangle = ["wasmtime-c-api/demangle"]
wat = ["wasmtime-c-api/wat"]
threads = ["wasmtime-c-api/threads"]
gc = ["wasmtime-c-api/gc"]
cranelift = ["wasmtime-c-api/cranelift"]
winch = ["wasmtime-c-api/winch"]
# ... if you add a line above this be sure to read the comment at the end of
# `default`
6 changes: 6 additions & 0 deletions crates/c-api/include/wasmtime/conf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
#cmakedefine WASMTIME_FEATURE_THREADS
#cmakedefine WASMTIME_FEATURE_GC
#cmakedefine WASMTIME_FEATURE_ASYNC
#cmakedefine WASMTIME_FEATURE_CRANELIFT
#cmakedefine WASMTIME_FEATURE_WINCH

#if defined(WASMTIME_FEATURE_CRANELIFT) || defined(WASMTIME_FEATURE_WINCH)
#define WASMTIME_FEATURE_COMPILER
#endif

#endif // WASMTIME_CONF_H
12 changes: 12 additions & 0 deletions crates/c-api/include/wasmtime/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,17 @@ WASMTIME_CONFIG_PROP(void, wasm_multi_memory, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_memory64, bool)

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Configures how JIT code will be compiled.
*
* This setting is #WASMTIME_STRATEGY_AUTO by default.
*/
WASMTIME_CONFIG_PROP(void, strategy, wasmtime_strategy_t)

#endif // WASMTIME_FEATURE_COMPILER

#ifdef WASMTIME_FEATURE_PARALLEL_COMPILATION

/**
Expand All @@ -260,6 +264,8 @@ WASMTIME_CONFIG_PROP(void, parallel_compilation, bool)

#endif // WASMTIME_FEATURE_PARALLEL_COMPILATION

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Configures whether Cranelift's debug verifier is enabled.
*
Expand Down Expand Up @@ -292,6 +298,8 @@ WASMTIME_CONFIG_PROP(void, cranelift_nan_canonicalization, bool)
*/
WASMTIME_CONFIG_PROP(void, cranelift_opt_level, wasmtime_opt_level_t)

#endif // WASMTIME_FEATURE_COMPILER

/**
* \brief Configures the profiling strategy used for JIT code.
*
Expand Down Expand Up @@ -372,6 +380,8 @@ wasmtime_config_cache_config_load(wasm_config_t *, const char *);

#endif // WASMTIME_FEATURE_CACHE

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Configures the target triple that this configuration will produce
* machine code for.
Expand Down Expand Up @@ -411,6 +421,8 @@ WASM_API_EXTERN void wasmtime_config_cranelift_flag_set(wasm_config_t *,
const char *key,
const char *value);

#endif // WASMTIME_FEATURE_COMPILER

/**
* \brief Configures whether, when on macOS, Mach ports are used for exception
* handling instead of traditional Unix-based signal handling.
Expand Down
8 changes: 8 additions & 0 deletions crates/c-api/include/wasmtime/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C" {
*/
typedef struct wasmtime_module wasmtime_module_t;

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Compiles a WebAssembly binary into a #wasmtime_module_t
*
Expand All @@ -46,6 +48,8 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_module_new(wasm_engine_t *engine,
size_t wasm_len,
wasmtime_module_t **ret);

#endif // WASMTIME_FEATURE_COMPILER

/**
* \brief Deletes a module.
*/
Expand All @@ -69,6 +73,8 @@ WASM_API_EXTERN void wasmtime_module_imports(const wasmtime_module_t *module,
WASM_API_EXTERN void wasmtime_module_exports(const wasmtime_module_t *module,
wasm_exporttype_vec_t *out);

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Validate a WebAssembly binary.
*
Expand Down Expand Up @@ -101,6 +107,8 @@ wasmtime_module_validate(wasm_engine_t *engine, const uint8_t *wasm,
WASM_API_EXTERN wasmtime_error_t *
wasmtime_module_serialize(wasmtime_module_t *module, wasm_byte_vec_t *ret);

#endif // WASMTIME_FEATURE_COMPILER

/**
* \brief Build a module from serialized data.
*
Expand Down
7 changes: 7 additions & 0 deletions crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub extern "C" fn wasmtime_config_wasm_memory64_set(c: &mut wasm_config_t, enabl
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_config_strategy_set(
c: &mut wasm_config_t,
strategy: wasmtime_strategy_t,
Expand All @@ -156,6 +157,7 @@ pub extern "C" fn wasmtime_config_parallel_compilation_set(c: &mut wasm_config_t
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_config_cranelift_debug_verifier_set(
c: &mut wasm_config_t,
enable: bool,
Expand All @@ -164,6 +166,7 @@ pub extern "C" fn wasmtime_config_cranelift_debug_verifier_set(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_config_cranelift_nan_canonicalization_set(
c: &mut wasm_config_t,
enable: bool,
Expand All @@ -172,6 +175,7 @@ pub extern "C" fn wasmtime_config_cranelift_nan_canonicalization_set(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_config_cranelift_opt_level_set(
c: &mut wasm_config_t,
opt_level: wasmtime_opt_level_t,
Expand Down Expand Up @@ -251,6 +255,7 @@ pub extern "C" fn wasmtime_config_native_unwind_info_set(c: &mut wasm_config_t,
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_config_target_set(
c: &mut wasm_config_t,
target: *const c_char,
Expand All @@ -265,6 +270,7 @@ pub extern "C" fn wasmtime_config_macos_use_mach_ports_set(c: &mut wasm_config_t
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_config_cranelift_flag_enable(
c: &mut wasm_config_t,
flag: *const c_char,
Expand All @@ -274,6 +280,7 @@ pub unsafe extern "C" fn wasmtime_config_cranelift_flag_enable(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_config_cranelift_flag_set(
c: &mut wasm_config_t,
flag: *const c_char,
Expand Down
6 changes: 6 additions & 0 deletions crates/c-api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct wasm_shared_module_t {
wasmtime_c_api_macros::declare_own!(wasm_shared_module_t);

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasm_module_new(
store: &mut wasm_store_t,
binary: &wasm_byte_vec_t,
Expand All @@ -40,6 +41,7 @@ pub unsafe extern "C" fn wasm_module_new(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasm_module_validate(
store: &mut wasm_store_t,
binary: &wasm_byte_vec_t,
Expand Down Expand Up @@ -105,6 +107,7 @@ pub unsafe extern "C" fn wasm_module_obtain(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasm_module_serialize(module: &wasm_module_t, ret: &mut wasm_byte_vec_t) {
if let Ok(buf) = module.module.serialize() {
ret.set_buffer(buf);
Expand All @@ -130,6 +133,7 @@ pub struct wasmtime_module_t {
wasmtime_c_api_macros::declare_own!(wasmtime_module_t);

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_module_new(
engine: &wasm_engine_t,
wasm: *const u8,
Expand Down Expand Up @@ -166,6 +170,7 @@ pub extern "C" fn wasmtime_module_imports(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_module_validate(
engine: &wasm_engine_t,
wasm: *const u8,
Expand All @@ -176,6 +181,7 @@ pub unsafe extern "C" fn wasmtime_module_validate(
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_module_serialize(
module: &wasmtime_module_t,
ret: &mut wasm_byte_vec_t,
Expand Down