Skip to content

Commit 63cccaa

Browse files
committed
Add wasmi recipe
1 parent 521306f commit 63cccaa

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed

.github/workflows/export.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
conan export m4/all --version=1.4.19
3838
conan export snappy/all --version=1.1.10
3939
conan export soci/all --version=4.0.3
40+
conan export wasmi/all --version=0.42.1
4041
conan export wasm-xrplf/all --version=2.4.1-xrplf
4142
- name: Upload the recipes (dry run)
4243
run: conan upload '*' --confirm --check --only-recipe --remote ${{ vars.CONAN_REMOTE_NAME }} --dry-run

recipes/wasmi/all/conandata.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Do not update. Maintained by programmability team.
2+
3+
sources:
4+
"0.42.1":
5+
sha256: 2a5697be33c7afce8f671af4a5a3621d9e93ce55d253d31bd8201458e465fbb8
6+
url: https://github.com/wasmi-labs/wasmi/archive/refs/tags/v0.42.1.tar.gz
7+
patches:
8+
"0.42.1":
9+
- patch_file: "patches/0001-xrplf-0.42.1.patch"
10+
patch_type: conan

recipes/wasmi/all/conanfile.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from conan import ConanFile, tools
2+
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
3+
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get
4+
import os
5+
6+
required_conan_version = ">=2.0.0"
7+
8+
class WasmiConan(ConanFile):
9+
name = "wasmi"
10+
license = "Apache License v2.0"
11+
url = "https://github.com/wasmi-labs/wasmi.git"
12+
description = "WebAssembly (Wasm) interpreter"
13+
package_type = "library"
14+
settings = "os", "arch", "compiler", "build_type"
15+
options = {"shared": [True, False]}
16+
default_options = {"shared": False}
17+
18+
def export_sources(self):
19+
export_conandata_patches(self)
20+
21+
def config_options(self):
22+
pass
23+
24+
def layout(self):
25+
cmake_layout(self, src_folder="src")
26+
27+
def source(self):
28+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
29+
30+
def generate(self):
31+
tc = CMakeToolchain(self)
32+
33+
tc.variables["CMAKE_CXX_STANDARD"] = 20
34+
tc.variables["BUILD_SHARED_LIBS"] = 0
35+
36+
tc.generate()
37+
38+
deps = CMakeDeps(self)
39+
deps.generate()
40+
41+
def build(self):
42+
apply_conandata_patches(self)
43+
cmake = CMake(self)
44+
cmake.verbose = True
45+
cmake.configure(build_script_folder=os.path.join(self.source_folder, "crates", "c_api"))
46+
cmake.build()
47+
48+
def package(self):
49+
cmake = CMake(self)
50+
cmake.verbose = True
51+
cmake.install()
52+
53+
def package_info(self):
54+
self.cpp_info.libs = ["wasmi"]
55+
self.cpp_info.names["cmake_find_package"] = "wasmi"
56+
self.cpp_info.names["cmake_find_package_multi"] = "wasmi"
57+
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
+

recipes/wasmi/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"0.42.1":
3+
folder: all

0 commit comments

Comments
 (0)