1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use crate::{
get_global_store,
module::{Module, ModuleInfo},
new,
};
use std::str::FromStr;
pub use new::wasmer_cache::FileSystemCache;
#[derive(Debug)]
pub enum Error {
DeserializeError(new::wasmer_engine::DeserializeError),
SerializeError(new::wasmer_engine::SerializeError),
}
pub struct Artifact {
new_module: new::wasmer::Module,
}
impl Artifact {
pub(crate) fn new(new_module: new::wasmer::Module) -> Self {
Self { new_module }
}
pub fn serialize(&self) -> Result<Vec<u8>, Error> {
self.new_module.serialize().map_err(Error::SerializeError)
}
pub unsafe fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
Ok(Self::new(
new::wasmer::Module::deserialize(&get_global_store(), bytes)
.map_err(Error::DeserializeError)?,
))
}
pub fn module(self) -> Module {
Module::new(self.new_module)
}
pub fn info(&self) -> &ModuleInfo {
self.new_module.info()
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct WasmHash {
new_hash: new::wasmer_cache::Hash,
}
impl WasmHash {
pub fn generate(wasm_bytes: &[u8]) -> Self {
Self {
new_hash: new::wasmer_cache::Hash::generate(wasm_bytes),
}
}
pub fn encode(self) -> String {
self.new_hash.to_string()
}
pub fn decode(hex_str: &str) -> Result<Self, new::wasmer_engine::DeserializeError> {
Ok(Self {
new_hash: new::wasmer_cache::Hash::from_str(hex_str)?,
})
}
}
pub const WASMER_VERSION_HASH: &'static str =
include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt"));