From 9400de3917397e8e799b774ff7fcb77496473e87 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 21 Jun 2023 15:07:33 -0700 Subject: [PATCH 1/2] Build WebAssembly with `SINGLE_FILE=1` Summary: Emscripten normally compiles a binary into a `.js` file and a `.wasm` file. The `.js` file contains a shim to load the WebAssembly file for the target platform, along with passing some environment information to the underlying assembly. Under Node this would use APIs like `fs.readFile` and its WebAssembly APIs to load the binary. In a browser, APIs like `instantiateStreaming` are used to start downloading and compiling the binary at the same time. This format creates many, many, headaches, and manual bundler configuration. E.g. we must tell Webpack to treat WASM files as auxilary files instead of WebAssembly, cannot use Emscripten's loader directly, and would need to add more variants of the binary, since (or Node polyfills in the browser) `-s ENVIRONMENT='web,node'` emits code that looks like `if (isNode) {require('fs')}`. This change makes us instead pack the WebAssembly as base64 inline with the JS loader. This adds a size penalty, and means we cannot start async compilation until the entire file is present, but should work out of the box when using different bundlers and configurations, and the size is small enough where it likely makes sense to inline into the bundle anyway. There is a [proposal for integration of WebAssembly and ES Modules](https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration) that Node has experimental support for, and bundlers are veering towards supporting. It is the eventual solution we should target, but does not seem mature enough yet. E.g. WebPack [does not support](https://github.com/webpack/webpack/issues/11893) WebAssembly import objects, and will instead try to import each of the named imports as modules. Differential Revision: D46884398 fbshipit-source-id: 6bbaf8a82ddca5519af921040e86792eb9fcc1a8 --- javascript/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/javascript/CMakeLists.txt b/javascript/CMakeLists.txt index 15ea1e94..3feeb548 100644 --- a/javascript/CMakeLists.txt +++ b/javascript/CMakeLists.txt @@ -64,9 +64,11 @@ target_link_options(asmjs-async PUBLIC add_executable(wasm-sync $) target_link_options(wasm-sync PUBLIC "SHELL:-s WASM=1" + "SHELL:-s SINGLE_FILE=1" "SHELL:-s WASM_ASYNC_COMPILATION=0") add_executable(wasm-async $) target_link_options(wasm-async PUBLIC "SHELL:-s WASM=1" + "SHELL:-s SINGLE_FILE=1" "SHELL:-s WASM_ASYNC_COMPILATION=1") -- 2.50.1.windows.1 From 708d8301f5534b397376f7ea5d906714733db46c Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 21 Jun 2023 15:08:02 -0700 Subject: [PATCH 2/2] Add more ignore patterns (#1311) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1311 Adds some more output files to be ignored by prettier, eslint, tsconfig Reviewed By: rozele Differential Revision: D46884397 fbshipit-source-id: 302acf78508abe933529b0b35e1c3a4fb531bdc8 --- javascript/.eslintrc.js | 2 +- javascript/.prettierignore | 4 +++- javascript/tsconfig.json | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/javascript/.eslintrc.js b/javascript/.eslintrc.js index a350868b..e43435dc 100644 --- a/javascript/.eslintrc.js +++ b/javascript/.eslintrc.js @@ -11,7 +11,7 @@ const path = require('path'); module.exports = { root: true, - ignorePatterns: ['dist/**', 'tests/generated/**'], + ignorePatterns: ['binaries/**', 'build/**', 'dist/**', 'tests/generated/**'], extends: ['eslint:recommended', 'plugin:prettier/recommended'], plugins: ['prettier'], rules: { diff --git a/javascript/.prettierignore b/javascript/.prettierignore index 8b9a7043..6ee82041 100644 --- a/javascript/.prettierignore +++ b/javascript/.prettierignore @@ -1,2 +1,4 @@ -tests/generated/ +binaries/ +build/ src/generated/ +tests/generated/ diff --git a/javascript/tsconfig.json b/javascript/tsconfig.json index ba6074ad..a1434af8 100644 --- a/javascript/tsconfig.json +++ b/javascript/tsconfig.json @@ -17,5 +17,9 @@ }, "ts-node": { "transpileOnly": true - } + }, + "exclude": [ + "binaries/**/*", + "build/**/*" + ] } -- 2.50.1.windows.1