Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ build-capi-jsc:
build-capi-headless:
ifeq ($(CARGO_TARGET_FLAG),)
CARGO_TARGET_DIR=target/headless RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features compiler-headless,wasi,webc_runner --locked
--no-default-features --features compiler-headless,wasi,webc_runner,wasmer-api/cranelift --locked
else
CARGO_TARGET_DIR=target/headless RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features compiler-headless,wasi,webc_runner --locked
--no-default-features --features compiler-headless,wasi,webc_runner,wasmer-api/cranelift --locked
endif

build-capi-headless-ios:
Expand Down
71 changes: 55 additions & 16 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,31 +412,70 @@
//! [`wamr`]: https://github.com/bytecodealliance/wasm-micro-runtime
//! [`wasmi`]: https://github.com/wasmi-labs/wasmi

macro_rules! cfg_compiler {
($($item:item)*) => {
$(
#[cfg(any(
feature = "cranelift",
feature = "singlepass",
feature = "llvm",
feature = "js",
feature = "jsc",
feature = "wamr",
feature = "v8",
feature = "wasmi"
))]
$item
)*
};
}

#[cfg(not(any(
feature = "sys",
feature = "js",
feature = "jsc",
feature = "singlepass",
feature = "cranelift",
feature = "llvm",
feature = "wamr",
feature = "wasmi",
feature = "v8",
feature = "wasmi"
feature = "js",
feature = "jsc"
)))]
compile_error!(
"One of: `sys`, `js`, `jsc` `wamr`, `wasmi` or `v8` features must be enabled. Please, pick one."
"wasmer requires enabling at least one backend feature: `singlepass`, `cranelift`, `llvm`, `wamr`, `wasmi`, `v8`, `js`, or `jsc`."
);

mod utils;
pub use utils::*;

mod entities;
pub use entities::memory::{MemoryView, location::MemoryLocation};
pub use entities::*;
#[cfg(all(
feature = "sys",
not(any(feature = "singlepass", feature = "cranelift", feature = "llvm"))
))]
compile_error!(
"the `sys` feature requires enabling at least one compiler backend: `singlepass`, `cranelift`, or `llvm`."
);

mod error;
pub use error::*;
cfg_compiler! {
mod utils;
pub use utils::*;
pub use entities::memory::{MemoryView, location::MemoryLocation};
mod error;
pub use error::*;
pub use entities::*;
Comment on lines +458 to +461
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The cfg_compiler! macro block (lines 455-465) includes re-exports from the entities module (lines 458, 461), but the actual mod entities; declaration is located after the macro block (line 478). While both are guarded by the same feature flags, this separation makes the code harder to follow because:

  1. The re-exports appear before the module declaration
  2. The dependency on entities is not immediately visible within the macro block
  3. A reader might not realize that entities must be declared elsewhere

Consider adding a comment within the cfg_compiler! block before the entities re-exports (e.g., at line 458) noting that mod entities; is declared separately below due to the ambiguity issue mentioned in the TODO. This would help readers understand the relationship without needing to search through the file.

Copilot uses AI. Check for mistakes.
mod backend;
pub use backend::*;
mod vm;
}

mod backend;
pub use backend::*;
mod vm;
// TODO: cannot be placed into cfg_compiler due to: error: `inner` is ambiguous
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The TODO comment states that mod entities; cannot be placed into cfg_compiler! due to an "inner is ambiguous" error, but doesn't provide details about what causes this ambiguity or how it might be resolved in the future.

Consider expanding this comment to explain:

  1. What specific ambiguity error occurs when placing entities in the macro
  2. What "inner" refers to (likely the inner.rs files in entity modules)
  3. Whether this is a temporary workaround or if there's a plan to restructure the module layout to avoid this issue

This will help future maintainers understand the constraint and potentially address it when refactoring.

Suggested change
// TODO: cannot be placed into cfg_compiler due to: error: `inner` is ambiguous
// NOTE: `mod entities;` cannot be placed inside `cfg_compiler!` due to a Rust compiler ambiguity error:
// When `entities` is included in the macro, the compiler reports "`inner` is ambiguous" because multiple
// submodules within `entities` (e.g., `entities/memory/inner.rs`, `entities/table/inner.rs`, etc.) have files named `inner.rs`.
// This causes the module resolution to fail, as Rust cannot disambiguate which `inner` is being referred to.
// As a workaround, `mod entities;` is declared outside the macro with explicit `#[cfg]` gating.
// If the module layout is restructured in the future (e.g., by renaming `inner.rs` files or flattening the hierarchy),
// this workaround may no longer be necessary and `mod entities;` could be moved into `cfg_compiler!`.

