Skip to content

Conversation

@theduke
Copy link
Contributor

@theduke theduke commented Sep 29, 2025

Currently, when no backend is enabled, we get a horrible mess of errors.

This commit:

  • Makes sure the wasmer-compiler crate can be compiled withou the
    compiler feature enabled
  • Makes sure the compiler crate fails to compile with a single
    meaningful message if neither core nor std features are enabled
  • Makes sure the api crate fails to compile with a single meaninful
    error when no backend is enabled

Note: our current module structure doesn't make it trivial to do this
cleanly.

I went for an approach that has more duplication, but is minimally
invasive.

Currently, when no backend is enabled, we get a horrible mess of errors.

This commit:
* Makes sure the wasmer-compiler crate can be compiled withou the
  compiler feature enabled
* Makes sure the compiler crate fails to compile with a single
  meaningful message if neither core nor std features are enabled
* Makes sure the api crate fails to compile with a single meaninful
  error when no backend is enabled

Note: our current module structure doesn't make it trivial to do this
cleanly.

I went for an approach that has more duplication, but is minimally
invasive.
@Arshia001
Copy link
Member

LGTM, but can we turn the overly verbose cfgs into a macro please?

@theduke theduke changed the title fix(build): Meaningful backend compilation errors in api fix(build): Meaningful compilation errors when no backend feature enabled Sep 29, 2025
Copilot AI review requested due to automatic review settings November 25, 2025 16:09
@marxin
Copy link
Contributor

marxin commented Nov 25, 2025

LGTM, but can we turn the overly verbose cfgs into a macro please?

Done that.

@theduke please check my change hasn't changed the expected build behavior?

Copilot finished reviewing on behalf of marxin November 25, 2025 16:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves compilation error messages when required backend features are not enabled. Currently, missing features result in cascading compilation errors that are difficult to debug. The changes introduce meaningful compile_error! messages and feature-gate code appropriately.

  • Adds compile_error! macros to catch missing backend/compiler feature combinations early
  • Introduces cfg_std_or_core! and cfg_compiler! macros to reduce duplication in conditional compilation
  • Adds feature = "compiler" guards to perfmap-related functions that depend on compiler infrastructure

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/compiler/src/lib.rs Introduces cfg_std_or_core! macro and wraps module declarations to ensure they're only compiled when std or core features are enabled
lib/compiler/src/engine/inner.rs Adds feature = "compiler" guard to register_perfmap function which accesses compiler-specific fields
lib/compiler/src/engine/artifact.rs Adds feature = "compiler" guard to register_perfmap call site for consistency
lib/api/src/lib.rs Adds compile_error! checks for missing backend features, introduces cfg_compiler! macro to conditionally compile modules based on enabled backends

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +458 to +461
pub use entities::memory::{MemoryView, location::MemoryLocation};
mod error;
pub use error::*;
pub use entities::*;
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;
// 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants