Remove usage of CompilationStrategy from Config (#764)
* 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
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use faerie::{Artifact, Decl, Link};
|
||||
use wasmtime_environ::entity::EntityRef;
|
||||
use wasmtime_environ::settings;
|
||||
@@ -19,26 +20,23 @@ pub fn declare_functions(
|
||||
obj: &mut Artifact,
|
||||
module: &Module,
|
||||
relocations: &Relocations,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
for i in 0..module.imported_funcs.len() {
|
||||
let string_name = format!("_wasm_function_{}", i);
|
||||
obj.declare(string_name, Decl::function_import())
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
obj.declare(string_name, Decl::function_import())?;
|
||||
}
|
||||
for (_, function_relocs) in relocations.iter() {
|
||||
for r in function_relocs {
|
||||
let special_import_name = get_reloc_target_special_import_name(r.reloc_target);
|
||||
if let Some(special_import_name) = special_import_name {
|
||||
obj.declare(special_import_name, Decl::function_import())
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
obj.declare(special_import_name, Decl::function_import())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i, _function_relocs) in relocations.iter().rev() {
|
||||
let func_index = module.func_index(i);
|
||||
let string_name = format!("_wasm_function_{}", func_index.index());
|
||||
obj.declare(string_name, Decl::function().global())
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
obj.declare(string_name, Decl::function().global())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -49,7 +47,7 @@ pub fn emit_functions(
|
||||
module: &Module,
|
||||
compilation: &Compilation,
|
||||
relocations: &Relocations,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
debug_assert!(
|
||||
module.start_func.is_none()
|
||||
|| module.start_func.unwrap().index() >= module.imported_funcs.len(),
|
||||
@@ -66,8 +64,7 @@ pub fn emit_functions(
|
||||
let func_index = module.func_index(i);
|
||||
let string_name = format!("_wasm_function_{}", func_index.index());
|
||||
|
||||
obj.define(string_name, body.clone())
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
obj.define(string_name, body.clone())?;
|
||||
}
|
||||
|
||||
for (i, function_relocs) in relocations.iter() {
|
||||
@@ -82,8 +79,7 @@ pub fn emit_functions(
|
||||
from: &string_name,
|
||||
to: &target_name,
|
||||
at: r.offset as u64,
|
||||
})
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
})?;
|
||||
}
|
||||
RelocationTarget::Memory32Grow
|
||||
| RelocationTarget::ImportedMemory32Grow
|
||||
@@ -93,8 +89,7 @@ pub fn emit_functions(
|
||||
from: &string_name,
|
||||
to: get_reloc_target_special_import_name(r.reloc_target).expect("name"),
|
||||
at: r.offset as u64,
|
||||
})
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
})?;
|
||||
}
|
||||
RelocationTarget::JumpTable(_, _) => {
|
||||
// ignore relocations for jump tables
|
||||
|
||||
Reference in New Issue
Block a user