Skip to content

Commit 0ba3a56

Browse files
committed
Clarified selective build section and discourage from using post-js
1 parent dd4ccd3 commit 0ba3a56

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

extension/wasm/README.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ emcmake cmake . -DEXECUTORCH_BUILD_WASM=ON \
3333
cmake --build cmake-out-wasm --target executorch_wasm -j32
3434
```
3535

36-
You may also use the selective build options found in the [Kernel Library Selective Build guide](../../docs/source/kernel-library-selective-build.md) or with optimized kernels using the `EXECUTORCH_BUILD_KERNELS_OPTIMIZED` option. Portable kernels are used by default.
36+
To reduce the binary size, you may also use the selective build options found in the [Kernel Library Selective Build guide](../../docs/source/kernel-library-selective-build.md). You may also use optimized kernels with the `EXECUTORCH_BUILD_KERNELS_OPTIMIZED` option. Portable kernels are used by default.
3737

3838
### Building for Web
3939

@@ -63,37 +63,17 @@ Building this should output `executorch_wasm_lib.js` and `executorch_wasm_lib.wa
6363
<script src="executorch_wasm_lib.js"></script>
6464
```
6565

66-
Alternatively, you may want to have your code come after the JS library code.
67-
68-
```html
69-
<script src="executorch_wasm_lib.js"></script>
70-
<script>
71-
const et = Module; // Assign Module into et for ease of use
72-
et.onRuntimeInitialized = () => {
73-
// Emscripten calls Module.onRuntimeInitialized once the runtime is ready.
74-
const model = et.Module.load("mv2.pte");
75-
// ...
76-
}
77-
</script>
78-
```
79-
8066
### Building for Node.js
8167

82-
You can follow the [Building for Web](#building-for-web) instructions and access the API with:
83-
84-
```js
85-
const et = require("./executorch_wasm_lib");
86-
```
87-
88-
However, doing so does not give you access to the [Emscripten API](https://emscripten.org/docs/api_reference/index.html) which would be stored in the globals. For example, you may want to use the [File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html) in your unit tests, which cannot be done if the library is loaded with `require`. Instead, you can use the `--pre-js` or `--post-js` to prepend or append your file to the end of the JS output.
68+
While the standard way to import a module in Node.js is to use the `require` function, doing so does not give you access to the [Emscripten API](https://emscripten.org/docs/api_reference/index.html) which would be stored in the globals. For example, you may want to use the [File System API](https://emscripten.org/docs/api_reference/Filesystem-API.html) in your unit tests, which cannot be done if the library is loaded with `require`. Instead, you can use the `--pre-js` option to prepend your file to the start of the JS output and behave similarly to the example in the [Web build](#building-for-web).
8969

9070
```cmake
9171
add_executable(my_project) # Emscripten outputs this as a JS and Wasm file
9272
target_link_libraries(my_project PRIVATE executorch_wasm)
93-
target_link_options(my_project PRIVATE --post-js my_code.js) # Add any additional link options here
73+
target_link_options(my_project PRIVATE --pre-js my_code.js) # Add any additional link options here
9474
```
9575

96-
The output `my_project.js` should contain both the emitted JS code and the contents of `my_code.js`.
76+
The output `my_project.js` should contain both the emitted JS code and the contents of `my_code.js` prepended.
9777

9878
## JavaScript API
9979

0 commit comments

Comments
 (0)