MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / load_module_contents

Method load_module_contents

src/common.rs:261–312  ·  view source on GitHub ↗
(
        &self,
        engine: &Engine,
        path: &Path,
        bytes: &[u8],
        deserialize_module: impl FnOnce() -> Result<Module>,
        #[cfg(feature = "component-model")] deserializ

Source from the content-addressed store, hash-verified

259 }
260
261 pub fn load_module_contents(
262 &self,
263 engine: &Engine,
264 path: &Path,
265 bytes: &[u8],
266 deserialize_module: impl FnOnce() -> Result<Module>,
267 #[cfg(feature = "component-model")] deserialize_component: impl FnOnce() -> Result<Component>,
268 ) -> Result<RunTarget> {
269 Ok(match Engine::detect_precompiled(bytes) {
270 Some(Precompiled::Module) => {
271 self.ensure_allow_precompiled()?;
272 RunTarget::Core(deserialize_module()?)
273 }
274 #[cfg(feature = "component-model")]
275 Some(Precompiled::Component) => {
276 self.ensure_allow_precompiled()?;
277 self.ensure_allow_components()?;
278 RunTarget::Component(deserialize_component()?)
279 }
280 #[cfg(not(feature = "component-model"))]
281 Some(Precompiled::Component) => {
282 bail!("support for components was not enabled at compile time");
283 }
284 #[cfg(any(feature = "cranelift", feature = "winch"))]
285 None => {
286 let mut code = wasmtime::CodeBuilder::new(engine);
287 code.wasm_binary_or_text(bytes, Some(path))?;
288 match code.hint() {
289 Some(wasmtime::CodeHint::Component) => {
290 #[cfg(feature = "component-model")]
291 {
292 self.ensure_allow_components()?;
293 RunTarget::Component(code.compile_component()?)
294 }
295 #[cfg(not(feature = "component-model"))]
296 {
297 bail!("support for components was not enabled at compile time");
298 }
299 }
300 Some(wasmtime::CodeHint::Module) | None => {
301 RunTarget::Core(code.compile_module()?)
302 }
303 }
304 }
305
306 #[cfg(not(any(feature = "cranelift", feature = "winch")))]
307 None => {
308 let _ = (path, engine);
309 bail!("support for compiling modules was disabled at compile time");
310 }
311 })
312 }
313
314 pub fn configure_wasip2(&self, builder: &mut WasiCtxBuilder) -> Result<()> {
315 // It's ok to block the current thread since we're the only thread in

Callers 1

load_moduleMethod · 0.80

Calls 10

OkFunction · 0.85
wasm_binary_or_textMethod · 0.80
hintMethod · 0.80
compile_moduleMethod · 0.80
detect_precompiledFunction · 0.50
ComponentClass · 0.50
newFunction · 0.50
compile_componentMethod · 0.45

Tested by

no test coverage detected