Wasm fallback and min safari version

### This PR
- fixes WASM not loading on older Apple devices/browsers
- adds a fallback mechanism

#### Fix for older devices
The addition of `MIN_SAFARI_VERSION` is the only flag that resolved the issue on the affected devices (see discussion: https://2dimensions.slack.com/archives/CLLCU09T6/p1714494911457529)

#### Fallback
This PR is meant to showcase a way to introduce a fallback mechanism quickly. Can it be merged? Yes. But we need to consider the impact and alternatives (see below). _Also note that this PR makes an assumption about the best way to handle our single packages, which needs to be discussed before merging (see below)._

#### Problem with this fallback
We'll increase the NPM package size by having two WASM files: `rive.wasm` and `rive_fallback.wasm`. To alleviate any concern, this can be resolved with proper documentation. The packages that load the WASM remotely do so through `unpkg` or `jsdelvr` (or overridden manually). It would not have an impact on the actual end client (to my knowledge), but maybe the perception of the "increased" NPM package size is something we want to avoid.

#### Benefit of this approach
Quick, with minimal change. We continue to use `unpkg` and `jsdelvr` to host.

#### TODO
Adaptive Loading: Implement more sophisticated loading strategies, such as loading different WASM modules based on the user's browser capabilities or preferences. This draft PR only loads the fallback if the current one failed. This does not need to be part of this PR and can be a future enhancement.

### Single vs Non-Single versions
**This fallback mechanism will only work for the non-single packages where we load the WASM bundle separately**. Not the **-single versions, where WASM is bundled with the JS. In my testing during the call to `loadRuntime` the callback for `locateFile` will not be called if Emscripten is built with `-sSINGLE_FILE=1`.

At the time of making the draft PR I've not come up with a solution for this. It might not be possible.

TODO: This needs to be investigated more. Or we should reach out to Emscripten.

#### What this means
If we can't create a fallback for these, then we should make a decision around our single libraries:
- Should they prefer to support older architecture and we recommend that people use the non-single packages to benefit from the fallback mechanism.
- Or the alternative and we still recommend using the non-single packages to benefit from a fallback.

**There are other benefits to using the non-single:**
- Streaming Compilation: Newer browsers can start compiling the WASM file as soon as it starts downloading, which could lead to faster execution start times.
- Better Cache Control: JavaScript and WASM can be cached separately. If you update one, users may not need to re-download the other. With the single version, I can see how people may end up using it in a way where any update to their site might then be bundling everything again.

### Alternative One
_Most of the above still apply._

Instead of adding `rive_fallback.wasm` to the current packages, we create another NPM package called `rive_fallback` or something. And all this package is responsible for is to distribute the fallback WASM files, for example, `rive_canvas_fallback.wasm` and `rive_webgl_fallback.wasm`.

**Benefit**
We do not increase the perceived NPM package size for our published packages. And we can continue to use `unpkg` and `jsdelivr` for hosting.

### Alternative Two
_Most of the above still apply._
We build our own hosting with versioning, etc.

Diffs=
4342a3f04 Wasm fallback and min safari version (#7214)
2 files changed
tree: 062db4603d95ed653ac8671d241b8c16fb213970
  1. glad/
  2. include/
  3. path_fiddle/
  4. renderer/
  5. submodules/
  6. webgpu_player/
  7. .gitmodules
  8. .rive_head
  9. LICENSE
  10. make_dawn.sh
  11. premake5.lua
  12. premake5_pls_renderer.lua
  13. README.md
README.md

Rive Renderer

The Rive Renderer is a vector and raster graphics renderer custom-built for Rive content, for animation, and for runtime.

This repository contains the renderer code and an example for how to interface with it directly. The code within this repository does not contain a Rive runtime. It contains the best in class concrete implementation of Rive's rendering abstraction layer, which we call the Rive Renderer.

Clone this repo

Make sure to clone this repo with submodules!

git clone --recurse-submodules git@github.com:rive-app/rive-renderer.git

Build GLFW

cd submodules/rive-cpp/skia/dependencies
./make_glfw.sh

Install Premake5

Grab the binary from the premake5 GitHub releases: https://github.com/premake/premake-core/releases/ or you can build your own for Apple Silicon:

git clone --depth 1 --branch master https://github.com/premake/premake-core.git
cd premake-core
make -f Bootstrap.mak osx PLATFORM=ARM
# binaries will be in bin/release/* put them in your path

Install Python PLY

python3 -m pip install ply

Call Premake & Build

PREMAKE_PATH="$(pwd)/submodules/rive-cpp/build" premake5 gmake2 --with_rive_text --config=release --out=out/release
cd out/release
make -j20
# run path_fiddle
./path_fiddle [/path/to/my.riv]

Build and serve for WebGL2

PREMAKE_PATH="$(pwd)/submodules/rive-cpp/build" premake5 gmake2 --with_rive_text --config=release --arch=wasm --out=out/wasm_release
cd out/wasm_release
# Ensure your emsdk_env is configured.
make -j20 path_fiddle
# serve to http://localhost:5555/
python3 -m http.server 5555

Helpful keys

  • h/H: add/subtract copies to the left and right (only when a .riv is provided)
  • j/J: add/subtract copies below (only when a .riv is provided)
  • k/K: add/subtract copies above (only when a .riv is provided)
  • p: pause runtime (for benchmarking the renderer in isolation)
  • a: toggle “atomic” mode