@@ -244,10 +244,6 @@ else()
244244 )
245245
246246 if (onnxruntime_USE_JSEP)
247- # NOTE: "-s ASYNCIFY=1" is required for JSEP to work with WebGPU
248- # This flag allows async functions to be called from sync functions, in the cost of binary size and
249- # build time. See https://emscripten.org/docs/porting/asyncify.html for more details.
250-
251247 target_compile_definitions (onnxruntime_webassembly PRIVATE USE_JSEP=1)
252248 target_link_options (onnxruntime_webassembly PRIVATE
253249 "SHELL:--pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-jsep.js\" "
@@ -275,13 +271,24 @@ else()
275271 endif ()
276272
277273 if (onnxruntime_USE_JSEP OR onnxruntime_USE_WEBGPU OR onnxruntime_USE_WEBNN)
278- # if any of the above is enabled, we need to use the asyncify library
279- target_link_options (onnxruntime_webassembly PRIVATE
280- "SHELL:--pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-async.js\" "
281- "SHELL:-s ASYNCIFY=1"
282- "SHELL:-s ASYNCIFY_STACK_SIZE=65536"
283- )
284- list (APPEND onnxruntime_webassembly_script_deps "${ONNXRUNTIME_ROOT} /wasm/pre-async.js" )
274+ if (onnxruntime_ENABLE_WEBASSEMBLY_JSPI)
275+ target_link_options (onnxruntime_webassembly PRIVATE
276+ "SHELL:-s JSPI=1"
277+ "SHELL:-s JSPI_EXPORTS=[OrtAppendExecutionProvider,OrtCreateSession,OrtRun,OrtRunWithBinding,OrtBindInput]"
278+ )
279+ else ()
280+ # NOTE: "-s ASYNCIFY=1" is required for JSEP to work with WebGPU
281+ # This flag allows async functions to be called from sync functions, in the cost of binary size and
282+ # build time. See https://emscripten.org/docs/porting/asyncify.html for more details.
283+ #
284+ # if any of the above is enabled, we need to use the asyncify library
285+ target_link_options (onnxruntime_webassembly PRIVATE
286+ "SHELL:--pre-js \" ${ONNXRUNTIME_ROOT} /wasm/pre-async.js\" "
287+ "SHELL:-s ASYNCIFY=1"
288+ "SHELL:-s ASYNCIFY_STACK_SIZE=65536"
289+ )
290+ list (APPEND onnxruntime_webassembly_script_deps "${ONNXRUNTIME_ROOT} /wasm/pre-async.js" )
291+ endif ()
285292 endif ()
286293
287294 if (onnxruntime_EMSCRIPTEN_SETTINGS)
@@ -322,8 +329,12 @@ else()
322329 endif ()
323330 endif ()
324331
325- # Set link flag to enable exceptions support, this will override default disabling exception throwing behavior when disable exceptions.
326- target_link_options (onnxruntime_webassembly PRIVATE "SHELL:-s DISABLE_EXCEPTION_THROWING=0" )
332+ if (NOT onnxruntime_ENABLE_WEBASSEMBLY_JSPI)
333+ # Set link flag to enable exceptions support, this will override default disabling exception throwing behavior when disable exceptions.
334+ target_link_options (onnxruntime_webassembly PRIVATE
335+ "SHELL:-s DISABLE_EXCEPTION_THROWING=0"
336+ )
337+ endif ()
327338
328339 if (onnxruntime_ENABLE_WEBASSEMBLY_PROFILING)
329340 target_link_options (onnxruntime_webassembly PRIVATE --profiling --profiling-funcs)
@@ -379,8 +390,11 @@ else()
379390 if (onnxruntime_USE_JSEP)
380391 string (APPEND target_name ".jsep" )
381392 elseif (onnxruntime_USE_WEBGPU OR onnxruntime_USE_WEBNN)
382- string (APPEND target_name ".asyncify" )
383- # TODO: support JSPI and add ".jspi" once JSPI build is supported
393+ if (onnxruntime_ENABLE_WEBASSEMBLY_JSPI)
394+ string (APPEND target_name ".jspi" )
395+ else ()
396+ string (APPEND target_name ".asyncify" )
397+ endif ()
384398 endif ()
385399
386400 set_target_properties (onnxruntime_webassembly PROPERTIES OUTPUT_NAME ${target_name} SUFFIX ".mjs" )
0 commit comments