Here is a minimal reproduction
Basically, the issue is I am unable to import from a package that is a canister but can import from a package that contains a normal
These lines import from another canister
These lines import from another package in the workspace
The first one doesn’t work, the second one does. Can I not import from one canister package into another? Seems like an arbitrary limitation.
Likely, the constraint comes from following config in
crate-type = ["cdylib"]
This is crucial for building target wasm. But it also make the crate not a rust lib anymore. Then it cannot be depended by other crates.
For data structures to be used by multiple canisters, it’s better to move them into a non-
And let each canister crate depend on that crate.
This is indeed what you achieved with the
Oh well, would have preferred to be able to do that, for the sake of colocating types, but as I read more, I understand this is a Rust limitation, not an IC limitation.
I updated the code here to make the compiler happy, but the
dfx build step still fails.
Basically, I tried 2 things:
- Removing the crate type
- Adding “lib” to the “cdylib” for the crate type array
Both of them make the compiler happy but the build fails.
What’s the reason for a canister type to specifically be “cdylib”?
So, better not to do it and just define things in a shared lib?