-
Notifications
You must be signed in to change notification settings - Fork 922
fix(build): Meaningful compilation errors when no backend feature enabled #5767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6ad1a3d
d50c7f9
2b4fe02
da96336
308b47b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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::*; | ||||||||||||||||||
| 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 | ||||||||||||||||||
|
||||||||||||||||||
| // 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!`. |
There was a problem hiding this comment.
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 theentitiesmodule (lines 458, 461), but the actualmod 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:entitiesis not immediately visible within the macro blockentitiesmust be declared elsewhereConsider adding a comment within the
cfg_compiler!block before theentitiesre-exports (e.g., at line 458) noting thatmod 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.