Skip to content

Commit aad3c79

Browse files
committed
Base commit for using EMSDK 3.1.74 (LTO disabled)
1 parent 444fceb commit aad3c79

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
[submodule "cmake/external/emsdk"]
88
path = cmake/external/emsdk
99
url = https://github.com/emscripten-core/emsdk.git
10-
branch = 3.1.59
10+
branch = 3.1.74

cgmanifests/generated/cgmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"component": {
77
"type": "git",
88
"git": {
9-
"commitHash": "d52c46520124845b1e0e0525f2759299d840143f",
9+
"commitHash": "3d6d8ee910466516a53e665b86458faa81dae9ba",
1010
"repositoryUrl": "https://github.com/emscripten-core/emsdk.git"
1111
},
1212
"comments": "git submodule at cmake/external/emsdk"

cmake/adjust_global_compile_flags.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
2929
# (2) "-flto=thin" does not work correctly for wasm-ld.
3030
# we don't set onnxruntime_ENABLE_LTO because it appends flag "-flto=thin"
3131
# instead, we manually set CMAKE_CXX_FLAGS "-flto"
32-
string(APPEND CMAKE_C_FLAGS " -flto")
33-
string(APPEND CMAKE_CXX_FLAGS " -flto")
32+
#string(APPEND CMAKE_C_FLAGS " -flto")
33+
#string(APPEND CMAKE_CXX_FLAGS " -flto")
3434
endif()
3535

3636
if (onnxruntime_ENABLE_WEBASSEMBLY_DEBUG_INFO)
@@ -372,4 +372,4 @@ endif()
372372

373373
if (onnxruntime_USE_EXTENSIONS)
374374
include_directories(${REPO_ROOT}/include/onnxruntime/core/session)
375-
endif()
375+
endif()

cmake/onnxruntime_webassembly.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,59 @@ jsepDownload:_pp_")
466466
endif()
467467

468468
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME ${target_name} SUFFIX ".mjs")
469+
470+
#
471+
# The following POST_BUILD script is a workaround for enabling:
472+
# - using onnxruntime-web with Multi-threading enabled when import from CDN
473+
# - using onnxruntime-web when consumed in some frameworks like Vite
474+
#
475+
# In the use case mentioned above, the file name of the script may be changed. So we need to replace the line:
476+
# `new Worker(new URL("ort-wasm-*.mjs", import.meta.url),`
477+
# with
478+
# `new Worker(new URL(import.meta.url),`
479+
#
480+
# This behavior is introduced in https://github.com/emscripten-core/emscripten/pull/22165. Since it's unlikely to be
481+
# reverted, and there is no config to disable this behavior, we have to use a post-build script to workaround it.
482+
#
483+
484+
# Generate a script to do the post-build work
485+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js "
486+
const fs = require('fs');
487+
const path = require('path');
488+
489+
// node wasm_post_build.js <mjsFilePath>
490+
const mjsFilePath = process.argv[2];
491+
let contents = fs.readFileSync(mjsFilePath).toString();
492+
493+
const regex = 'new Worker\\\\(new URL\\\\(\".+?\", ?import\\\\.meta\\\\.url\\\\),';
494+
const matches = [...contents.matchAll(new RegExp(regex, 'g'))];
495+
if (matches.length !== 1) {
496+
throw new Error(
497+
`Unexpected number of matches for \"${regex}\" in \"${filepath}\": ${matches.length}.`,
498+
);
499+
}
500+
501+
// Replace the only occurrence.
502+
contents = contents.replace(
503+
new RegExp(regex),
504+
`new Worker(new URL(import.meta.url),`,
505+
);
506+
507+
fs.writeFileSync(mjsFilePath, contents);
508+
"
509+
)
510+
511+
find_program(NODE_EXECUTABLE node required)
512+
if (NOT NODE_EXECUTABLE)
513+
message(FATAL_ERROR "Node is required to run the post-build script")
514+
endif()
515+
516+
add_custom_command(
517+
TARGET onnxruntime_webassembly
518+
POST_BUILD
519+
COMMAND ${CMAKE_COMMAND} -E echo "Backup file at $<TARGET_FILE_NAME:onnxruntime_webassembly>.bak"
520+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE_NAME:onnxruntime_webassembly>" "$<TARGET_FILE_NAME:onnxruntime_webassembly>.bak"
521+
COMMAND ${CMAKE_COMMAND} -E echo "Performing workaround for $<TARGET_FILE_NAME:onnxruntime_webassembly>"
522+
COMMAND ${NODE_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js" "$<TARGET_FILE_NAME:onnxruntime_webassembly>"
523+
)
469524
endif()

tools/ci_build/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def convert_arg_line_to_args(self, arg_line):
478478
# WebAssembly build
479479
parser.add_argument("--build_wasm", action="store_true", help="Build for WebAssembly")
480480
parser.add_argument("--build_wasm_static_lib", action="store_true", help="Build for WebAssembly static library")
481-
parser.add_argument("--emsdk_version", default="3.1.59", help="Specify version of emsdk")
481+
parser.add_argument("--emsdk_version", default="3.1.74", help="Specify version of emsdk")
482482

483483
parser.add_argument("--enable_wasm_simd", action="store_true", help="Enable WebAssembly SIMD")
484484
parser.add_argument("--enable_wasm_threads", action="store_true", help="Enable WebAssembly multi-threads support")

tools/ci_build/github/azure-pipelines/templates/linux-wasm-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ jobs:
8686
- script: |
8787
set -ex
8888
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
89-
./emsdk install 3.1.59 ccache-git-emscripten-64bit
90-
./emsdk activate 3.1.59 ccache-git-emscripten-64bit
89+
./emsdk install 3.1.74 ccache-git-emscripten-64bit
90+
./emsdk activate 3.1.74 ccache-git-emscripten-64bit
9191
displayName: 'emsdk install and activate ccache for emscripten'
9292
- ${{if eq(parameters.WithCache, false)}}:
9393
- script: |
9494
set -ex
9595
cd '$(Build.SourcesDirectory)/cmake/external/emsdk'
96-
./emsdk install 3.1.59
97-
./emsdk activate 3.1.59
96+
./emsdk install 3.1.74
97+
./emsdk activate 3.1.74
9898
displayName: 'emsdk install and activate ccache for emscripten'
9999
100100
- template: build-linux-wasm-step.yml

0 commit comments

Comments
 (0)