mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
### Description
This PR includes the following changes:
- upgrade js dependencies
- enable STRICT mode for web assembly build.
- corresponding fix for cmake-js upgrade
- corresponsing fix for linter upgrade
- upgrade default typescript compile option of:
- `moduleResolution`: from `node` to `node16`
- `target`: from `es2017` to `es2020`
- fix ESM module import in commonJS source file
## change explanation
### changes to onnxruntime_webassembly.cmake
`-s WASM=1` and `-s LLD_REPORT_UNDEFINED` in latest version is
by-default and deprecated.
### changes to onnxruntime_node.cmake
The npm package `cmake-js` updated its way to find file `node.lib`.
previously it downloads this file from Node.js public release channel,
and now it generates it from a definition file.
The node.js release channel does not contain a windows/arm64 version, so
previously cmake-js will fail to download `node.lib` for that platform.
this is why we made special handling to download the unofficial binary
to build. now this is no longer needed so we removed that from the cmake
file.
### changes to tsconfig.json
`node16` module resolution supports async import and `es2020` as target
supports top level await.
84 lines
2.7 KiB
CMake
84 lines
2.7 KiB
CMake
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
set(JS_ROOT ${REPO_ROOT}/js)
|
|
set(JS_COMMON_ROOT ${JS_ROOT}/common)
|
|
set(JS_NODE_ROOT ${JS_ROOT}/node)
|
|
|
|
find_program(NPM_CLI
|
|
NAMES "npm.cmd" "npm"
|
|
DOC "NPM command line client"
|
|
REQUIRED
|
|
)
|
|
|
|
# verify Node.js and NPM
|
|
execute_process(COMMAND node --version
|
|
WORKING_DIRECTORY ${JS_NODE_ROOT}
|
|
OUTPUT_VARIABLE node_version
|
|
RESULT_VARIABLE had_error
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
if(had_error)
|
|
message(FATAL_ERROR "Failed to find Node.js: " ${had_error})
|
|
endif()
|
|
execute_process(COMMAND ${NPM_CLI} --version
|
|
WORKING_DIRECTORY ${JS_NODE_ROOT}
|
|
OUTPUT_VARIABLE npm_version
|
|
RESULT_VARIABLE had_error
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
if(had_error)
|
|
message(FATAL_ERROR "Failed to find NPM: " ${had_error})
|
|
endif()
|
|
|
|
# setup ARCH
|
|
if (APPLE)
|
|
if (CMAKE_OSX_ARCHITECTURES_LEN GREATER 1)
|
|
message(FATAL_ERROR "CMake.js does not support multi-architecture for macOS")
|
|
endif()
|
|
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
|
set(NODEJS_BINDING_ARCH arm64)
|
|
else()
|
|
set(NODEJS_BINDING_ARCH x64)
|
|
endif()
|
|
elseif (WIN32)
|
|
if (NOT MSVC)
|
|
message(FATAL_ERROR "Only support MSVC for building Node.js binding on Windows.")
|
|
endif()
|
|
if(onnxruntime_target_platform STREQUAL "ARM64")
|
|
set(NODEJS_BINDING_ARCH arm64)
|
|
elseif(onnxruntime_target_platform STREQUAL "x64")
|
|
set(NODEJS_BINDING_ARCH x64)
|
|
else()
|
|
message(FATAL_ERROR "Unsupported target platform for Node.js binding:" ${onnxruntime_target_platform})
|
|
endif()
|
|
else()
|
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
|
|
set(NODEJS_BINDING_ARCH arm64)
|
|
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
|
set(NODEJS_BINDING_ARCH x64)
|
|
else()
|
|
message(FATAL_ERROR "Unsupported target platform for Node.js binding:" ${onnxruntime_target_platform})
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT onnxruntime_ENABLE_STATIC_ANALYSIS)
|
|
# add custom target
|
|
add_custom_target(js_npm_ci ALL
|
|
COMMAND ${NPM_CLI} ci
|
|
WORKING_DIRECTORY ${JS_ROOT}
|
|
COMMENT "NPM install on /js")
|
|
|
|
add_custom_target(js_common_npm_ci ALL
|
|
COMMAND ${NPM_CLI} ci
|
|
WORKING_DIRECTORY ${JS_COMMON_ROOT}
|
|
COMMENT "NPM install on /js/common")
|
|
|
|
add_custom_target(nodejs_binding_wrapper ALL
|
|
COMMAND ${NPM_CLI} ci
|
|
COMMAND ${NPM_CLI} run build -- --onnxruntime-build-dir=${CMAKE_CURRENT_BINARY_DIR} --config=${CMAKE_BUILD_TYPE} --arch=${NODEJS_BINDING_ARCH}
|
|
WORKING_DIRECTORY ${JS_NODE_ROOT}
|
|
COMMENT "Using cmake-js to build OnnxRuntime Node.js binding")
|
|
|
|
add_dependencies(js_common_npm_ci js_npm_ci)
|
|
add_dependencies(nodejs_binding_wrapper js_common_npm_ci)
|
|
add_dependencies(nodejs_binding_wrapper onnxruntime)
|
|
endif()
|