Skip to content

Commit caefefe

Browse files
authored
Cleaned up Wasm cmake (#13106)
### Summary Before, if dependencies for the API were not enabled in the cmake command, you would get linking errors when trying to compile. Now, if EXECUTORCH_BUILD_WASM is turned on, an error will occur during configure stage if dependencies were not enabled. Also changed the API to use executorch_kernels rather than hardcoding in portable_ops_lib. For the unit tests, changed the libraries to PRIVATE instead of PUBLIC and to use `--pre-js` instead of `--post-js` as that is the recommended way of interfacing with the Embind Module. ### Test plan ```bash bash scripts/build_wasm_tests.sh cd cmake-out-wasm/extension/wasm/test/ npm test # after installing Jest ```
1 parent 366baa6 commit caefefe

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

extension/wasm/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ list(
3737
embind
3838
executorch_core
3939
extension_data_loader
40-
portable_ops_lib
4140
extension_module_static
4241
extension_tensor
4342
extension_runner_util
@@ -49,8 +48,12 @@ target_compile_options(executorch_wasm PUBLIC ${_common_compile_options})
4948
target_include_directories(
5049
executorch_wasm PUBLIC ${_common_include_directories}
5150
)
52-
target_link_libraries(executorch_wasm PUBLIC ${link_libraries})
51+
target_link_libraries(
52+
executorch_wasm
53+
PUBLIC ${link_libraries}
54+
INTERFACE executorch_kernels
55+
)
5356

54-
if(EXECUTORCH_BUILD_WASM_TESTS)
57+
if(BUILD_TESTING)
5558
add_subdirectory(test)
5659
endif()

extension/wasm/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ add_custom_target(
4141
)
4242

4343
add_executable(executorch_wasm_tests)
44-
target_link_libraries(executorch_wasm_tests PUBLIC executorch_wasm)
44+
target_link_libraries(executorch_wasm_tests PRIVATE executorch_wasm)
4545
target_link_options(
4646
executorch_wasm_tests
47-
PUBLIC
47+
PRIVATE
4848
--embed-file
4949
"${MODELS_DIR}@/"
50-
--post-js
50+
--pre-js
5151
${CMAKE_CURRENT_SOURCE_DIR}/unittests.js
5252
-sASSERTIONS=2
5353
)

extension/wasm/test/unittests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
let et;
9+
var Module = {};
10+
const et = Module;
1011
beforeAll((done) => {
11-
et = Module;
1212
et.onRuntimeInitialized = () => {
1313
done();
1414
}

scripts/build_wasm_tests.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../"
1111
emcmake cmake . -DEXECUTORCH_BUILD_WASM=ON \
1212
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
1313
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
14-
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
1514
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
1615
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
17-
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
18-
-DEXECUTORCH_BUILD_WASM_TESTS=ON \
16+
-DEXECUTORCH_SELECT_OPS_LIST="aten::mm.out,aten::add.out" \
17+
-DEXECUTORCH_BUILD_TESTS=ON \
1918
-DCMAKE_BUILD_TYPE=Release \
2019
-B"${CMAKE_OUT}"
2120

tools/cmake/preset/default.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ define_overridable_option(
152152
EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER "Build CoreML executor runner." BOOL
153153
OFF
154154
)
155+
define_overridable_option(
156+
EXECUTORCH_BUILD_WASM "Build the ExecuTorch JavaScript API" BOOL OFF
157+
)
155158

156159
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
157160
set(_default_executorch_build_pthreadpool OFF)
@@ -321,6 +324,11 @@ check_conflicting_options_on(
321324
IF_ON EXECUTORCH_SELECT_OPS_LIST CONFLICTS_WITH EXECUTORCH_SELECT_OPS_MODEL
322325
)
323326

327+
check_required_options_on(
328+
IF_ON EXECUTORCH_BUILD_WASM REQUIRES EXECUTORCH_BUILD_EXTENSION_MODULE
329+
EXECUTORCH_BUILD_EXTENSION_TENSOR
330+
)
331+
324332
if(NOT EXISTS ${EXECUTORCH_PAL_DEFAULT_FILE_PATH})
325333
message(
326334
FATAL_ERROR

0 commit comments

Comments
 (0)