Copilot uses AI. Check for mistakes.
#[cfg(any(
feature = "cranelift",
feature = "singlepass",
feature = "llvm",
feature = "js",
feature = "jsc",
feature = "wamr",
feature = "v8",
feature = "wasmi"
))]
mod entities;

pub use wasmer_types::{
Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo,
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ filesystem = []
blake3-pure = ["blake3/pure"]

[package.metadata.docs.rs]
features = ["wasmer/sys", "wasmer/compiler"]
features = ["wasmer/sys", "wasmer/compiler", "wasmer/cranelift"]
rustc-args = ["--cfg", "docsrs"]
1 change: 1 addition & 0 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,4 @@ bin-dir = "bin/{ bin }.exe"

[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]
features = ["wasmer/cranelift"]
2 changes: 1 addition & 1 deletion lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl Artifact {
get_got_address(RelocationTarget::LibCall(wasmer_vm::LibCall::EHPersonality)),
)?;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "compiler", not(target_arch = "wasm32")))]
{
engine_inner.register_perfmap(&finished_functions, module_info)?;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/src/engine/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl EngineInner {
.register_frame_info(frame_info);
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(feature = "compiler", not(target_arch = "wasm32")))]
pub(crate) fn register_perfmap(
&self,
finished_functions: &PrimaryMap<LocalFunctionIndex, FunctionExtent>,
Expand Down
35 changes: 25 additions & 10 deletions lib/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

macro_rules! cfg_std_or_core {
($($item:item)*) => {
$(
#[cfg(any(
feature = "std",
feature = "core",
))]
$item
)*
};
}

#[cfg(all(feature = "std", feature = "core"))]
compile_error!(
"The `std` and `core` features are both enabled, which is an error. Please enable only once."
Expand All @@ -32,6 +44,7 @@ compile_error!("Both the `std` and `core` features are disabled. Please enable o
extern crate alloc;

#[allow(unused_imports)]
#[cfg(any(feature = "std", feature = "core"))]
mod lib {
#[cfg(feature = "core")]
pub mod std {
Expand All @@ -46,20 +59,22 @@ mod lib {
}
}

mod engine;
mod traits;
cfg_std_or_core! {
mod engine;
mod traits;

pub mod misc;
pub mod object;
pub mod serialize;
pub mod types;
pub mod misc;
pub mod object;
pub mod serialize;
pub mod types;

pub use crate::engine::*;
pub use crate::traits::*;
pub use crate::engine::*;
pub use crate::traits::*;

mod artifact_builders;
mod artifact_builders;

pub use self::artifact_builders::*;
pub use self::artifact_builders::*;
}

#[cfg(feature = "compiler")]
mod compiler;
Expand Down
1 change: 1 addition & 0 deletions lib/middlewares/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ maintenance = { status = "actively-developed" }

[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]
features = ["wasmer/cranelift"]
2 changes: 1 addition & 1 deletion lib/swift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ wasmer-package.workspace = true
uniffi = { version = "0.27", features = ["build"] }

[package.metadata.docs.rs]
features = ["wasmer/sys", "wasmer/compiler"]
features = ["wasmer/sys", "wasmer/cranelift"]
rustc-args = ["--cfg", "docsrs"]
1 change: 1 addition & 0 deletions lib/sys-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tracing-subscriber = { workspace = true, features = ["fmt"] }
tracing.workspace = true

[package.metadata.docs.rs]
features = ["wasmer/cranelift"]
rustc-args = ["--cfg", "docsrs"]

[features]
Expand Down
2 changes: 1 addition & 1 deletion lib/wai-bindgen-wasmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ singlepass = ["wasmer/singlepass"]
llvm = ["wasmer/llvm"]

[package.metadata.docs.rs]
features = ["wasmer/sys", "wasmer/compiler"]
features = ["wasmer/sys", "wasmer/cranelift"]
rustc-args = ["--cfg", "docsrs"]
2 changes: 1 addition & 1 deletion lib/wasi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ version = "1.3.0"
enable-serde = ["serde", "wasmer-types/serde"]

[package.metadata.docs.rs]
features = ["wasmer/sys", "wasmer/compiler"]
features = ["wasmer/sys", "wasmer/cranelift"]
rustc-args = ["--cfg", "docsrs"]
2 changes: 1 addition & 1 deletion lib/wasix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ enable-serde = [
[package.metadata.docs.rs]
features = [
"wasmer/sys",
"wasmer/compiler",
"wasmer/cranelift",
"webc_runner_rt_wcgi",
"webc_runner_rt_dcgi",
"webc_runner_rt_dproxy",
Expand Down
Loading