Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generating public modules for Rust on import #289

Open
philpax opened this issue Jul 25, 2022 · 2 comments
Open

Allow generating public modules for Rust on import #289

philpax opened this issue Jul 25, 2022 · 2 comments
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly

Comments

@philpax
Copy link
Contributor

philpax commented Jul 25, 2022

Right now, if you generate Rust-import, you get this:

#[allow(clippy::all)]
mod input {

If you generate wasmtime-import, you get this:

#[allow(clippy::all)]
pub mod input {

Ideally, there'd be an option to make the former generate like the latter (e.g. with pub mod instead of mod), or they would both be pub mod by default.

With the modules being private, I can't expose them to user code using their original names. I'd use wit_bindgen_wasmtime::import to sidestep this, but I encounter build issues:

error[E0425]: cannot find function `lock` in module `os`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/region-2.2.0/src/lock.rs:30:7
   |
30 |   os::lock(
   |       ^^^^ not found in `os`
   |
help: consider importing this function
   |
1  | use lock;
   |
help: if you import `lock`, refer to it directly
   |
30 -   os::lock(
30 +   lock(
   |

error[E0425]: cannot find function `unlock` in module `os`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/region-2.2.0/src/lock.rs:60:7
   |
60 |   os::unlock(
   |       ^^^^^^ not found in `os`
   |
help: consider importing this function
   |
1  | use unlock;
   |
help: if you import `unlock`, refer to it directly
   |
60 -   os::unlock(
60 +   unlock(
   |

error[E0425]: cannot find function `page_size` in module `os`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/region-2.2.0/src/page.rs:16:39
   |
16 |     INIT.call_once(|| PAGE_SIZE = os::page_size());
   |                                       ^^^^^^^^^ not found in `os`

error[E0425]: cannot find function `set_protection` in module `os`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/region-2.2.0/src/protect.rs:48:7
   |
48 |   os::set_protection(
   |       ^^^^^^^^^^^^^^ not found in `os`

error[E0425]: cannot find function `get_region` in module `os`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/region-2.2.0/src/lib.rs:133:7
    |
133 |   os::get_region(page::floor(address as usize) as *const u8)
    |       ^^^^^^^^^^ not found in `os`

(I also don't know which one I'm supposed to use for a Wasmtime export and a Rust guest, anyway)

@Liamolucko
Copy link
Contributor

Perhaps import could be changed to an attribute macro on mod, so that you can explicitly add the pub modifier, e.g.:

#[wit_bindgen_rust::import("foo.wit")]
pub mod foo;

@Michael-F-Bryan
Copy link
Contributor

It's not a solution, but one trick I've been using is to re-export your generated module's contents under a module with the same name.

pub mod foo {
  wit_bindgen_wasmtime::import!("foo");

  pub use self::foo::*; 
}

@alexcrichton alexcrichton added gen-rust Related to bindings for Rust-compiled-to-WebAssembly gen-wasmtime labels Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly
Projects
None yet
Development

No branches or pull requests

4 participants