diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 81e3f661194..22f6d38b707 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -69,6 +69,7 @@ jobs: toolchain: stable # needed for integration & memory tests codecs support - run: sudo add-apt-repository multiverse && sudo apt update && sudo apt install -y ubuntu-restricted-extras + - run: sudo apt-get -y install binaryen - run: npm install - run: rustup target add wasm32-unknown-unknown - run: npm run build diff --git a/package-lock.json b/package-lock.json index a73fec510c9..341a2e69473 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,6 @@ "@typescript-eslint/parser": "6.16.0", "arraybuffer-loader": "1.0.8", "babel-loader": "9.1.3", - "binaryen": "116.0.0", "chai": "4.3.10", "core-js": "3.34.0", "esbuild": "0.19.10", @@ -4830,16 +4829,6 @@ "node": ">=8" } }, - "node_modules/binaryen": { - "version": "116.0.0", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-116.0.0.tgz", - "integrity": "sha512-Hp0dXC6Cb/rTwWEoUS2BRghObE7g/S9umKtxuTDt3f61G6fNTE/YVew/ezyy3IdHcLx3f17qfh6LwETgCfvWkQ==", - "dev": true, - "bin": { - "wasm-opt": "bin/wasm-opt", - "wasm2js": "bin/wasm2js" - } - }, "node_modules/body-parser": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", @@ -18204,12 +18193,6 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, - "binaryen": { - "version": "116.0.0", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-116.0.0.tgz", - "integrity": "sha512-Hp0dXC6Cb/rTwWEoUS2BRghObE7g/S9umKtxuTDt3f61G6fNTE/YVew/ezyy3IdHcLx3f17qfh6LwETgCfvWkQ==", - "dev": true - }, "body-parser": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", diff --git a/package.json b/package.json index 5939f8598d3..22d06b23563 100644 --- a/package.json +++ b/package.json @@ -95,19 +95,45 @@ }, "typesVersions": { "*": { - "experimental": ["./dist/es2017/experimental/index.d.ts"], - "experimental/features": ["./dist/es2017/experimental/features/index.d.ts"], - "experimental/features/embeds": ["./dist/es2017/__GENERATED_CODE/index.d.ts"], - "experimental/features/*": ["./dist/es2017/experimental/features/*.d.ts"], - "experimental/tools": ["./dist/es2017/experimental/tools/index.d.ts"], - "experimental/tools/*": ["./dist/es2017/experimental/tools/*/index.d.ts"], - "features": ["./dist/es2017/features/list/index.d.ts"], - "features/*": ["./dist/es2017/features/list/*.d.ts"], - "logger": ["./dist/es2017/log.d.ts"], - "minimal": ["./dist/es2017/minimal.d.ts"], - "tools": ["./dist/es2017/tools/index.d.ts"], - "tools/*": ["./dist/es2017/tools/*/index.d.ts"], - "types": ["./dist/es2017/public_types.d.ts"] + "experimental": [ + "./dist/es2017/experimental/index.d.ts" + ], + "experimental/features": [ + "./dist/es2017/experimental/features/index.d.ts" + ], + "experimental/features/embeds": [ + "./dist/es2017/__GENERATED_CODE/index.d.ts" + ], + "experimental/features/*": [ + "./dist/es2017/experimental/features/*.d.ts" + ], + "experimental/tools": [ + "./dist/es2017/experimental/tools/index.d.ts" + ], + "experimental/tools/*": [ + "./dist/es2017/experimental/tools/*/index.d.ts" + ], + "features": [ + "./dist/es2017/features/list/index.d.ts" + ], + "features/*": [ + "./dist/es2017/features/list/*.d.ts" + ], + "logger": [ + "./dist/es2017/log.d.ts" + ], + "minimal": [ + "./dist/es2017/minimal.d.ts" + ], + "tools": [ + "./dist/es2017/tools/index.d.ts" + ], + "tools/*": [ + "./dist/es2017/tools/*/index.d.ts" + ], + "types": [ + "./dist/es2017/public_types.d.ts" + ] } }, "keywords": [ @@ -132,7 +158,7 @@ "build:dev": "./scripts/generate_build.mjs --dev-mode", "build:all": "npm run build:wasm:release && npm run bundle && npm run bundle:min && npm run build", "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", - "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", + "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", "bundle": "webpack --progress --config webpack.config.mjs --env production", "bundle:min": "webpack --progress --config webpack.config.mjs --env minify --env production", "bundle:min:watch": "webpack --progress --config webpack.config.mjs -w --env production --env minify", @@ -191,7 +217,6 @@ "@typescript-eslint/parser": "6.16.0", "arraybuffer-loader": "1.0.8", "babel-loader": "9.1.3", - "binaryen": "116.0.0", "chai": "4.3.10", "core-js": "3.34.0", "esbuild": "0.19.10", diff --git a/scripts/wasm-optimize.mjs b/scripts/wasm-optimize.mjs deleted file mode 100644 index 0a3216fe4f3..00000000000 --- a/scripts/wasm-optimize.mjs +++ /dev/null @@ -1,63 +0,0 @@ -/** - * ============= wasm-optimize util ============= - * - * == What is this? - * - * This file allows to optimize a WebAssembly binary file (`.wasm`) by running - * binaryen's wasm-opt tool on it, through its JavaScript API. - * - * To run it, provide the source WebAssembly file as first argument and the - * output as second: - * ``` - * node wasm-optimize.mjs source.wasm dest.wasm - * ``` - * - * == Why? - * - * As the WebAssembly file produced by the RxPlayer is mostly for performance - * enhancement, it is important that we squeeze the most performance out of it - * at compile-time. - * - * The wasm-opt tool specically optimizes WebAssembly files, it is different - * from performance improvements made by the initial source compiler (e.g. the - * Rust compiler) which may not have the same constraints. Whether this script - * brings or not an improvement in comparison to the source WebAssembly file - * still should probably be regularly checked in real-life scenarios. - */ - -import binaryen from "binaryen"; -import * as fs from "fs"; - -run(); -function run() { - let inputFileName; - let outputFileName; - - if (process.argv.length < 3) { - console.error("Error: missing input file as first argument"); - process.exit(1); - } - if (process.argv.length < 4) { - console.error("Error: missing output file as second argument"); - process.exit(1); - } - inputFileName = process.argv[2]; - outputFileName = process.argv[3]; - - console.log("Starting logic to optimize wasm file:", inputFileName); - - let dataU8; - try { - const data = fs.readFileSync(inputFileName); - dataU8 = new Uint8Array(data.buffer); - binaryen.setOptimizeLevel(4); - const module = binaryen.readBinary(dataU8); - module.optimize(); - const output = module.emitBinary(); - fs.writeFileSync(outputFileName, output); - } catch (err) { - console.error("Error:", err?.message ?? "Unknown"); - process.exit(1); - } - console.log("WASM successfuly optimized!"); -} diff --git a/src/parsers/manifest/dash/wasm-parser/README.md b/src/parsers/manifest/dash/wasm-parser/README.md index 74b781b3aff..01d950c093b 100644 --- a/src/parsers/manifest/dash/wasm-parser/README.md +++ b/src/parsers/manifest/dash/wasm-parser/README.md @@ -251,12 +251,13 @@ fear that they may change in the future, in which case this documentation could easily be outdated. To be able to call those scripts, you will need to have the Rust compiler -toolchain installed and ready to compile to WebAssembly. +toolchain installed and ready to compile to WebAssembly as well as `binaryen`, a +WebAssembly-specialized toolbox. -To do this, the easiest way would be to rely on `rustup`, a tool to install and -update Rust toolchains: +There are several ways this can be done, with the easiest way generally being: - 1. Install [rustup](https://rustup.rs/) + 1. Install [rustup](https://rustup.rs/), which is a tool intended to + facilitate the installation of Rust toolchains 2. Install and rely on the stable toolchain: ```sh @@ -268,4 +269,6 @@ update Rust toolchains: rustup target add wasm32-unknown-unknown ``` + 4. Now install [binaryen](https://github.com/WebAssembly/binaryen) + That should be it!