* Remove usage of `CompilationStrategy` from `Config` This commit removes the public API usage of the internal `CompilationStrategy` enumeration from the `Config` type in the `wasmtime` crate. To do this the `enum` was copied locally into the crate and renamed `Strategy`. The high-level description of this change is: * The `Config::strategy` method now takes a locally-defined `Strategy` enumeration instead of an internal type. * The contents of `Strategy` are always the same, not relying on Cargo features to indicate which variants are present. This avoids unnecessary downstream `#[cfg]`. * A `lightbeam` feature was added to the `wasmtime` crate itself to lightbeam compilation support. * The `Config::strategy` method is now fallible. It returns a runtime error if support for the selected strategy wasn't compiled in. * The `Strategy` enum is listed as `#[non_exhaustive]` so we can safely add variants over time to it. This reduces the public crate dependencies of the `wasmtime` crate itself, removing the need to reach into internal crates even more! cc #708 * Fix fuzz targets * Update nightly used to build releases * Run rustfmt
62 lines
1.8 KiB
Rust
62 lines
1.8 KiB
Rust
use crate::context::layout_vmcontext;
|
|
use crate::data_segment::{declare_data_segment, emit_data_segment};
|
|
use crate::function::{declare_functions, emit_functions};
|
|
use crate::table::{declare_table, emit_table};
|
|
use anyhow::Result;
|
|
use faerie::{Artifact, Decl, Link};
|
|
use wasmtime_environ::isa::TargetFrontendConfig;
|
|
use wasmtime_environ::{Compilation, DataInitializer, Module, Relocations};
|
|
|
|
fn emit_vmcontext_init(
|
|
obj: &mut Artifact,
|
|
module: &Module,
|
|
target_config: &TargetFrontendConfig,
|
|
) -> Result<()> {
|
|
let (data, table_relocs) = layout_vmcontext(module, target_config);
|
|
obj.declare_with("_vmcontext_init", Decl::data().global(), data.to_vec())?;
|
|
for reloc in table_relocs.iter() {
|
|
let target_name = format!("_table_{}", reloc.index);
|
|
obj.link(Link {
|
|
from: "_vmcontext_init",
|
|
to: &target_name,
|
|
at: reloc.offset as u64,
|
|
})?;
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// Emits a module that has been emitted with the `wasmtime-environ` environment
|
|
/// implementation to a native object file.
|
|
pub fn emit_module(
|
|
obj: &mut Artifact,
|
|
module: &Module,
|
|
compilation: &Compilation,
|
|
relocations: &Relocations,
|
|
data_initializers: &[DataInitializer],
|
|
target_config: &TargetFrontendConfig,
|
|
) -> Result<()> {
|
|
declare_functions(obj, module, relocations)?;
|
|
|
|
for (i, initializer) in data_initializers.iter().enumerate() {
|
|
declare_data_segment(obj, initializer, i)?;
|
|
}
|
|
|
|
for i in 0..module.table_plans.len() {
|
|
declare_table(obj, i)?;
|
|
}
|
|
|
|
emit_functions(obj, module, compilation, relocations)?;
|
|
|
|
for (i, initializer) in data_initializers.iter().enumerate() {
|
|
emit_data_segment(obj, initializer, i)?;
|
|
}
|
|
|
|
for i in 0..module.table_plans.len() {
|
|
emit_table(obj, i)?;
|
|
}
|
|
|
|
emit_vmcontext_init(obj, module, target_config)?;
|
|
|
|
Ok(())
|
|
}
|