fuzing opened issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.I have the following file structure
wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import compression; }On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use fusing:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing added the bug label to Issue #11627.
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import compression; }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use fusing:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import compression; }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use fusing:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use fusing:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import types; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use fusing:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import types; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use abc:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/types.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import types; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use abc:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
fuzing edited issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/types.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import types; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, I'm usingbindgen!inside eachHostimplementation source file. For thecompressionhost implementor, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use abc:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
alexcrichton commented on issue #11627:
Can you try changing:
bindgen!({ path: "wit/deps/compression", world: "imports", });to
bindgen!({ world: "abc:compression/imports", });and does that fix your issue?
fuzing commented on issue #11627:
It does indeed - thank you so much, and enjoy your weekend!
fuzing closed issue #11627:
I'm trying to share
typesacross packages in WIT definitions. The functionality defined in the WIT files is provided by an embedded wasmtime host (Rust). There is also a wasm guest that consumes the functionality.I have 2 projects that consume the WIT definitions, namely:
- a rust project that provides the embedded wasmtime runtime (I'll refer to this as
host)- a project that generates wasm bytecode that will run inside the wasmtime host (I'll refer to this as
guest)I have the following file structure for my WIT files (WIT files are defined within the
hostproject)wit/package.wit wit/deps/types/world.wit wit/deps/types/types.wit wit/deps/compression/compression.wit wit/deps/compression/types.wit wit/deps/compression/world.witMy shared types WIT files look like these:
wit/deps/types/world.witpackage abc:types@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import types; }
wit/deps/types/types.witpackage abc:types@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) type bytes = list<u8>; }Note that it's the
bytestype that I need to share with (in this case) the compression packageThe package attempting to access the above shared types look like these:
wit/deps/compression/compression.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface compression { @since(version = 0.1.0) use abc:types/types@0.1.0.{bytes}; @since(version = 0.1.0) use types.{compression-level, compression-type}; @since(version = 0.1.0) compress: func(compression-type: compression-type, compression-level: compression-level, data: bytes) -> bytes; @since(version = 0.1.0) decompress: func(compression-type: compression-type, data: bytes) -> bytes; }
wit/deps/compression/world.witpackage abc:compression@0.1.0; @since(version = 0.1.0) world imports { @since(version = 0.1.0) import abc:types/types@0.1.0; @since(version = 0.1.0) import types; @since(version = 0.1.0) import compression; }
wit/deps/compression/types.witpackage abc:compression@0.1.0; @since(version = 0.1.0) interface types { @since(version = 0.1.0) enum compression-level { ultra-low, low, medium, high, ultra-high, } @since(version = 0.1.0) enum compression-type { zstd, deflate, } }On the
guestside, the component builds fine using the following steps:
- cargo component bindings
- cargo component build --release --target wasm32-unknown-unknown
Step
1above seems to parse the WIT files as I'd anticipate, and the resultingbindings.rscontains the definition forBytes(2 definitions, namely scoped to:abc::types::types::Bytesandabc::compression::compression::Bytes) that can be used by the local rust code.On the wasmtime embedded
hostside, thebindgen!macro seems unable to find/resolve the shared types across packages (in this case, betweenpackage abc:compression@0.1.0andpackage abc:types@0.1.0, whereabc:types@0.1.0contains a typebytesthat should be shared across other packages, including to theabc:compression@0.1.0package.On the
host, I'm usingbindgen!inside eachHostimplementation source file. For thecompressionhost implementor, thebindgen!looks like:bindgen!({ path: "wit/deps/compression", world: "imports", });The error coming from the compilation of the
hostis as follows:Compiling wasmtime-test v1.0.0 (/home/abc/Projects/abc-project/bin/wasmtime-test) error: failed to resolve directory while parsing WIT for path [/home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression] Caused by: package 'abc:types@0.1.0' not found. known packages: abc:compression@0.1.0 --> /home/abc/Projects/abc-project/bin/wasmtime-test/wit/deps/compression/compression.wit:6:9 | 6 | use abc:types/types@0.1.0.{bytes}; | ^----------- --> bin/wasmtime-test/src/platform_implementations/compression/compression.rs:15:1 | 15 | / bindgen!({ 16 | | path: "wit/deps/compression", 17 | | world: "imports", ... | 26 | | }); | |__^Notes:
On the
guestwasm bytecode project side, the following had to be included in theCargo.tomlfile:[package.metadata.component.target.dependencies] "abc:compression" = { path = "../../bin/wasmtime-test/wit/deps/compression" } "abc:types" = { path = "../../bin/wasmtime-test/wit/deps/types" }I've tried adding these to the Cargo.toml inside the
hostwasmtime embedding project but to no avail (I'm guessing that the bindgen! macro doesn't use these).Also for the
guest, a singleworld.witWIT file, defined as:package component:wasm-component; interface run { run: func(); } world client { import abc:compression/compression@0.1.0; import abc:types/types@0.1.0; export run; }Is there something I'm missing for the
bindgen!macro options (or for the Cargo.toml on thehostside)?
Last updated: Dec 06 2025 at 07:03 UTC