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

Method load_main_module

src/commands/run.rs:682–773  ·  view source on GitHub ↗
(
        &self,
        store: &mut Store<Host>,
        linker: &mut CliLinker,
        main_target: &RunTarget,
        profiled_modules: Vec<(String, Module)>,
    )

Source from the content-addressed store, hash-verified

680 }
681
682 async fn load_main_module(
683 &self,
684 store: &mut Store<Host>,
685 linker: &mut CliLinker,
686 main_target: &RunTarget,
687 profiled_modules: Vec<(String, Module)>,
688 ) -> Result<CliInstance> {
689 // The main module might be allowed to have unknown imports, which
690 // should be defined as traps:
691 if self.run.common.wasm.unknown_imports_trap == Some(true) {
692 match linker {
693 CliLinker::Core(linker) => {
694 linker.define_unknown_imports_as_traps(main_target.unwrap_core())?;
695 }
696 #[cfg(feature = "component-model")]
697 CliLinker::Component(linker) => {
698 linker.define_unknown_imports_as_traps(main_target.unwrap_component())?;
699 }
700 }
701 }
702
703 // ...or as default values.
704 if self.run.common.wasm.unknown_imports_default == Some(true) {
705 match linker {
706 CliLinker::Core(linker) => {
707 linker.define_unknown_imports_as_default_values(
708 &mut *store,
709 main_target.unwrap_core(),
710 )?;
711 }
712 _ => bail!("cannot use `--default-values-unknown-imports` with components"),
713 }
714 }
715
716 let finish_epoch_handler =
717 self.setup_epoch_handler(store, main_target, profiled_modules)?;
718
719 let result = match linker {
720 CliLinker::Core(linker) => {
721 let module = main_target.unwrap_core();
722 let instance = linker
723 .instantiate_async(&mut *store, &module)
724 .await
725 .with_context(|| {
726 format!("failed to instantiate {:?}", self.module_and_args[0])
727 })?;
728
729 // If `_initialize` is present, meaning a reactor, then invoke
730 // the function.
731 if let Some(func) = instance.get_func(&mut *store, "_initialize") {
732 func.typed::<(), ()>(&store)?
733 .call_async(&mut *store, ())
734 .await?;
735 }
736
737 // Look for the specific function provided or otherwise look for
738 // "" or "_start" exports to run as a "main" function.
739 let func = if let Some(name) = &self.invoke {

Callers 1

instantiate_and_runMethod · 0.80

Calls 15

OkFunction · 0.85
unwrap_coreMethod · 0.80
unwrap_componentMethod · 0.80
setup_epoch_handlerMethod · 0.80
with_contextMethod · 0.80
invoke_funcMethod · 0.80
invoke_componentMethod · 0.80
run_command_componentMethod · 0.80
handle_core_dumpMethod · 0.80
instantiate_asyncMethod · 0.45

Tested by

no test coverage detected