Skip to content

Commit b5217ee

Browse files
committed
WASM: Temporarily rollback on wasm-opt dependency for release builds to make it work on some lg TVs
After testing at large scale our `MULTI_THREAD` feature, we noticed that some LG and samsung TVs had issues running it. The problem in question was due to an unrecognized WebAssembly Op Code by the device linked to the "sign-extensions" proposal (https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md) which was not introduced initially with the so-called "WebAssembly MVP" (the initial release of WebAssembly). It turns out that rustc (the Rust compiler) targets a WebAssembly version that is a little further than the MVP by default (it seems that this decision is actually taken by the LLVM project from what I understand from an answers in rust-lang/rust#109807) and amongst the included features is the sign-extensions feature (so the rest of included feature is totally unclear and I could not find any resource on the web listing them. From there, I was able to remove the sign-extensions Op Code from the built WebAssembly file by doing either one of these two ways: 1. Through a rustc flag (`-C target-feature=-sign-ext`). It should be noted that the inclusion of this flag prints a warning notice indicating that the flag is "unstable" Interestingly, a `-C target-cpu=mvp` flag, which looks like it is exactly what we want, is also listed in that page yet it doesn't seem to remove the sign-extensions opcode for me. Maybe because it takes an already-compiled stdlib and the problematic opcode is from there? We could re-build stdlib through another flag but this latter one is marked as "unstable" so I didn't want to adventure too far into this theory and I didn't either understand why the other flag would have an effect in that case. 2. By adding the `--signext-lowering` flag to binaryen's wasm-opt tool which is documented at: > lower sign-ext operations to wasm mvp and disable the sign > extension feature That solution is nice but I couldn't rely on that flag with the [binaryen npm module](https://www.npmjs.com/package/binaryen) we now rely on (because RxPlayer developers most likely have npm installed so it was seen as a simpler dependency in the project than binaries brought by a binaryen project that has to be installed separately). This means that to add this feature, I have to bring back the full `binaryen` package as a dependency of the RxPlayer which isn't nice. Even with its drawbacks, I chose to go with the second solution here because I was afraid due to its warning notice, the fact that the other rustc flag (-C target=mvp) didn't have the expected effect and the hint that this might not work when the feature is in stdlib. We may come back to this in the future. Still, this only fix the issue with the `sign-extensions` opcode, and not the real larger issue which is to either properly handle all devices supporting WebAssembly or to be able to detect and fallback when a device fails to compile it. This hypotetical scenario (for now, though may be more common in the future), will be handled in a future PR. It only acts on that feature. Future WebAssembly builds could break if other new features are not handled by the device.
1 parent d134224 commit b5217ee

File tree

5 files changed

+48
-99
lines changed

5 files changed

+48
-99
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
toolchain: stable
7070
# needed for integration & memory tests codecs support
7171
- run: sudo add-apt-repository multiverse && sudo apt update && sudo apt install -y ubuntu-restricted-extras
72+
- run: sudo apt-get -y install binaryen
7273
- run: npm install
7374
- run: rustup target add wasm32-unknown-unknown
7475
- run: npm run build

package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,45 @@
9595
},
9696
"typesVersions": {
9797
"*": {
98-
"experimental": ["./dist/es2017/experimental/index.d.ts"],
99-
"experimental/features": ["./dist/es2017/experimental/features/index.d.ts"],
100-
"experimental/features/embeds": ["./dist/es2017/__GENERATED_CODE/index.d.ts"],
101-
"experimental/features/*": ["./dist/es2017/experimental/features/*.d.ts"],
102-
"experimental/tools": ["./dist/es2017/experimental/tools/index.d.ts"],
103-
"experimental/tools/*": ["./dist/es2017/experimental/tools/*/index.d.ts"],
104-
"features": ["./dist/es2017/features/list/index.d.ts"],
105-
"features/*": ["./dist/es2017/features/list/*.d.ts"],
106-
"logger": ["./dist/es2017/log.d.ts"],
107-
"minimal": ["./dist/es2017/minimal.d.ts"],
108-
"tools": ["./dist/es2017/tools/index.d.ts"],
109-
"tools/*": ["./dist/es2017/tools/*/index.d.ts"],
110-
"types": ["./dist/es2017/public_types.d.ts"]
98+
"experimental": [
99+
"./dist/es2017/experimental/index.d.ts"
100+
],
101+
"experimental/features": [
102+
"./dist/es2017/experimental/features/index.d.ts"
103+
],
104+
"experimental/features/embeds": [
105+
"./dist/es2017/__GENERATED_CODE/index.d.ts"
106+
],
107+
"experimental/features/*": [
108+
"./dist/es2017/experimental/features/*.d.ts"
109+
],
110+
"experimental/tools": [
111+
"./dist/es2017/experimental/tools/index.d.ts"
112+
],
113+
"experimental/tools/*": [
114+
"./dist/es2017/experimental/tools/*/index.d.ts"
115+
],
116+
"features": [
117+
"./dist/es2017/features/list/index.d.ts"
118+
],
119+
"features/*": [
120+
"./dist/es2017/features/list/*.d.ts"
121+
],
122+
"logger": [
123+
"./dist/es2017/log.d.ts"
124+
],
125+
"minimal": [
126+
"./dist/es2017/minimal.d.ts"
127+
],
128+
"tools": [
129+
"./dist/es2017/tools/index.d.ts"
130+
],
131+
"tools/*": [
132+
"./dist/es2017/tools/*/index.d.ts"
133+
],
134+
"types": [
135+
"./dist/es2017/public_types.d.ts"
136+
]
111137
}
112138
},
113139
"keywords": [
@@ -132,7 +158,7 @@
132158
"build:dev": "./scripts/generate_build.mjs --dev-mode",
133159
"build:all": "npm run build:wasm:release && npm run bundle && npm run bundle:min && npm run build",
134160
"build:wasm:debug": "mkdir -p dist && cd ./src/parsers/manifest/dash/wasm-parser && cargo build --target wasm32-unknown-unknown && cp target/wasm32-unknown-unknown/debug/mpd_node_parser.wasm ../../../../../dist/mpd-parser.wasm",
135-
"build:wasm:release": "mkdir -p dist && cd ./src/parsers/manifest/dash/wasm-parser && cargo build --target wasm32-unknown-unknown --release && node ../../../../../scripts/wasm-optimize.mjs target/wasm32-unknown-unknown/release/mpd_node_parser.wasm ../../../../../dist/mpd-parser.wasm && cd ../../../../../ && npm run wasm-strip",
161+
"build:wasm:release": "mkdir -p dist && cd ./src/parsers/manifest/dash/wasm-parser && cargo build --target wasm32-unknown-unknown --release && wasm-opt target/wasm32-unknown-unknown/release/mpd_node_parser.wasm --signext-lowering --strip-dwarf -O4 -o ../../../../../dist/mpd-parser.wasm",
136162
"bundle": "webpack --progress --config webpack.config.mjs --env production",
137163
"bundle:min": "webpack --progress --config webpack.config.mjs --env minify --env production",
138164
"bundle:min:watch": "webpack --progress --config webpack.config.mjs -w --env production --env minify",
@@ -191,7 +217,6 @@
191217
"@typescript-eslint/parser": "6.16.0",
192218
"arraybuffer-loader": "1.0.8",
193219
"babel-loader": "9.1.3",
194-
"binaryen": "116.0.0",
195220
"chai": "4.3.10",
196221
"core-js": "3.34.0",
197222
"esbuild": "0.19.10",

scripts/wasm-optimize.mjs

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/parsers/manifest/dash/wasm-parser/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ fear that they may change in the future, in which case this documentation could
251251
easily be outdated.
252252

253253
To be able to call those scripts, you will need to have the Rust compiler
254-
toolchain installed and ready to compile to WebAssembly.
254+
toolchain installed and ready to compile to WebAssembly as well as `binaryen`, a
255+
WebAssembly-specialized toolbox.
255256

256-
To do this, the easiest way would be to rely on `rustup`, a tool to install and
257-
update Rust toolchains:
257+
There are several ways this can be done, with the easiest way generally being:
258258

259-
1. Install [rustup](https://rustup.rs/)
259+
1. Install [rustup](https://rustup.rs/), which is a tool intended to
260+
facilitate the installation of Rust toolchains
260261

261262
2. Install and rely on the stable toolchain:
262263
```sh
@@ -268,4 +269,6 @@ update Rust toolchains:
268269
rustup target add wasm32-unknown-unknown
269270
```
270271

272+
4. Now install [binaryen](https://github.com/WebAssembly/binaryen)
273+
271274
That should be it!

0 commit comments

Comments
 (0)