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

Support WASM #16

Open
CarlKCarlK opened this issue Jul 9, 2023 · 4 comments
Open

Support WASM #16

CarlKCarlK opened this issue Jul 9, 2023 · 4 comments

Comments

@CarlKCarlK
Copy link

The include-flate crate is great and would be super useful for WASM apps and libraries. It would be a way to include data files that WASM couldn't otherwise upload.

It's possible that you can make it compatible just by changing some ::std's to ::alloc's.

When I expand the flate! macro on my I get code like this (noticed the ::std's)

struct NAME_TO_PROB_STR {
    __private_field: (),
}
#[doc(hidden)]
static NAME_TO_PROB_STR: NAME_TO_PROB_STR = NAME_TO_PROB_STR {
    __private_field: (),
};
impl ::lazy_static::__Deref for NAME_TO_PROB_STR {
    type Target = ::std::string::String;
    fn deref(&self) -> &::std::string::String {
        #[inline(always)]
        fn __static_ref_initialize() -> ::std::string::String {
            ::include_flate::decode_string(
                b"\x05\xc0;\n\x00 \x08\x00\xd0Y\xc1\xa3\x14.\xd1l\xd0A\x14\x1a\x84~DK\xb7\xefM\x1d\r\xf6Y\xa6\xe6\xdd\xef#\x14)\x90\"s\r\x9c\t?",
            )
        }
        #[inline(always)]
        fn __stability() -> &'static ::std::string::String {
            static LAZY: ::lazy_static::lazy::Lazy<::std::string::String> = ::lazy_static::lazy::Lazy::INIT;
            LAZY.get(__static_ref_initialize)
        }
        __stability()
    }
}
impl ::lazy_static::LazyStatic for NAME_TO_PROB_STR {
    fn initialize(lazy: &Self) {
        let _ = &**lazy;
    }
}

This works if I manually change the ::std's to ::alloc's. You use lazy_static which says that it is 'no_std' compatible, so it should be able to work with WASM.

Thanks for considering adding this capability.

  • Carl
    p.s. I recently converted one of my non-macro crates to WASM and no_std compatibility and wrote a blog post about the process that you might find interesting. Thanks again for creating this crate. It did just want I needed.
@SOF3
Copy link
Owner

SOF3 commented Jul 10, 2023

I have no problem with no_std support. But doesn't the wasm32 target contain std? Or am I missing something?

@CarlKCarlK
Copy link
Author

CarlKCarlK commented Jul 10, 2023 via email

@SOF3
Copy link
Owner

SOF3 commented Jul 10, 2023

I mean the wasm32-unknown-unknown target already supports std (even though many are unimplemented), and it doesn't seem to require no_std to build a normal .wasm binary.

@CarlKCarlK
Copy link
Author

CarlKCarlK commented Jul 10, 2023 via email

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

No branches or pull requests

2 participants