Support WASM
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.
I have no problem with no_std support. But doesn't the wasm32 target contain std? Or am I missing something?
Wasm32 supports many things in std (like alloc::collections and core:f32), but not everything. The biggest thing it is missing is file IO.
From: Jonathan Chan Kwan @.> Sent: Sunday, July 9, 2023 7:11 PM To: @.> Cc: Carl @.>; @.> Subject: Re: [SOF3/include-flate] Support WASM (Issue #16)
I have no problem with no_std support. But doesn't the wasm32 target contain std? Or am I missing something?
— Reply to this email directly, view it on GitHubhttps://github.com/SOF3/include-flate/issues/16#issuecomment-1627969357, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABR65P7ISB4Q3XBLT3N7T4LXPNQD3ANCNFSM6AAAAAA2DZTF7A. You are receiving this because you authored the thread.Message ID: @.***>
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.
I didn’t know that. Thanks! Include-flate seems to be working for me, now.
- Carl From: Jonathan Chan Kwan @.> Sent: Sunday, July 9, 2023 8:08 PM To: @.> Cc: Carl @.>; @.> Subject: Re: [SOF3/include-flate] Support WASM (Issue #16)
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 wasm32 binary.
— Reply to this email directly, view it on GitHubhttps://github.com/SOF3/include-flate/issues/16#issuecomment-1628012344, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABR65P75THW5YZVR2MCPVJLXPNWZXANCNFSM6AAAAAA2DZTF7A. You are receiving this because you authored the thread.Message ID: @.***>