Skip to content

Commit

Permalink
add runtime feature
Browse files Browse the repository at this point in the history
  • Loading branch information
adambratschikaye committed Jan 10, 2024
1 parent 617ba5e commit fccbf74
Show file tree
Hide file tree
Showing 65 changed files with 1,329 additions and 1,228 deletions.
1 change: 1 addition & 0 deletions cranelift/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub fn infer_native_flags(isa_builder: &mut dyn Configurable) -> Result<(), &'st
// the cpuinfo interface, so we can't rely on it being present for now.
let _ = riscv::cpuinfo_detect(isa_builder);
}
let _ = isa_builder;
Ok(())
}

Expand Down
9 changes: 5 additions & 4 deletions crates/cranelift-shared/src/isa_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ pub struct IsaBuilder<T> {

impl<T> IsaBuilder<T> {
/// Create a new ISA builder with the given lookup function.
pub fn new(lookup: fn(Triple) -> Result<Builder<T>>) -> Self {
pub fn new(triple: Option<Triple>, lookup: fn(Triple) -> Result<Builder<T>>) -> Result<Self> {
let mut flags = settings::builder();

// We don't use probestack as a stack limit mechanism
flags
.set("enable_probestack", "false")
.expect("should be valid flag");

let mut isa_flags = lookup(Triple::host()).expect("host machine is not a supported target");
let triple = triple.unwrap_or_else(Triple::host);
let mut isa_flags = lookup(triple)?;
cranelift_native::infer_native_flags(&mut isa_flags).unwrap();

Self {
Ok(Self {
shared_flags: flags,
inner: isa_flags,
lookup,
}
})
}

pub fn triple(&self) -> &target_lexicon::Triple {
Expand Down
6 changes: 5 additions & 1 deletion crates/cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ anyhow = { workspace = true }
log = { workspace = true }
wasmtime-environ = { workspace = true }
cranelift-wasm = { workspace = true }
cranelift-codegen = { workspace = true, features = ["default"] }
cranelift-codegen = { workspace = true, default-features = false, features = [
"std",
"unwind",
] }
cranelift-frontend = { workspace = true }
cranelift-entity = { workspace = true }
cranelift-native = { workspace = true }
Expand All @@ -31,6 +34,7 @@ wasmtime-versioned-export-macros = { workspace = true }

[features]
all-arch = ["cranelift-codegen/all-arch"]
host-arch = ["cranelift-codegen/host-arch"]
component-model = ["wasmtime-environ/component-model"]
incremental-cache = ["cranelift-codegen/incremental-cache"]
wmemcheck = []
9 changes: 5 additions & 4 deletions crates/cranelift/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use cranelift_codegen::{
use std::fmt;
use std::path;
use std::sync::Arc;
use target_lexicon::Triple;
use wasmtime_cranelift_shared::isa_builder::IsaBuilder;
use wasmtime_environ::{CacheStore, CompilerBuilder, Setting, Tunables};

Expand All @@ -36,15 +37,15 @@ pub struct LinkOptions {
pub force_jump_veneers: bool,
}

pub fn builder() -> Box<dyn CompilerBuilder> {
Box::new(Builder {
pub fn builder(triple: Option<Triple>) -> Result<Box<dyn CompilerBuilder>> {
Ok(Box::new(Builder {
tunables: Tunables::default(),
inner: IsaBuilder::new(|triple| isa::lookup(triple).map_err(|e| e.into())),
inner: IsaBuilder::new(triple, |triple| isa::lookup(triple).map_err(|e| e.into()))?,
linkopts: LinkOptions::default(),
cache_store: None,
clif_dir: None,
wmemcheck: false,
})
}))
}

impl CompilerBuilder for Builder {
Expand Down
16 changes: 11 additions & 5 deletions crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "nightlydoc"]
features = ["component-model"]

[dependencies]
wasmtime-runtime = { workspace = true }
wasmtime-runtime = { workspace = true, optional = true }
wasmtime-environ = { workspace = true }
wasmtime-jit-debug = { workspace = true, features = [
"perf_jitdump",
Expand Down Expand Up @@ -96,6 +96,8 @@ default = [
'addr2line',
'coredump',
'debug-builtins',
'runtime',
'host-arch',
]

# An on-by-default feature enabling runtime compilation of WebAssembly modules
Expand Down Expand Up @@ -135,27 +137,29 @@ async = [
]

# Enables support for the pooling instance allocation strategy
pooling-allocator = ["wasmtime-runtime/pooling-allocator"]
pooling-allocator = ["runtime", "wasmtime-runtime/pooling-allocator"]

# Enables support for all architectures in Cranelift, allowing
# cross-compilation using the `wasmtime` crate's API, notably the
# `Engine::precompile_module` function.
all-arch = ["wasmtime-cranelift?/all-arch", "wasmtime-winch?/all-arch"]

host-arch = ["wasmtime-cranelift?/host-arch"]

# Enables in-progress support for the component model. Note that this feature is
# in-progress, buggy, and incomplete. This is primarily here for internal
# testing purposes.
component-model = [
"wasmtime-environ/component-model",
"wasmtime-cranelift?/component-model",
"wasmtime-winch?/component-model",
"wasmtime-runtime/component-model",
"wasmtime-runtime?/component-model",
"dep:wasmtime-component-macro",
"dep:wasmtime-component-util",
"dep:encoding_rs",
]

wmemcheck = ["wasmtime-runtime/wmemcheck", "wasmtime-cranelift?/wmemcheck"]
wmemcheck = ["wasmtime-runtime?/wmemcheck", "wasmtime-cranelift?/wmemcheck"]

# Enables support for demangling WebAssembly function names at runtime in
# errors such as backtraces.
Expand All @@ -166,4 +170,6 @@ coredump = ["dep:wasm-encoder"]

# Export some symbols from the final binary to assist in debugging
# Cranelift-generated code with native debuggers like GDB and LLDB.
debug-builtins = ["wasmtime-runtime/debug-builtins"]
debug-builtins = ["wasmtime-runtime?/debug-builtins"]

runtime = ["dep:wasmtime-runtime"]
Loading

0 comments on commit fccbf74

Please sign in to comment.