-
Notifications
You must be signed in to change notification settings - Fork 219
no_std support in the Rust guest bindings. #345
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
Conversation
I think this is reasonable to land for implementing the standard library itself but I'm wary about the " In terms of organization could most of the references to the |
This adds no_std support in the Rust guest bindings. Mostly this involves using `core` and `alloc` instead of `std`, but it also involves adding `extern crate alloc;` in a few places, and also adding a `"std"` cargo feature to gen-guest-rust so that the `impl std::error::Error` can be made conditional. This will eventually be useful for generating bindings from the WASI wit files for std itself to use. And, it's useful for experimenting with generating minimal bindings.
Right; the use cases I'm looking at are: ways to build highly specialized polyfills that don't work like regular modules, and eventually, building std.
I've now factored out all the |
crates/gen-rust-lib/Cargo.toml
Outdated
[features] | ||
default = ["std"] | ||
std = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading over this again, I think a compile-time option may not be the best way to shoehorn this feature for the code generators. Could the print_typedef_enum
method grow a gen_error: bool
method perhaps which is threaded through? For the Wasmtime-host generator this would always pass true
but for the Rust-guest generator I think it would be best to have this as a configurable Opts
option which, in the proc-macro, would be configured based on a feature flag of the proc-macro itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would help cut down on the default-features = false
traffic as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; and yeah, it's a lot simpler that way.
crates/guest-rust/src/lib.rs
Outdated
// Re-export things from liballoc for convenient use. | ||
pub use liballoc::{alloc, string, vec}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these move into mod rt
since that's the "internal stuff exported for the macro" module? (and would also avoid the need to rename alloc
to liballoc
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Cargo.toml
Outdated
wit-bindgen-gen-rust-lib = { path = 'crates/gen-rust-lib', version = '0.2.0' } | ||
wit-bindgen-guest-rust = { path = 'crates/guest-rust', version = '0.2.0' } | ||
wit-bindgen-gen-rust-lib = { path = 'crates/gen-rust-lib', version = '0.2.0', default-features = false } | ||
wit-bindgen-guest-rust = { path = 'crates/guest-rust', version = '0.2.0', default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my suggestion below it will remove the need to say default-features = false
on the gen-guest-rust
and gen-rust-lib
crates, and with those changes is this still necessary?
I'll admit that I do wish that workspace = true, default-features = false
would indeed turn off default features but alas. If that's the point of conflict you're running into I think it might be reasonable to, for that particular dependency line, avoid workspace = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that change got rid of all the default-features changes in this PR.
This adds no_std support in the Rust guest bindings. Mostly this involves using
core
andalloc
instead ofstd
, but it also involves addingextern crate alloc;
in a few places, and also adding a"std"
cargo feature to gen-guest-rust so that theimpl std::error::Error
can be made conditional.This will eventually be useful for generating bindings from the WASI wit files for std itself to use. And, it's useful for experimenting with generating minimal bindings.