I'm not sure whether this is an issue with wit-bindgen
, cargo-component
, wit-parser
, or some combination, so I figured I'd ask here for guidance.
Given a world that defines a type outside of an interface, for example:
package gumbo:logging@0.1.0;
/// The `logging` world provides a standardized entry point for logging capabilities.
/// It serves as a dedicated interface for interacting with the logging functionality
/// defined within the `logging` interface, allowing for structured logging, context management,
/// and tracing within a plugin or application.
@since(version = 0.1.0)
world logging {
/// Defines the severity level of a log message.
@since(version = 0.1.0)
enum log-level {
/// Detailed information typically used for diagnosing issues.
trace,
/// Information useful for developers to debug the application.
debug,
/// General operational information about the application's state.
info,
/// Indicates a potential problem that should be investigated.
warn,
/// Indicates a significant issue that could impact the application's functionality.
error,
}
/// Gets the current `log-level` of the application.
///
/// # Returns
/// - The current log level, or `None` if logging is disabled.
@since(version = 0.1.0)
import get-log-level: func() -> option<log-level>;
/// Logs an event with the specified severity level, target, and message.
///
/// # Parameters
/// - `level`: The severity level of the log event.
/// - `target`: The target or category of the log event.
/// - `message`: The log message.
///
/// # Returns
/// - `Ok(())`: If the event was logged successfully.
/// - `Err(log-error)`: If the logging operation failed.
@since(version = 0.1.0)
import log-event: func(level: log-level, target: string, message: string);
}
When using wit_bindgen::generate!
with the pub_export_macro
option, I get an error when using cargo component build
Caused by:
0: failed to merge worlds from two documents
1: duplicate import found for interface `log-level`
I'm trying to track down the bug, but it's a bit complicated because cargo-component
uses an older version of wit-parser
than wit-bindgen
.
It's also weird because log-level
is a type, not an interface...
If I wrap the functionality into an interface, there's no problem
@since(version = 0.1.0)
world logging {
import logging: interface {
/// Defines the severity level of a log message.
@since(version = 0.1.0)
enum log-level {
/// Detailed information typically used for diagnosing issues.
trace,
/// Information useful for developers to debug the application.
debug,
/// General operational information about the application's state.
info,
/// Indicates a potential problem that should be investigated.
warn,
/// Indicates a significant issue that could impact the application's functionality.
error,
}
/// Gets the current `log-level` of the application.
///
/// # Returns
/// - The current log level, or `None` if logging is disabled.
@since(version = 0.1.0)
get-log-level: func() -> option<log-level>;
/// Logs an event with the specified severity level, target, and message.
///
/// # Parameters
/// - `level`: The severity level of the log event.
/// - `target`: The target or category of the log event.
/// - `message`: The log message.
///
/// # Returns
/// - `Ok(())`: If the event was logged successfully.
/// - `Err(log-error)`: If the logging operation failed.
@since(version = 0.1.0)
log-event: func(level: log-level, target: string, message: string);
}
}
That’s a wit-bindgen bug, types and functions in a world rather than an interface have historically been a source of bugs but it all should work
Can you file it on that repo?
Yes, I'll put together a minimal example and file a bug. Just didn't know which project to file it under. Thanks!
Wait hmm. I actually take it back that may be a wit-component bug that is due to being on an old version in cargo component… but I’m not sure. I’m done with my laptop for the day and answering from mobile so I can’t reproduce to check quick. But file it on wit-bindgen and we will look
Yeah, it looks like the resolver stuff was refactored in wit-parser
. I attempted to update wit-component with the newer version, but it requires changes that I'm not comfortable with.
Porting to the updated dependencies might fix things.
Last updated: Nov 22 2024 at 16:03 UTC