Skip to content

Add wasm32 compatibility#49

Open
juntyr wants to merge 29 commits intorobertu94:masterfrom
juntyr:wasm
Open

Add wasm32 compatibility#49
juntyr wants to merge 29 commits intorobertu94:masterfrom
juntyr:wasm

Conversation

@juntyr
Copy link
Copy Markdown

@juntyr juntyr commented Feb 12, 2026

This PR allows libpressio to be compiled for wasm32, which is used with the libpressio-rs bindings to compile numcodecs-pressio to numcodecs-wasm-pressio

@juntyr juntyr changed the title WASM hacks Add wasm32 compatibility Mar 10, 2026
@juntyr juntyr marked this pull request as ready for review March 10, 2026 07:51
@juntyr juntyr requested a review from robertu94 March 10, 2026 07:52
@juntyr
Copy link
Copy Markdown
Author

juntyr commented Mar 10, 2026

@robertu94 I'd like to push forward with these changes now that they've been cleaned up

Copy link
Copy Markdown
Owner

@robertu94 robertu94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these comments are small.

CMakeLists.txt Outdated
set_property(CACHE LIBPRESSIO_BUILD_MODE PROPERTY STRINGS "CORE" "FULL")
endif()

option(LIBPRESSIO_WITH_EXTERNAL "Support external plugins" ON)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this switch needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The external plugins cannot be supported on WASM. The external metrics could be supported in theory, but in practice, the wasi-libc doesn't support mkstemps yet (WebAssembly/wasi-libc#229). The forkexec is definitely not supported in WASM (maybe one day WASI will support command spawning, there are forks that do this, but no standard support yet).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External is not intended to be tried explicitly to fork+exec. There are currently 4 implementations python, mpi, forkexec, and http. Maybe there are functions/refactoring we need to do to support this, and which case we can split this into a seperate issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, none of them can be implemented in WASM, but one may be able to come up with one that could (an in-process external ...) in the future.

How should we resolve this for now? Should forkexec get its own feature switch, like the others, but on-by-default? What should we do about the external metric? We could add a WASM-specific polyfill for mkstemps, but having an external metric without any external launch wouldn't work anyways ...

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was: https://docs.rs/wasmtime-wasi-http/latest/wasmtime_wasi_http/ which would allow the HTTP option. If you don't want to support this for now I understand, and we can add a switch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasi does offer HTTP, yes, but I haven't yet added support for it in the numcodecs-wasm engine. This is mainly because the engine is set up to create a fully sandboxed environment - there is no input beyond the data bytes (the environment is controlled, randomness is seeded, stdin is empty) and the only outputs are stdout/stderr, which also provides no feedback. This is all done to ensure that execution is fully reproducible. Exposing external metrics, compressors, etc., would change the guarantee to "only deterministic if the external one is deterministic", which is something I would likely switch to at some point. But at least for now, supporting external is out of scope

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've at least added support for wasi:http in my sandbox in juntyr/wasi-sandboxed-component#3 - this would allow code depending on wasi:http to compile, but every outgoing request is refused (yay sandbox), and there are no incoming requests (yay sandbox)

@juntyr
Copy link
Copy Markdown
Author

juntyr commented Mar 21, 2026

@robertu94 Thank you for the review! I've tried to address all of your comments, but left two unresolved since I need more input from you.

@juntyr
Copy link
Copy Markdown
Author

juntyr commented Mar 30, 2026

@robertu94 Does this PR need anything else, or can it be merged? Ideally, I'd like to publish the libpressio-rs and numcodecs-pressio crates once this PR is upstream (and ideally ideally there has been a release with these changes so we can point at a release version)

@robertu94
Copy link
Copy Markdown
Owner

I think it looks good. I want to pull in these changes locally and do some testing to double-check that nothing broke, and I hope to do that soon. It's on my todo list I promise.

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

Successfully merging this pull request may close these issues.

2 participants