onnxruntime/cmake/onnxruntime_webassembly.cmake
Ye Wang 83dc22585c
Second round cherry-pick to rel-1.9.0 (#9062)
* Adding async fetching for webgl backend (#8951)

* Adding async fetching for webgl backend

* fix PR comments and CI failure.

* fixing a bug

* adding a flag

* Enable linking in exception throwing support library when build onnxruntime wasm. (#8973)

* Enable linking in exception throwing support library when build onnxruntime webassembly containing onnxruntime-extensions.

* Add flag in build.py to enable linking exceptions throwing library.

* Update onnxruntime-extensions document and bind custom_ops build flag with use_extensions.

* Update doc.

* Update cgmanifest.json.

Co-authored-by: Zuwei Zhao <zuzhao@microsoft.com>

* Remove document text from error message in a couple of ops (#9003)

* do not add pkg wheel entry to the index html file if it already exists (#9004)

* do not add pkg wheel entry to the index html file if it already exists

* [js/web] fix ort web e2e test (#9025)

* Fix cmake POWER10 detection

Recent commit 60c98a8 changed variable mlas_common_srcs which affects
POWER10 detection.

* Fix Where op type reduction processing (#9033)

* Update type reduction script to track Where Op's second input type.

* Clean up op_kernel_type_control.h includes.

* Use more maintainable include.

* Fix ROCm wheels CI pipeline break by installing latest protobuf from source (#9047)

* install protobuf from source

* fix rm command in Dockerfile

* fix options on rm command

* fix cd into protobuf source directory

* try again

* remove strip step

* debug list the files

* ls on /usr

* more debug

* more debug

* adjust LD_LIBRARY_PATH

* try remove protobuf before ORT build

* [js/web] a bugfix and add tests for wasm proxy worker (#9048)

* [js/web] add tests for wasm proxy worker

* fix script src override

* Set onnxruntime_DISABLE_RTTI to default OFF (#9049)

Co-authored-by: Du Li <duli1@microsoft.com>
Co-authored-by: Zuwei Zhao <4123666+Zuwei-Zhao@users.noreply.github.com>
Co-authored-by: Zuwei Zhao <zuzhao@microsoft.com>
Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com>
Co-authored-by: liqun Fu <liqfu@microsoft.com>
Co-authored-by: Yulong Wang <yulongw@microsoft.com>
Co-authored-by: Rajalakshmi Srinivasaraghavan <rajis@linux.ibm.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Co-authored-by: Suffian Khan <sukha@microsoft.com>
Co-authored-by: Changming Sun <chasun@microsoft.com>
2021-09-15 18:02:07 -07:00

85 lines
3.9 KiB
CMake

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
file(GLOB_RECURSE onnxruntime_webassembly_src CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/wasm/api.cc"
)
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_webassembly_src})
add_executable(onnxruntime_webassembly
${onnxruntime_webassembly_src}
)
if (NOT onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
add_compile_definitions(
MLAS_NO_ONNXRUNTIME_THREADPOOL
)
# Override re2 compiler options to remove -pthread
set_property(TARGET re2 PROPERTY COMPILE_OPTIONS )
endif()
target_compile_options(onnx PRIVATE -Wno-unused-parameter -Wno-unused-variable)
target_link_libraries(onnxruntime_webassembly PRIVATE
nsync_cpp
${PROTOBUF_LIB}
onnx
onnx_proto
onnxruntime_common
onnxruntime_flatbuffers
onnxruntime_framework
onnxruntime_graph
onnxruntime_mlas
onnxruntime_optimizer
onnxruntime_providers
onnxruntime_session
onnxruntime_util
re2::re2
)
set(EXTRA_EXPORTED_RUNTIME_METHODS "['stackAlloc','stackRestore','stackSave','UTF8ToString','stringToUTF8','lengthBytesUTF8']")
set_target_properties(onnxruntime_webassembly PROPERTIES LINK_FLAGS " \
-s \"EXTRA_EXPORTED_RUNTIME_METHODS=${EXTRA_EXPORTED_RUNTIME_METHODS}\" \
-s WASM=1 \
-s NO_EXIT_RUNTIME=0 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s EXPORT_ALL=0 \
-s LLD_REPORT_UNDEFINED \
-s VERBOSE=0 \
-s NO_FILESYSTEM=1 \
-s MALLOC=${onnxruntime_WEBASSEMBLY_MALLOC} \
--closure 1 \
--no-entry")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=1 -s DEMANGLE_SUPPORT=1")
else()
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s ASSERTIONS=0 -s SAFE_HEAP=0 -s STACK_OVERFLOW_CHECK=0 -s DEMANGLE_SUPPORT=0")
endif()
# Set link flag to enable exceptions support, this will override default disabling exception throwing behavior when disable exceptions.
if (onnxruntime_ENABLE_WEBASSEMBLY_EXCEPTION_THROWING)
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s DISABLE_EXCEPTION_THROWING=0")
endif()
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s EXPORT_NAME=ortWasmSimdThreaded -s USE_PTHREADS=1")
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME "ort-wasm-simd-threaded")
else()
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s EXPORT_NAME=ortWasmThreaded -s USE_PTHREADS=1")
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME "ort-wasm-threaded")
endif()
else()
if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s EXPORT_NAME=ortWasmSimd")
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME "ort-wasm-simd")
else()
set_property(TARGET onnxruntime_webassembly APPEND_STRING PROPERTY LINK_FLAGS " -s EXPORT_NAME=ortWasm")
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME "ort-wasm")
endif()
endif()