|
| 1 | +diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt |
| 2 | +index b15c787a..2420bea2 100644 |
| 3 | +--- a/crates/c_api/CMakeLists.txt |
| 4 | ++++ b/crates/c_api/CMakeLists.txt |
| 5 | +@@ -43,6 +43,11 @@ endif() |
| 6 | + list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/) |
| 7 | + list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/) |
| 8 | + |
| 9 | ++if(NOT BUILD_SHARED_LIBS) |
| 10 | ++ set(WASMI_SHARED_FILES ) |
| 11 | ++endif() |
| 12 | ++ |
| 13 | ++ |
| 14 | + # Instructions on how to build and install the Wasmi Rust crate. |
| 15 | + find_program(WASMI_CARGO_BINARY cargo REQUIRED) |
| 16 | + include(ExternalProject) |
| 17 | +@@ -112,23 +117,25 @@ install( |
| 18 | + DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 19 | + ) |
| 20 | + |
| 21 | +-if(WASMI_TARGET MATCHES "darwin") |
| 22 | +- set(INSTALLED_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwasmi.dylib") |
| 23 | +- install( |
| 24 | +- FILES "${INSTALLED_LIB}" |
| 25 | +- DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" |
| 26 | +- COMPONENT Runtime |
| 27 | +- ) |
| 28 | +- if(NOT CMAKE_INSTALL_NAME_TOOL) |
| 29 | +- message(WARNING "CMAKE_INSTALL_NAME_TOOL is not set. LC_ID_DYLIB for libwasmi.dylib will not be set.") |
| 30 | +- else() |
| 31 | +- set(install_name_tool_cmd |
| 32 | +- "${CMAKE_INSTALL_NAME_TOOL}" |
| 33 | +- "-id" |
| 34 | +- "@rpath/libwasmi.dylib" |
| 35 | +- "${INSTALLED_LIB}" |
| 36 | ++if(BUILD_SHARED_LIBS) |
| 37 | ++ if(WASMI_TARGET MATCHES "darwin") |
| 38 | ++ set(INSTALLED_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwasmi.dylib") |
| 39 | ++ install( |
| 40 | ++ FILES "${INSTALLED_LIB}" |
| 41 | ++ DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" |
| 42 | ++ COMPONENT Runtime |
| 43 | + ) |
| 44 | +- install(CODE "execute_process(COMMAND ${install_name_tool_cmd})") |
| 45 | ++ if(NOT CMAKE_INSTALL_NAME_TOOL) |
| 46 | ++ message(WARNING "CMAKE_INSTALL_NAME_TOOL is not set. LC_ID_DYLIB for libwasmi.dylib will not be set.") |
| 47 | ++ else() |
| 48 | ++ set(install_name_tool_cmd |
| 49 | ++ "${CMAKE_INSTALL_NAME_TOOL}" |
| 50 | ++ "-id" |
| 51 | ++ "@rpath/libwasmi.dylib" |
| 52 | ++ "${INSTALLED_LIB}" |
| 53 | ++ ) |
| 54 | ++ install(CODE "execute_process(COMMAND ${install_name_tool_cmd})") |
| 55 | ++ endif() |
| 56 | + endif() |
| 57 | + endif() |
| 58 | + |
| 59 | +diff --git a/crates/c_api/include/wasm.h b/crates/c_api/include/wasm.h |
| 60 | +index 5ee617ff..0199192d 100644 |
| 61 | +--- a/crates/c_api/include/wasm.h |
| 62 | ++++ b/crates/c_api/include/wasm.h |
| 63 | +@@ -146,6 +146,13 @@ WASM_DECLARE_OWN(store) |
| 64 | + |
| 65 | + WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*); |
| 66 | + |
| 67 | ++// Store fuel functions (forward declarations) |
| 68 | ++struct wasmi_error; |
| 69 | ++ |
| 70 | ++WASM_API_EXTERN struct wasmi_error* wasm_store_get_fuel(const wasm_store_t*, uint64_t* fuel); |
| 71 | ++WASM_API_EXTERN struct wasmi_error* wasm_store_set_fuel(wasm_store_t*, uint64_t fuel); |
| 72 | ++//WASM_API_EXTERN void *wasm_store_get_data(const wasm_store_t*); |
| 73 | ++//WASM_API_EXTERN void wasm_store_set_data(wasm_store_t*, void *data); |
| 74 | + |
| 75 | + /////////////////////////////////////////////////////////////////////////////// |
| 76 | + // Type Representations |
| 77 | +diff --git a/crates/c_api/include/wasmi.h b/crates/c_api/include/wasmi.h |
| 78 | +index 2caffa37..0c0584ec 100644 |
| 79 | +--- a/crates/c_api/include/wasmi.h |
| 80 | ++++ b/crates/c_api/include/wasmi.h |
| 81 | +@@ -10,7 +10,7 @@ |
| 82 | + /** |
| 83 | + * \brief Wasmi version string. |
| 84 | + */ |
| 85 | +-#define WASMI_VERSION "0.35.0" |
| 86 | ++#define WASMI_VERSION "0.42.1" |
| 87 | + /** |
| 88 | + * \brief Wasmi major version number. |
| 89 | + */ |
| 90 | +@@ -18,10 +18,10 @@ |
| 91 | + /** |
| 92 | + * \brief Wasmi minor version number. |
| 93 | + */ |
| 94 | +-#define WASMI_VERSION_MINOR 35 |
| 95 | ++#define WASMI_VERSION_MINOR 42 |
| 96 | + /** |
| 97 | + * \brief Wasmi patch version number. |
| 98 | + */ |
| 99 | +-#define WASMI_VERSION_PATCH 0 |
| 100 | ++#define WASMI_VERSION_PATCH 1 |
| 101 | + |
| 102 | + #endif // WASMI_H |
| 103 | +diff --git a/crates/c_api/src/store.rs b/crates/c_api/src/store.rs |
| 104 | +index 56d4898f..543dbff8 100644 |
| 105 | +--- a/crates/c_api/src/store.rs |
| 106 | ++++ b/crates/c_api/src/store.rs |
| 107 | +@@ -175,3 +175,44 @@ pub extern "C" fn wasmi_context_set_fuel( |
| 108 | + ) -> Option<Box<wasmi_error_t>> { |
| 109 | + crate::handle_result(store.set_fuel(fuel), |()| {}) |
| 110 | + } |
| 111 | ++ |
| 112 | ++//////////////////////////////////////////////////////////////////////////////////////// |
| 113 | ++//////////////////////////////////////////////////////////////////////////////////////// |
| 114 | ++//////////////////////////////////////////////////////////////////////////////////////// |
| 115 | ++//////////////////////////////////////////////////////////////////////////////////////// |
| 116 | ++ |
| 117 | ++/// Returns the current fuel of the wasm store context in `fuel`. |
| 118 | ++/// |
| 119 | ++/// Wraps [`Store::get_fuel`]. |
| 120 | ++/// |
| 121 | ++/// # Errors |
| 122 | ++/// |
| 123 | ++/// If [`Store::get_fuel`] errors. |
| 124 | ++#[no_mangle] |
| 125 | ++pub extern "C" fn wasm_store_get_fuel( |
| 126 | ++ store: &wasm_store_t, |
| 127 | ++ fuel: &mut u64, |
| 128 | ++) -> Option<Box<wasmi_error_t>> { |
| 129 | ++ let context = unsafe { store.inner.context() }; |
| 130 | ++ crate::handle_result(context.get_fuel(), |amt| { |
| 131 | ++ *fuel = amt; |
| 132 | ++ }) |
| 133 | ++} |
| 134 | ++ |
| 135 | ++/// Sets the current fuel of the wasm store context to `fuel`. |
| 136 | ++/// |
| 137 | ++/// Wraps [`Store::set_fuel`]. |
| 138 | ++/// |
| 139 | ++/// # Errors |
| 140 | ++/// |
| 141 | ++/// If [`Store::set_fuel`] errors. |
| 142 | ++#[no_mangle] |
| 143 | ++pub extern "C" fn wasm_store_set_fuel( |
| 144 | ++ store: &mut wasm_store_t, |
| 145 | ++ fuel: u64, |
| 146 | ++) -> Option<Box<wasmi_error_t>> { |
| 147 | ++ |
| 148 | ++ let mut context = unsafe { store.inner.context_mut() }; |
| 149 | ++ crate::handle_result(context.set_fuel(fuel), |()| {}) |
| 150 | ++} |
| 151 | ++ |
0 commit comments