foobar
foobar•10mo ago

wasmbuild & rust module path

I try to call some rust modules in a wasm project https://deno.com/blog/wasmbuild My tree project is
rs_lib
- src
-- core
---sub core
rs_lib
- src
-- core
---sub core
It looks like the compiler doesn't find the right path for module when compiling (rs_lib, lib / deno task wasmbuild). How works relative/absolute path when compiling ?
Deno Blog
wasmbuild - Using Rust in Deno and Web Apps
An easier way to build Rust for Deno and the Web.
No description
2 Replies
Deno AI Helper
Deno AI Helper•10mo ago
The documentation doesn't provide explicit information on how relative or absolute paths work when compiling with wasmbuild and Rust. However, in general, Rust uses a module system to manage files and namespaces, and the path to a module is typically relative to the file in which it's being called. In your case, if you're trying to use a module from the sub_core directory in another file, you would typically use a relative path like mod core::sub_core; or use core::sub_core; in the file where you want to use the sub_core module. If you're having trouble with the module paths, make sure that you have the correct mod.rs files in each directory that declare the modules in that directory. For example, in the core directory, you should have a mod.rs file that contains something like pub mod sub_core;. If you're still having issues, it might be helpful to check the Rust documentation on the module system or ask for help in a Rust community forum.
Mrcool 🇵🇸
Wasmbuild by default expect the project to contain a folder named rs_lib, so you need to run it from the outside of that folder You can also just use deno task wasmbuild new, to see what's the default layout looks like