wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Fix rust generator guest import error in `no_std` build

Open mambisi opened this issue 3 years ago • 4 comments

error snapshot

    |
100 |     pub fn generate_native_address(seed: &[u8]) -> Vec<u8> {
    |                                                    ^^^ not found in this scope
    |
help: consider importing one of these items
    |
3   |     use alloc::vec::Vec;
    |
3   |     use crate::Vec;
    |
3   |     use rune_std::vec::Vec;
    |
3   |     use wit_bindgen_guest_rust::rt::vec::Vec;
    |

adds

#[allow(unused_imports)]
use wit_bindgen_guest_rust::rt::{{alloc, vec::Vec, string::String}};

in the beginning of the mod generation, remove it from ending

mambisi avatar Jan 29 '23 22:01 mambisi

Thanks! I think this breaks some existing tests, however, so that'll need fixing as well.

Can you additionally add tests for this to the tests/codegen.rs file?

alexcrichton avatar Jan 30 '23 14:01 alexcrichton

Yeah Sure

mambisi avatar Jan 30 '23 15:01 mambisi

Sorry but for fixing the tests I don't mean adding imports to the test. The generated code shouldn't require the code around the macro to import anything as the generated code should be entirely standalone.

alexcrichton avatar Jan 30 '23 19:01 alexcrichton

Got it

mambisi avatar Jan 30 '23 20:01 mambisi

Thanks for the PR! This ended up getting fixed in #488. For no_std use cases, wit-bindgen now has a --std-feature flag in which it emits code that uses #[feature = "std"] guarding things that need std.

sunfishcode avatar Mar 20 '24 23:03 sunfishcode