mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
WASMI data
This commit is contained in:
5
external/wasmi/conandata.yml
vendored
Normal file
5
external/wasmi/conandata.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
patches:
|
||||
0.42.1:
|
||||
- patch_description: install only static lib (to prevent conflict with shared)
|
||||
patch_file: patches/wasmi.patch
|
||||
patch_type: conan
|
||||
90
external/wasmi/conanfile.py
vendored
Normal file
90
external/wasmi/conanfile.py
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
from conan import ConanFile, tools
|
||||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
|
||||
from conan.tools.files import (
|
||||
apply_conandata_patches,
|
||||
export_conandata_patches,
|
||||
# get,
|
||||
)
|
||||
from conan.tools.scm import Git
|
||||
|
||||
import os
|
||||
# import json
|
||||
|
||||
required_conan_version = ">=1.55.0"
|
||||
|
||||
class WasmiConan(ConanFile):
|
||||
name = "wasmi"
|
||||
license = "Apache License v2.0"
|
||||
url = "https://github.com/wasmi-labs/wasmi.git"
|
||||
description = "WebAssembly (Wasm) interpreter"
|
||||
package_type = "library"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
options = {"shared": [True, False]}
|
||||
default_options = {"shared": False}
|
||||
# generators = "CMakeToolchain", "CMakeDeps"
|
||||
#requires = [("llvm/20.1.1@")]
|
||||
|
||||
def export_sources(self):
|
||||
export_conandata_patches(self)
|
||||
pass
|
||||
|
||||
# def build_requirements(self):
|
||||
# self.tool_requires("llvm/20.1.1")
|
||||
|
||||
|
||||
def config_options(self):
|
||||
#if self.settings.os == "Windows":
|
||||
# del self.options.fPIC
|
||||
pass
|
||||
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self, src_folder="src")
|
||||
|
||||
|
||||
def source(self):
|
||||
git = Git(self)
|
||||
git.fetch_commit(
|
||||
url="https://github.com/wasmi-labs/wasmi.git",
|
||||
commit="f628a7a86c9715f2c306f6ef9aea1cc2bdca5fa7",
|
||||
)
|
||||
#get(self, **self.conan_data["sources"][self.version], strip_root=True)
|
||||
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
|
||||
tc.variables["CMAKE_CXX_STANDARD"] = 20
|
||||
tc.variables["BUILD_SHARED_LIBS"] = 0
|
||||
|
||||
tc.generate()
|
||||
|
||||
# This generates "foo-config.cmake" and "bar-config.cmake" in self.generators_folder
|
||||
deps = CMakeDeps(self)
|
||||
deps.generate()
|
||||
|
||||
|
||||
def build(self):
|
||||
apply_conandata_patches(self)
|
||||
cmake = CMake(self)
|
||||
cmake.verbose = True
|
||||
cmake.configure(build_script_folder=os.path.join(self.source_folder, "crates", "c_api"))
|
||||
cmake.build()
|
||||
#self.run(f'echo {self.source_folder}')
|
||||
|
||||
# Explicit way:
|
||||
# self.run('cmake %s/hello %s' % (self.source_folder, cmake.command_line))
|
||||
# self.run("cmake --build . %s" % cmake.build_config)
|
||||
|
||||
|
||||
def package(self):
|
||||
cmake = CMake(self)
|
||||
cmake.verbose = True
|
||||
cmake.install()
|
||||
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.libs = ["wasmi"]
|
||||
self.cpp_info.names["cmake_find_package"] = "wasmi"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "wasmi"
|
||||
|
||||
15
external/wasmi/patches/static_only.patch
vendored
Normal file
15
external/wasmi/patches/static_only.patch
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt
|
||||
index b15c787..97dd294 100644
|
||||
--- a/crates/c_api/CMakeLists.txt
|
||||
+++ b/crates/c_api/CMakeLists.txt
|
||||
@@ -43,6 +43,10 @@ endif()
|
||||
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||
|
||||
+if(NOT BUILD_SHARED_LIBS)
|
||||
+ set(WASMI_SHARED_FILES )
|
||||
+endif()
|
||||
+
|
||||
# Instructions on how to build and install the Wasmi Rust crate.
|
||||
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
|
||||
include(ExternalProject)
|
||||
109
external/wasmi/patches/wasmi.patch
vendored
Normal file
109
external/wasmi/patches/wasmi.patch
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt
|
||||
index b15c787a..0d0a04b7 100644
|
||||
--- a/crates/c_api/CMakeLists.txt
|
||||
+++ b/crates/c_api/CMakeLists.txt
|
||||
@@ -43,6 +43,11 @@ endif()
|
||||
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||
|
||||
+if(NOT BUILD_SHARED_LIBS)
|
||||
+ set(WASMI_SHARED_FILES )
|
||||
+endif()
|
||||
+
|
||||
+
|
||||
# Instructions on how to build and install the Wasmi Rust crate.
|
||||
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
|
||||
include(ExternalProject)
|
||||
diff --git a/crates/c_api/include/wasm.h b/crates/c_api/include/wasm.h
|
||||
index 5ee617ff..0199192d 100644
|
||||
--- a/crates/c_api/include/wasm.h
|
||||
+++ b/crates/c_api/include/wasm.h
|
||||
@@ -146,6 +146,13 @@ WASM_DECLARE_OWN(store)
|
||||
|
||||
WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
|
||||
|
||||
+// Store fuel functions (forward declarations)
|
||||
+struct wasmi_error;
|
||||
+
|
||||
+WASM_API_EXTERN struct wasmi_error* wasm_store_get_fuel(const wasm_store_t*, uint64_t* fuel);
|
||||
+WASM_API_EXTERN struct wasmi_error* wasm_store_set_fuel(wasm_store_t*, uint64_t fuel);
|
||||
+//WASM_API_EXTERN void *wasm_store_get_data(const wasm_store_t*);
|
||||
+//WASM_API_EXTERN void wasm_store_set_data(wasm_store_t*, void *data);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Type Representations
|
||||
diff --git a/crates/c_api/include/wasmi.h b/crates/c_api/include/wasmi.h
|
||||
index 2caffa37..0c0584ec 100644
|
||||
--- a/crates/c_api/include/wasmi.h
|
||||
+++ b/crates/c_api/include/wasmi.h
|
||||
@@ -10,7 +10,7 @@
|
||||
/**
|
||||
* \brief Wasmi version string.
|
||||
*/
|
||||
-#define WASMI_VERSION "0.35.0"
|
||||
+#define WASMI_VERSION "0.42.1"
|
||||
/**
|
||||
* \brief Wasmi major version number.
|
||||
*/
|
||||
@@ -18,10 +18,10 @@
|
||||
/**
|
||||
* \brief Wasmi minor version number.
|
||||
*/
|
||||
-#define WASMI_VERSION_MINOR 35
|
||||
+#define WASMI_VERSION_MINOR 42
|
||||
/**
|
||||
* \brief Wasmi patch version number.
|
||||
*/
|
||||
-#define WASMI_VERSION_PATCH 0
|
||||
+#define WASMI_VERSION_PATCH 1
|
||||
|
||||
#endif // WASMI_H
|
||||
diff --git a/crates/c_api/src/store.rs b/crates/c_api/src/store.rs
|
||||
index 56d4898f..543dbff8 100644
|
||||
--- a/crates/c_api/src/store.rs
|
||||
+++ b/crates/c_api/src/store.rs
|
||||
@@ -175,3 +175,44 @@ pub extern "C" fn wasmi_context_set_fuel(
|
||||
) -> Option<Box<wasmi_error_t>> {
|
||||
crate::handle_result(store.set_fuel(fuel), |()| {})
|
||||
}
|
||||
+
|
||||
+////////////////////////////////////////////////////////////////////////////////////////
|
||||
+////////////////////////////////////////////////////////////////////////////////////////
|
||||
+////////////////////////////////////////////////////////////////////////////////////////
|
||||
+////////////////////////////////////////////////////////////////////////////////////////
|
||||
+
|
||||
+/// Returns the current fuel of the wasm store context in `fuel`.
|
||||
+///
|
||||
+/// Wraps [`Store::get_fuel`].
|
||||
+///
|
||||
+/// # Errors
|
||||
+///
|
||||
+/// If [`Store::get_fuel`] errors.
|
||||
+#[no_mangle]
|
||||
+pub extern "C" fn wasm_store_get_fuel(
|
||||
+ store: &wasm_store_t,
|
||||
+ fuel: &mut u64,
|
||||
+) -> Option<Box<wasmi_error_t>> {
|
||||
+ let context = unsafe { store.inner.context() };
|
||||
+ crate::handle_result(context.get_fuel(), |amt| {
|
||||
+ *fuel = amt;
|
||||
+ })
|
||||
+}
|
||||
+
|
||||
+/// Sets the current fuel of the wasm store context to `fuel`.
|
||||
+///
|
||||
+/// Wraps [`Store::set_fuel`].
|
||||
+///
|
||||
+/// # Errors
|
||||
+///
|
||||
+/// If [`Store::set_fuel`] errors.
|
||||
+#[no_mangle]
|
||||
+pub extern "C" fn wasm_store_set_fuel(
|
||||
+ store: &mut wasm_store_t,
|
||||
+ fuel: u64,
|
||||
+) -> Option<Box<wasmi_error_t>> {
|
||||
+
|
||||
+ let mut context = unsafe { store.inner.context_mut() };
|
||||
+ crate::handle_result(context.set_fuel(fuel), |()| {})
|
||||
+}
|
||||
+
|
||||
Reference in New Issue
Block a user