For me there's a lot going on in this thread but I think there's a lot of good points to call out too. The tl;dr; is that I don't think we're in a great position right now (sort of self-evident given the discussion) but there's no easy way out of this. There are a number of competing concerns and desires here, but I can try to offer my 2c on thoughts on ways forward on this.
Guidelines for enabling wasm extensions
As far as I know there's no currently written down policy of "here's when it's decided to turn a wasm feature on". The WebAssembly specification has been evolving for years and will continue to do so. Whether or not it makes sense to turn a feature on-by-default will continuously come up. Personally I don't think either extreme of "never turn anything on" or "turn everything on after 6 months" is feasible.
Right now Rust's default set of extensions enabled is inherited from LLVM. For discussion of the various policies there the internals forum here isn't the best place since the wasm backend LLVM maintainers (mostly Googlers working with Emscripten) likely don't frequent here. Instead I'd recommend raising a discussion in the tool-conventions repository.
I'll specifically call out here though that I at least personally think it's important to keep C/C++/Rust/etc in sync. While it's certainly possible to have different defaults in Rust than in LLVM I believe that will cause confusion in the long run. I understand it's more work to engage with external folks, but I think it'll result in a better result in the long run.
I was not personally part of the discussion to turn these proposal on-by-default in LLVM, so I don't know if Safari was ignored, forgotten, explicitly chosen against, or something else. I did raise an issue on the tool-conventions repository which has some discussion which interested folks may wish to engage with as well.
Adding more Rust targets
While on the surface adding a wasm32v1-unknown-unknown
target might seem like the most straightforward path here I agree with the arguments against this, and I think once the complete picture is seen it's clear that this is no longer an "obvious path forward". Both the benefits and downsides of std
on wasm32-unknown-unknown
are real and I don't think there's an obvious decision of "it's worth it" vs "it's not". We already have a lot of wasm targets and it'd be unfortunate to keep adding more for various combinations, it's a pretty heavy hammer for what should be a relatively localized solution.
If someone is interested to champion this cause though I'd recommend following the MCP process for adding a new target to the compiler. It's pretty clear what this target would be if it were added, but there should also be dedicated discussion exclusively for that in Zulip. (although this thread is a bit of a precursor to that as well of course)
Using -Zbuild-std
Sort of like wasm32v1-unknown-unknown
this is a possible candidate for "most obvious solution". That being said the pain of using nightly Rust and possibly resulting in breakage is also very real. Integrating -Zbuild-std
into wrapper tools like wasm-pack
is not always obvious and can be difficult to figure out. Ideally -Zbuild-std
would be stable but that's a whole separate thorny set of questions.
I'm not aware how best to push on this in terms of helping making it stable. My guess is that it would require a lot more context and implementation effort outside of the interests of this thread. I also suspect Cargo folks are well-aware of the use case of recompiling libstd with/without CPU features so I at least personally reach the (unfortunate for this thread) conclusion that there may not be much to help the -Zbuild-std
stabilization effort at this time (I'd be happy to be wrong though!)
Adding a *-bindgen
Rust target
I personally intentionally never advocated for this when I was maintaining wasm-bindgen
, and I would have advocated against it had it been proposed at the time. I'm not currently maintaining wasm-bindgen
though so things can always shift, though.
The wasm-bindgen
crate was never designed for stability of compiler artifacts in mind and it has quite a lot of hacks which if anyone were to try to replicate they'd (reasonably) run away screaming. For example did you know that wasm-bindgen
has an interpreter for wasm which it executes to figure out types in your program? I always felt this was an appropriate hack for a crates.io-based crate but wildly inappropriate for something like the Rust standard library.
In that sense, at least if foundational parts haven't changed in the meantime, my opinion is that *-bindgen
targets in Rust is a dead end. It shouldn't happen and problems need to be solved via some other means. The "easiest" alternative solution here is to probably improve integration with Emscripten which is already tailor-made for running C/C++/wasm/LLVM on the web while assuming that JS exists. I put "easiest" in quotes here though because I realize this probably isn't easy, and I don't even know the depth of it myself as I'm not that knowledgable about Emscripten.
Timelines of a solution
One thing I'll also call attention to is the various timelines involved here. For example if it takes a year or so to figure out how to officially solve this then that technically means it's no longer a problem because at that point Safari support for wasm32-unknown-unknown
is probably at a high-enough level it's ok to use then. This to me cuts both ways in terms of if folks need a solution right this red hot second then pushing on some solutions in this thread may not be the best path forward due to the timelines involved. On the other hand though now's the best time to figure out solutions for these so this doesn't keep coming up in the future.
Sorry for the long read and I'm also sorry I can't really offer much in the way of a strong conclusion here either. I suspect solving this "for real" will require some dedicated work by someone which is more than "just copy that solution over there and tweak it a bit", since this thread is showing that all the "easy ideas" have serious drawbacks one way or another.