Greetings, I would like to bind with the imports inside a module and then use these inside other modules.
I have the following WIT definition:
world sensor {
import wasi:i2c/i2c@0.2.0-draft;
export hts;
}
world screen {
import wasi:i2c/i2c@0.2.0-draft;
import wasi:i2c/delay@0.2.0-draft;
export lcd;
}
(hts
and lcd
are interfaces that export some functions)
I have a device.rs
with inside the following bindgen invocation:
bindgen!({
path: "../wit/deps/i2c",
world: "wasi:i2c/imports",
with: {
"wasi:i2c/delay/delay": Delay,
"wasi:i2c/i2c/i2c": I2c,
}
});
And then I have a sensor.rs
with the following invocation:
bindgen!({
path: "../wit",
world: "sensor",
with: {
"wasi:i2c/i2c/i2c": I2c,
}
});
But I get the following error:
error[E0364]: `I2c` is private, and cannot be re-exported
--> src/sensor.rs:14:1
|
14 | / bindgen!({
15 | | path: "../wit",
16 | | world: "sensor",
17 | | with: {
18 | | "wasi:i2c/i2c/i2c": I2c,
19 | | }
20 | | });
| |__^
|
note: consider marking `I2c` as `pub` in the imported module
--> src/sensor.rs:14:1
|
14 | / bindgen!({
15 | | path: "../wit",
16 | | world: "sensor",
17 | | with: {
18 | | "wasi:i2c/i2c/i2c": I2c,
19 | | }
20 | | });
| |__^
= note: this error originates in the macro `bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
I'm not sure why I get this error, nor how to resolve it. The I2c definition: pub struct I2c(pub I2cdev);
and if I inline the macro the error becomes:
error[E0364]: `I2c` is private, and cannot be re-exported
--> src/sensor.rs:221:21
|
221 | pub use super::super::super::I2c;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: consider marking `I2c` as `pub` in the imported module
--> src/sensor.rs:221:21
|
221 | pub use super::super::super::I2c;
|
Does anyone have any clues on what I could to debug further, or how to resolve this?
how is I2c declared? and where? it should be pub struct I2c
-(edit) I see the declaration now - still would try enhancing the with
you may also want to be more specific given that you're generating an interface named I2c - so change your with: ...
to fully_qualified::path::to::I2c
- the error messages will be better at any rate if you do that
also cargo expand
is super helpful in these cases in my experience
My guess is that the world sensor should export i2c, given that you use with
here to associate with your implementation.
Oh, I guess that you should either use import exclusive or with for a given interface.
Also I first guessed that this would be the host side, if you target the guest please use a more recent wit-bindgen (I don't see the export! macro and with no longer applies with newer versions)
you may also want to be more specific given that you're generating an interface named I2c - so change your
with: ...
tofully_qualified::path::to::I2c
- the error messages will be better at any rate if you do that
This fixed it! I honestly did not expect that such a simple change could fix it :happy:
Friedrich Vandenberghe has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC