feat: Support compilation as wasm32-unknown-unknown - #312
Draft
dhdaines wants to merge 6 commits into
Draft
Conversation
dhdaines
marked this pull request as draft
July 23, 2026 22:22
Contributor
Author
|
Changed to draft! No longer necessary to vendor ffi-convert-rs as it has been updated, so I will update this as soon as possible: sonos/ffi-convert-rs#68 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently in order to get rustfst to run in the browser it's necessary to build it as WASI and then stub out the imported WASI symbols (using https://github.com/typst-community/wasm-minimal-protocol/tree/main/crates/wasi-stub for instance)
This is suboptimal since it adds an extra build step and retains useless code in the binaries. But unfortunately it's not actually possible to build
rustfst-ffifor the bare metal WebAssembly targetwasm32-unknown-unknownfor a couple of reasons:randgenrequiresgetrandomwhich doesn't work on wasm32-unknown (there is a way around this but it's discouraged for libraries: https://docs.rs/getrandom/latest/getrandom/#webassembly-support)ffi-convertdoesn't compile forwasm32-unknown-unknownbecause of a (useless) dependency onlibc(see fix: remove dep on libc to make wasm unknown work sonos/ffi-convert-rs#68), andlibcis also (uselessly) used in a lot of places inrustfst-ffi(I realize using
libcis probably leftover from whenstd::ffiandcore::ffiweren't very good, as the now very dated "Rust FFI Omnibus" suggests to do)This PR adds a
stddefault feature which compiles these things that require stdio. So to build forwasm32-unknown-unknownyou can omit the default features, the same pattern as we see elsewhere:(--features rustfst-state-label-u32 is unnecessary since wasm32 is 32)
(doesn't work for the top-level build because Reasons)
Because there isn't yet a version of
ffi-convertthat compiles, and when it will be released it will require Rust 2024, and I'm not sure if you want to require that here, I've simply vendored a fixed version of it since the license is totally compatible.Note: changing
libc::size_ttousizehas revealed that ... why exactly are you usingusizefor all those things inrustfst-ffi? Possibly for some of them it should be the same type as state IDs which I think is eitherusizeoru32(of course these are the same thing on WebAssembly!)