(
engine: &Engine,
binary: &[u8],
_dwarf_package: Option<&[u8]>,
unsafe_intrinsics_import: Option<&str>,
obj_state: &T::State,
)
| 141 | /// an owned mmap along with metadata about the compilation itself. |
| 142 | #[cfg(feature = "component-model")] |
| 143 | pub(crate) fn build_component_artifacts<T: FinishedObject>( |
| 144 | engine: &Engine, |
| 145 | binary: &[u8], |
| 146 | _dwarf_package: Option<&[u8]>, |
| 147 | unsafe_intrinsics_import: Option<&str>, |
| 148 | obj_state: &T::State, |
| 149 | ) -> Result<(T, Option<wasmtime_environ::component::ComponentArtifacts>)> { |
| 150 | use wasmtime_environ::ScopeVec; |
| 151 | use wasmtime_environ::component::{ |
| 152 | CompiledComponentInfo, ComponentArtifacts, ComponentTypesBuilder, |
| 153 | }; |
| 154 | |
| 155 | let compiler = engine.try_compiler()?; |
| 156 | let tunables = engine.tunables(); |
| 157 | |
| 158 | let scope = ScopeVec::new(); |
| 159 | let mut validator = wasmparser::Validator::new_with_features(engine.features()); |
| 160 | let mut types = ComponentTypesBuilder::new(&validator); |
| 161 | let mut translator = Translator::new(tunables, &mut validator, &mut types, &scope); |
| 162 | if let Some(name) = unsafe_intrinsics_import { |
| 163 | translator.expose_unsafe_intrinsics(name); |
| 164 | } |
| 165 | let (component, mut module_translations) = translator |
| 166 | .translate(binary) |
| 167 | .context("failed to parse WebAssembly module")?; |
| 168 | |
| 169 | for (_, translation) in module_translations.iter_mut() { |
| 170 | prepare_translation( |
| 171 | engine, |
| 172 | compiler, |
| 173 | translation, |
| 174 | types.module_types_builder_mut(), |
| 175 | ); |
| 176 | } |
| 177 | |
| 178 | let compile_inputs = CompileInputs::for_component( |
| 179 | engine, |
| 180 | &types, |
| 181 | &component, |
| 182 | module_translations.iter_mut().map(|(i, translation)| { |
| 183 | let functions = mem::take(&mut translation.function_body_inputs); |
| 184 | (i, &*translation, functions) |
| 185 | }), |
| 186 | ); |
| 187 | let unlinked_compile_outputs = compile_inputs.compile(&engine, types.module_types_builder())?; |
| 188 | |
| 189 | let PreLinkOutput { |
| 190 | needs_gc_heap, |
| 191 | compiled_funcs, |
| 192 | indices, |
| 193 | } = unlinked_compile_outputs.pre_link(); |
| 194 | for (_, t) in &mut module_translations { |
| 195 | t.module.needs_gc_heap |= needs_gc_heap |
| 196 | } |
| 197 | |
| 198 | // Collect bytecode slices here before moving `module_translations` below. |
| 199 | let module_wasms = if tunables.debug_guest { |
| 200 | module_translations |
no test coverage detected