(
&self,
store: &mut Store<Host>,
linker: &mut CliLinker,
main_target: &RunTarget,
profiled_modules: Vec<(String, Module)>,
)
| 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 { |
no test coverage detected