Skip to content

Fix an issue in wasm nortti build and add minimal build support for vcpkg #24012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

snnn
Copy link
Member

@snnn snnn commented Mar 12, 2025

  1. Patch ONNX to support minimal build
  2. Improve ort-web's vcpkg build scripts.

The generate_vcpkg_triplets_for_emscripten function in tools\python\util\vcpkg_helpers.py didn't process the enable_rtti condition. So, when it is true, we should add -fno-rtti to cxxflags

Fix an issue related to DISABLE_EXCEPTION_CATCHING. Make it clear that there are three modes:

  1. No EH (-fno-exceptions, -sDISABLE_EXCEPTION_CATCHING=1):
    Set enable_minimal_onnx_build=True, enable_wasm_exception_catching=False
  2. Full EH (-fexceptions, -sDISABLE_EXCEPTION_CATCHING=0):
    Set enable_minimal_onnx_build=False, enable_wasm_exception_catching=True
  3. Throw Only EH (-fexceptions, -sDISABLE_EXCEPTION_CATCHING=1):
    Set enable_minimal_onnx_build=False, enable_wasm_exception_catching=False

Debug build should only use the second one.
In release build by default emscripten disables catching C++ exceptions (specifically, emitting catch blocks). That's the second case. In a normal release build(what we ship),

  • Usually enable_wasm_api_exception_catching is set to true
  • So disable_wasm_exception_catching is also True
  • So onnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_CATCHING is False
  • So, the flag DISABLE_EXCEPTION_CATCHING should not be set. Because by default it is true. We should not have "-sDISABLE_EXCEPTION_CATCHING=0"

But we do not want to rely on what default value is. So the vcpkg_helper.py script still explicitly set DISABLE_EXCEPTION_CATCHING to 1.

In onnxruntime_webassembly.cmake currently we have

  if (NOT onnxruntime_ENABLE_WEBASSEMBLY_MEMORY64)
    target_link_options(onnxruntime_webassembly PRIVATE "SHELL:-s DISABLE_EXCEPTION_THROWING=0")
  endif()

But I think we need to set DISABLE_EXCEPTION_THROWING to 1 when the build is in the first mode(No EH). This PR also resolves #24279 , because vcpkg has native support for cross-compiling. Users do not need to specific a custom protoc path.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

fs-eire added a commit that referenced this pull request Mar 26, 2025
### Description

There are slightly mismatch for the build flags for Web build pipeline
when using vcpkg.

A [fix](#24012) is on the
way but for now we need to disable vcpkg for the next patch release.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
amarin16 pushed a commit that referenced this pull request Mar 26, 2025
### Description

There are slightly mismatch for the build flags for Web build pipeline
when using vcpkg.

A [fix](#24012) is on the
way but for now we need to disable vcpkg for the next patch release.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
@snnn snnn requested a review from fs-eire April 8, 2025 01:09
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

@snnn snnn changed the title Fix an issue in wasm nortti build Fix an issue in wasm nortti build and add minimal build support for vcpkg Apr 8, 2025
@fs-eire
Copy link
Contributor

fs-eire commented Apr 10, 2025

Testing....

Testing Plan

  • build release wasm (no vcpkg)

    build --parallel --config Release --build_wasm --enable_wasm_simd --enable_wasm_threads --target onnxruntime_webassembly --skip_tests --enable_wasm_api_exception_catching --disable_rtti --build_dir C:\code\o2\build_wasm_inferencing

  • build release wasm JSEP (no vcpkg)

    build --parallel --config Release --build_wasm --enable_wasm_simd --enable_wasm_threads --target onnxruntime_webassembly --skip_tests --enable_wasm_api_exception_catching --disable_rtti --build_dir C:\code\o2\build_wasm_inferencing_jsep --use_jsep --use_webnn --target onnxruntime_webassembly

  • build release wasm (vcpkg)

    build --parallel --config Release --build_wasm --enable_wasm_simd --enable_wasm_threads --target onnxruntime_webassembly --skip_tests --enable_wasm_api_exception_catching --disable_rtti --build_dir C:\code\o2\build_wasm_inferencing_vcpkg --use_vcpkg

  • build release wasm JSEP (no vcpkg)

    build --parallel --config Release --build_wasm --enable_wasm_simd --enable_wasm_threads --target onnxruntime_webassembly --skip_tests --enable_wasm_api_exception_catching --disable_rtti --build_dir C:\code\o2\build_wasm_inferencing_jsep_vcpkg --use_jsep --use_webnn --target onnxruntime_webassembly --use_vcpkg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants