bsuccinct-rs icon indicating copy to clipboard operation
bsuccinct-rs copied to clipboard

support target wasm32-wasip1

Open nkysg opened this issue 1 year ago • 1 comments

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 ?

nkysg avatar Jul 31 '24 15:07 nkysg

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 avatar Aug 03 '24 09:08 beling

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

beling avatar Aug 21 '24 09:08 beling

Thanks for your help!

nkysg avatar Aug 22 '24 11:08 nkysg

Now everything in 32bits branch seems to compile and pass the test on 32 bit platform (I've tested with i686-unknown-linux-gnu target). Can you check for your target platform(s)?

beling avatar Oct 01 '24 17:10 beling

Yeah, Thank you for your help. I have tried with 32 bit platform.

nkysg avatar Oct 01 '24 18:10 nkysg

Thanks. I will merge 32bits into main in the next few days and release new versions of crates to cargo.

beling avatar Oct 01 '24 19:10 beling