mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
Upgrade emsdk version to v4.0.1
This commit is contained in:
parent
0887e3694a
commit
a39326ba0b
8 changed files with 63 additions and 8 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
|
@ -7,4 +7,4 @@
|
||||||
[submodule "cmake/external/emsdk"]
|
[submodule "cmake/external/emsdk"]
|
||||||
path = cmake/external/emsdk
|
path = cmake/external/emsdk
|
||||||
url = https://github.com/emscripten-core/emsdk.git
|
url = https://github.com/emscripten-core/emsdk.git
|
||||||
branch = 3.1.59
|
branch = 4.0.1
|
||||||
|
|
|
||||||
2
cmake/external/emsdk
vendored
2
cmake/external/emsdk
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit d52c46520124845b1e0e0525f2759299d840143f
|
Subproject commit 9dbdc4b3437750b85d16931c7c801bb71a782122
|
||||||
|
|
@ -669,7 +669,7 @@ if (onnxruntime_USE_WEBGPU)
|
||||||
#
|
#
|
||||||
# We keep a copy of the missing file(s) in ${PROJECT_SOURCE_DIR}/patches/emscripten/, and now we extract them to the
|
# We keep a copy of the missing file(s) in ${PROJECT_SOURCE_DIR}/patches/emscripten/, and now we extract them to the
|
||||||
# emscripten toolchain folder.
|
# emscripten toolchain folder.
|
||||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar x "${PROJECT_SOURCE_DIR}/patches/emscripten/patch_3.1.74.tgz"
|
execute_process(COMMAND ${CMAKE_COMMAND} -E tar x "${PROJECT_SOURCE_DIR}/patches/emscripten/patch_4.0.1.tgz"
|
||||||
WORKING_DIRECTORY ${DAWN_EMSCRIPTEN_TOOLCHAIN})
|
WORKING_DIRECTORY ${DAWN_EMSCRIPTEN_TOOLCHAIN})
|
||||||
else()
|
else()
|
||||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||||
|
|
|
||||||
|
|
@ -472,4 +472,59 @@ jsepDownload:_pp_")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME ${target_name} SUFFIX ".mjs")
|
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME ${target_name} SUFFIX ".mjs")
|
||||||
|
|
||||||
|
#
|
||||||
|
# The following POST_BUILD script is a workaround for enabling:
|
||||||
|
# - using onnxruntime-web with Multi-threading enabled when import from CDN
|
||||||
|
# - using onnxruntime-web when consumed in some frameworks like Vite
|
||||||
|
#
|
||||||
|
# In the use case mentioned above, the file name of the script may be changed. So we need to replace the line:
|
||||||
|
# `new Worker(new URL("ort-wasm-*.mjs", import.meta.url),`
|
||||||
|
# with
|
||||||
|
# `new Worker(new URL(import.meta.url),`
|
||||||
|
#
|
||||||
|
# This behavior is introduced in https://github.com/emscripten-core/emscripten/pull/22165. Since it's unlikely to be
|
||||||
|
# reverted, and there is no config to disable this behavior, we have to use a post-build script to workaround it.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Generate a script to do the post-build work
|
||||||
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js "
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// node wasm_post_build.js <mjsFilePath>
|
||||||
|
const mjsFilePath = process.argv[2];
|
||||||
|
let contents = fs.readFileSync(mjsFilePath).toString();
|
||||||
|
|
||||||
|
const regex = 'new Worker\\\\(new URL\\\\(\".+?\", ?import\\\\.meta\\\\.url\\\\),';
|
||||||
|
const matches = [...contents.matchAll(new RegExp(regex, 'g'))];
|
||||||
|
if (matches.length !== 1) {
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected number of matches for \"${regex}\" in \"${filepath}\": ${matches.length}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the only occurrence.
|
||||||
|
contents = contents.replace(
|
||||||
|
new RegExp(regex),
|
||||||
|
`new Worker(new URL(import.meta.url),`,
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync(mjsFilePath, contents);
|
||||||
|
"
|
||||||
|
)
|
||||||
|
|
||||||
|
find_program(NODE_EXECUTABLE node required)
|
||||||
|
if (NOT NODE_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR "Node is required to run the post-build script")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET onnxruntime_webassembly
|
||||||
|
POST_BUILD
|
||||||
|
# Backup file at $<TARGET_FILE_NAME:onnxruntime_webassembly>.bak
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE_NAME:onnxruntime_webassembly>" "$<TARGET_FILE_NAME:onnxruntime_webassembly>.bak"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Performing post-process for $<TARGET_FILE_NAME:onnxruntime_webassembly>"
|
||||||
|
COMMAND ${NODE_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js" "$<TARGET_FILE_NAME:onnxruntime_webassembly>"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
cmake/patches/emscripten/patch_4.0.1.tgz
Normal file
BIN
cmake/patches/emscripten/patch_4.0.1.tgz
Normal file
Binary file not shown.
|
|
@ -488,7 +488,7 @@ def parse_arguments():
|
||||||
# WebAssembly build
|
# WebAssembly build
|
||||||
parser.add_argument("--build_wasm", action="store_true", help="Build for WebAssembly")
|
parser.add_argument("--build_wasm", action="store_true", help="Build for WebAssembly")
|
||||||
parser.add_argument("--build_wasm_static_lib", action="store_true", help="Build for WebAssembly static library")
|
parser.add_argument("--build_wasm_static_lib", action="store_true", help="Build for WebAssembly static library")
|
||||||
parser.add_argument("--emsdk_version", default="3.1.59", help="Specify version of emsdk")
|
parser.add_argument("--emsdk_version", default="4.0.1", help="Specify version of emsdk")
|
||||||
|
|
||||||
parser.add_argument("--enable_wasm_simd", action="store_true", help="Enable WebAssembly SIMD")
|
parser.add_argument("--enable_wasm_simd", action="store_true", help="Enable WebAssembly SIMD")
|
||||||
parser.add_argument("--enable_wasm_threads", action="store_true", help="Enable WebAssembly multi-threads support")
|
parser.add_argument("--enable_wasm_threads", action="store_true", help="Enable WebAssembly multi-threads support")
|
||||||
|
|
|
||||||
|
|
@ -82,15 +82,15 @@ jobs:
|
||||||
- script: |
|
- script: |
|
||||||
set -ex
|
set -ex
|
||||||
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
|
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
|
||||||
./emsdk install 3.1.59 ccache-git-emscripten-64bit
|
./emsdk install 4.0.1 ccache-git-emscripten-64bit
|
||||||
./emsdk activate 3.1.59 ccache-git-emscripten-64bit
|
./emsdk activate 4.0.1 ccache-git-emscripten-64bit
|
||||||
displayName: 'emsdk install and activate ccache for emscripten'
|
displayName: 'emsdk install and activate ccache for emscripten'
|
||||||
- ${{if eq(parameters.WithCache, false)}}:
|
- ${{if eq(parameters.WithCache, false)}}:
|
||||||
- script: |
|
- script: |
|
||||||
set -ex
|
set -ex
|
||||||
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
|
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
|
||||||
./emsdk install 3.1.59
|
./emsdk install 4.0.1
|
||||||
./emsdk activate 3.1.59
|
./emsdk activate 4.0.1
|
||||||
displayName: 'emsdk install and activate ccache for emscripten'
|
displayName: 'emsdk install and activate ccache for emscripten'
|
||||||
|
|
||||||
- template: build-linux-wasm-step.yml
|
- template: build-linux-wasm-step.yml
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue