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

Add export! macros #77

Merged
merged 7 commits into from
Feb 28, 2024
Merged

Add export! macros #77

merged 7 commits into from
Feb 28, 2024

Conversation

lann
Copy link
Contributor

@lann lann commented Feb 26, 2024

Also update bindings.rs with wit-bindgen 0.19.2.

Closes #76

use wasi::http::types::{IncomingRequest, ResponseOutparam};

wasi::http::incoming_handler::export!(Handler);

struct Handler;

impl exports::wasi::http::incoming_handler::Guest for Handler {
    fn handle(request: IncomingRequest, response_out: ResponseOutparam) {
        ...
    }
}

@lann lann changed the title wip: Add http::incoming_handler::export macro Add export! macros Feb 27, 2024
@lann lann marked this pull request as ready for review February 27, 2024 14:43
This adds two macros that wrap wit_bindgen::generate! with appropriate
path, world, exports, and with options:

- `wasi::cli::run::export!` for `wasi:cli/run`
- `wasi::http::incoming_handler::export!` for
  `wasi:http/incoming-handler`
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great to me, thanks for both the suggestion and the implementation!

@alexcrichton
Copy link
Member

Oh I realize now though that this isn't tested on CI. Can you add a CI check to ensure that the crate builds with this feature enabled?

For other nice-to-haves, feel free to defer these to either a future PR or a future contributor:

  • These would probably make good entries in documentation at the crate level along with instructions of how to build.
  • The wasi:cli/run macro may want some caution about it to indicate that it doesn't work with fn main() {} and fn main() {} otherwise works with the "command" adapter
  • It'd be good to have a CLI check to ensure that these build the expected world, perhaps using wasm-tools component targets

Again though these points aren't critical, only the CI bit I think is critical to have before landing.

@lann
Copy link
Contributor Author

lann commented Feb 28, 2024

Can you add a CI check to ensure that the crate builds with this feature enabled?
It'd be good to have a CLI check to ensure that these build the expected world, perhaps using wasm-tools component targets

Added wasmtime run for the cli/command example and wasm-tools component targets for the http/proxy example.

These would probably make good entries in documentation at the crate level along with instructions of how to build.

Added "Export Macros" section to root docs.

The wasi:cli/run macro may want some caution about it to indicate that it doesn't work with fn main() {} and fn main() {} otherwise works with the "command" adapter

Added "Compatibility with wasm32-wasi targets" section to macro docs.

@alexcrichton
Copy link
Member

Thanks again for all this!

@alexcrichton alexcrichton merged commit d00dbc4 into bytecodealliance:main Feb 28, 2024
5 checks passed
@lann lann deleted the macros branch February 28, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add macros for generating wasi world export bindings
2 participants