beling / bsuccinct-rs

Rust libraries and programs focused on succinct data structures
Apache License 2.0
112 stars 8 forks source link

support target wasm32-wasip1 #5

Open nkysg opened 1 month ago

nkysg commented 1 month ago

when I run the cmd

cargo +stable build  --target wasm32-wasip1 --no-default-features

It outputs this information

| pub const BITS_PER_L1_ENTRY: usize = 1<<32;
   |                                      ^^^^^ attempt to shift left by `32_i32`, which would overflow

   Compiling form_urlencoded v1.2.1
   Compiling sha3 v0.10.8
   Compiling eyre v0.6.12
note: erroneous constant encountered
   --> /home/ysg/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bitm-0.4.2/src/rank_select/select.rs:156:31
    |
156 |         *rank -= i as usize * BITS_PER_L1_ENTRY - unsafe{l1ranks.get_unchecked(i)};
    |                               ^^^^^^^^^^^^^^^^^

note: erroneous constant encountered
   --> /home/ysg/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bitm-0.4.2/src/rank_select/selec

Do we have plan to support wasm32-wasip1 ?

beling commented 1 month ago

The problem is technically easy to solve, but requires deep thinking about how the API should look like. In wasm32 usize has 4 bytes. My structures (bitmaps) support 2 to the power of 64 indexes. So I would have to use u64 instead of usize to index them. Moreover, I use arrays and vectors underneath, so when their indexes are 32 bits, I can't implement full 64 bit indexes in bitmaps.

As a workaround, you can try compiling with the wasm64-unknown-unknown target. It uses the (for now experimental) memory64 wasm extension.

beling commented 3 weeks ago

I work on 32 bit support in 32bits branch. The code should compile and work, but I have no way to test it at the moment. The API is preserved, i.e. usize is used for indexing and counting bits. This means that (for a 32 bit usize) their number cannot exceed 2 to the power of 32.

https://github.com/beling/bsuccinct-rs/tree/32bits

nkysg commented 3 weeks ago

Thanks for your help!