Skip to content

Commit 1cd7981

Browse files
author
Changming Sun
authored
VCPKG improvements (#23688)
### Description 1. Enabling wasm build. 2. Because the above, I need to delete all the existing vcpkg triplet files and use build.py to generate on-the-fly. 3. Updated onnx vcpkg port, to align with the latest changes in the upstream vcpkg repo. 4. Disabling downloading protoc when onnxruntime_USE_VCPKG is true. 5. Added "-e SYSTEM_COLLECTIONURI" to all "docker run " commands, so that in the docker instance I can use this information to determine if the build is running in an ONNX Runtime's team ADO project. 6. Disable vcpkg asset caching if the build is not running in an ONNX Runtime's team ADO project. 7. Add coreml-ep and dml-ep as ONNX Runtime package's features to "cmake/vcpkg.json" 8. Add VCPKG to tools/ci_build/github/linux/docker/migraphx-ci-pipeline-env.Dockerfile , which is used by MIGRAPHX CI build pipeline. ### Motivation and Context This PR appears large because there were a lot of generated vcpkg triplet files checked in to this repo. This PR deletes them. Here are the reasons: The official vcpkg repository has about 80 different triplets. But ONNX Runtime has many more build variants. For example, in general, for each platform, we need to support builds with C++ exceptions, builds without C++ exceptions, builds with C++ RTTI, builds without C++ RTTI, linking to static C++ runtime, linking to dynamic (shared) C++ runtime, builds with address sanitizer, builds without address sanitizer, etc. Therefore, a script file was created to dynamically generate the triplet files on-the-fly. Originally, we tried to check in all the generated files into our repository so that people could build onnxruntime without using build.py or any other Python scripts in the "/tools" directory. However, we encountered an issue when adding support for WASM builds. VCPKG has a limitation that when doing cross-compiling, the triplet file must specify the full path of the chain-loaded toolchain file. The file needs to be located either via environment variables (like ANDROID_NDK_HOME) or via an absolute path. Since environment variables are hard to track, we chose the latter approach. So the generated triplet files may contain absolute file paths that are only valid on the current build machine.
1 parent d07ea64 commit 1cd7981

File tree

194 files changed

+1089
-4258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+1089
-4258
lines changed

cmake/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ else()
794794
endif()
795795
if (HAS_DEPRECATED_ANON_ENUM_ENUM_CONVERSION)
796796
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-anon-enum-enum-conversion)
797+
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-enum-enum-conversion)
797798
endif()
798799
if (HAS_UNDEFINED_VAR_TEMPLATE)
799800
list(APPEND ORT_WARNING_FLAGS -Wno-undefined-var-template)
@@ -1085,6 +1086,16 @@ function(onnxruntime_set_compile_flags target_name)
10851086
endif()
10861087
if(onnxruntime_ENABLE_LAZY_TENSOR)
10871088
target_compile_definitions(${target_name} PRIVATE ENABLE_LAZY_TENSOR)
1089+
endif()
1090+
# Enable stream for all the non-minimal build
1091+
if (NOT onnxruntime_MINIMAL_BUILD)
1092+
target_compile_definitions(${target_name} PRIVATE ORT_ENABLE_STREAM)
1093+
endif()
1094+
if (onnxruntime_REDUCED_OPS_BUILD)
1095+
target_compile_definitions(${target_name} PRIVATE REDUCED_OPS_BUILD)
1096+
endif()
1097+
if (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS)
1098+
target_compile_definitions(${target_name} PRIVATE DISABLE_EXTERNAL_INITIALIZERS)
10881099
endif()
10891100
if (onnxruntime_ENABLE_CPU_FP16_OPS)
10901101
target_compile_definitions(${target_name} PRIVATE ENABLE_CPU_FP16_TRAINING_OPS)

cmake/adjust_global_compile_flags.cmake

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
# work around Android NDK bug which doesn't include -O flag for Release configuration
2-
# https://github.com/android/ndk/issues/1740
3-
# TODO: remove this when the NDK version(s) we support get fixed
4-
if (ANDROID)
5-
# NB: attempting to match the effects of this fix: https://android-review.googlesource.com/c/platform/ndk/+/2168845
6-
string(APPEND CMAKE_C_FLAGS_RELEASE " -O3")
7-
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3")
8-
string(APPEND CMAKE_ASM_FLAGS_RELEASE " -O3")
1+
# The flags set by this file are applied to 3rd-party libraries(e.g. protobuf) as well. If you want to set something that is only for ORT's code, please put it in the main CMakeLists.txt file.
92

3+
if (ANDROID)
104
# Build shared libraries with support for 16 KB ELF alignment
115
# https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment
126
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
@@ -101,11 +95,6 @@ if (onnxruntime_MINIMAL_BUILD)
10195
endif()
10296
endif()
10397

104-
# Enable stream for all the non-minimal build
105-
if (NOT onnxruntime_MINIMAL_BUILD)
106-
add_compile_definitions(ORT_ENABLE_STREAM)
107-
endif()
108-
10998
if (onnxruntime_ENABLE_LTO)
11099
include(CheckIPOSupported)
111100
check_ipo_supported(RESULT ipo_enabled OUTPUT ipo_output)
@@ -117,14 +106,6 @@ if (onnxruntime_ENABLE_LTO)
117106
endif()
118107
endif()
119108

120-
if (onnxruntime_REDUCED_OPS_BUILD)
121-
add_compile_definitions(REDUCED_OPS_BUILD)
122-
endif()
123-
124-
if (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS)
125-
add_definitions(-DDISABLE_EXTERNAL_INITIALIZERS=1)
126-
endif()
127-
128109
if (onnxruntime_DISABLE_RTTI)
129110
add_compile_definitions(ORT_NO_RTTI)
130111
if (MSVC)
@@ -160,6 +141,7 @@ if (onnxruntime_DISABLE_EXCEPTIONS)
160141
add_compile_definitions("ORT_NO_EXCEPTIONS")
161142
add_compile_definitions("MLAS_NO_EXCEPTION")
162143
add_compile_definitions("ONNX_NO_EXCEPTIONS")
144+
# The following line of code probably is not needed because the same effect can be achieved by setting the compiler flag -fno-exceptions.
163145
add_compile_definitions("JSON_NOEXCEPTION") # https://json.nlohmann.me/api/macros/json_noexception/
164146

165147
if (MSVC)
@@ -196,14 +178,6 @@ if (onnxruntime_CROSS_COMPILING)
196178
endif()
197179
endif()
198180

199-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
200-
check_cxx_compiler_flag(-Wno-error HAS_NOERROR)
201-
if (HAS_NOERROR)
202-
string(APPEND CMAKE_CXX_FLAGS " -Wno-error=attributes")
203-
string(APPEND CMAKE_C_FLAGS " -Wno-error=attributes")
204-
endif()
205-
endif()
206-
207181
# Mark symbols to be invisible, for macOS/iOS/visionOS target only
208182
# Due to many dependencies have different symbol visibility settings, set global compile flags here.
209183
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS")
@@ -253,7 +227,6 @@ if (MSVC)
253227
message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
254228
endif()
255229

256-
257230
#Always enable exception handling, even for Windows ARM
258231
if (NOT onnxruntime_DISABLE_EXCEPTIONS)
259232
string(APPEND CMAKE_CXX_FLAGS " /EHsc")
@@ -326,9 +299,6 @@ else()
326299
string(APPEND CMAKE_C_FLAGS " -g -O0 --coverage ")
327300
endif()
328301
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
329-
# suppress warnings from flatbuffers
330-
string(APPEND CMAKE_CXX_FLAGS " -Wno-restrict ")
331-
string(APPEND CMAKE_C_FLAGS " -Wno-restrict ")
332302
if(onnxruntime_USE_XNNPACK)
333303
# https://github.com/google/XNNPACK/issues/7650
334304
string(APPEND CMAKE_C_FLAGS " -Wno-incompatible-pointer-types ")

cmake/external/dml.cmake

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,17 @@ else()
100100
endif()
101101
endif()
102102

103-
onnxruntime_fetchcontent_declare(
103+
if (onnxruntime_USE_VCPKG)
104+
find_package(directx-headers CONFIG REQUIRED)
105+
else()
106+
onnxruntime_fetchcontent_declare(
104107
directx_headers
105108
URL ${DEP_URL_directx_headers}
106109
URL_HASH SHA1=${DEP_SHA1_directx_headers}
107110
EXCLUDE_FROM_ALL
108-
)
109-
110-
FetchContent_Populate(directx_headers)
111-
set(directx_headers_INCLUDE_DIRS "${directx_headers_SOURCE_DIR}/include")
111+
)
112112

113-
include_directories(BEFORE ${directx_headers_INCLUDE_DIRS})
113+
FetchContent_Populate(directx_headers)
114+
set(directx_headers_INCLUDE_DIRS "${directx_headers_SOURCE_DIR}/include")
115+
include_directories(BEFORE ${directx_headers_INCLUDE_DIRS})
116+
endif()

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ onnxruntime_fetchcontent_makeavailable(utf8_range)
125125
include_directories(${utf8_range_SOURCE_DIR})
126126

127127
# Download a protoc binary from Internet if needed
128-
if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE)
128+
if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE AND NOT onnxruntime_USE_VCPKG)
129129
# This part of code is only for users' convenience. The code couldn't handle all cases. Users always can manually
130130
# download protoc from Protobuf's Github release page and pass the local path to the ONNX_CUSTOM_PROTOC_EXECUTABLE
131131
# variable.
@@ -292,20 +292,22 @@ onnxruntime_fetchcontent_declare(
292292
)
293293
onnxruntime_fetchcontent_makeavailable(date)
294294

295-
onnxruntime_fetchcontent_declare(
296-
mp11
297-
URL ${DEP_URL_mp11}
298-
URL_HASH SHA1=${DEP_SHA1_mp11}
299-
EXCLUDE_FROM_ALL
300-
FIND_PACKAGE_ARGS NAMES Boost
301-
)
302-
onnxruntime_fetchcontent_makeavailable(mp11)
303295
if(NOT TARGET Boost::mp11)
304296
if(onnxruntime_USE_VCPKG)
305-
find_package(Boost REQUIRED)
297+
find_package(Boost REQUIRED)
298+
message(STATUS "Aliasing Boost::headers to Boost::mp11")
299+
add_library(Boost::mp11 ALIAS Boost::headers)
300+
else()
301+
onnxruntime_fetchcontent_declare(
302+
mp11
303+
URL ${DEP_URL_mp11}
304+
FIND_PACKAGE_ARGS NAMES Boost
305+
)
306+
onnxruntime_fetchcontent_makeavailable(mp11)
307+
if(NOT TARGET Boost::mp11)
308+
add_library(Boost::mp11 ALIAS Boost::headers)
309+
endif()
306310
endif()
307-
message(STATUS "Aliasing Boost::headers to Boost::mp11")
308-
add_library(Boost::mp11 ALIAS Boost::headers)
309311
endif()
310312

311313
set(JSON_BuildTests OFF CACHE INTERNAL "")
@@ -626,35 +628,10 @@ endif()
626628

627629

628630
if (onnxruntime_USE_WEBGPU)
629-
if (onnxruntime_CUSTOM_DAWN_SRC_PATH)
630-
# use the custom dawn source path if provided
631-
#
632-
# specified as:
633-
# build.py --use_webgpu --cmake_extra_defines "onnxruntime_CUSTOM_DAWN_SRC_PATH=<PATH_TO_DAWN_SRC_ROOT>"
634-
onnxruntime_fetchcontent_declare(
635-
dawn
636-
SOURCE_DIR ${onnxruntime_CUSTOM_DAWN_SRC_PATH}
637-
EXCLUDE_FROM_ALL
638-
)
639-
else()
640-
onnxruntime_fetchcontent_declare(
641-
dawn
642-
URL ${DEP_URL_dawn}
643-
URL_HASH SHA1=${DEP_SHA1_dawn}
644-
# # All previous patches are merged into the upstream dawn project. We don't need to apply any patches right now.
645-
# # if we need to apply patches in the future, we can uncomment the following line.
646-
#
647-
# The dawn.patch contains the following changes:
648-
# - https://dawn-review.googlesource.com/c/dawn/+/225514
649-
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn.patch
650-
EXCLUDE_FROM_ALL
651-
)
652-
endif()
653-
654631
set(DAWN_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
655632
set(DAWN_ENABLE_NULL OFF CACHE BOOL "" FORCE)
656633
set(DAWN_FETCH_DEPENDENCIES ON CACHE BOOL "" FORCE)
657-
634+
set(DAWN_BUILD_TESTS OFF CACHE BOOL "" FORCE)
658635
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
659636
set(DAWN_EMSCRIPTEN_TOOLCHAIN "${REPO_ROOT}/cmake/external/emsdk/upstream/emscripten" CACHE STRING "" FORCE)
660637
else()
@@ -732,6 +709,30 @@ if (onnxruntime_USE_WEBGPU)
732709
set(DAWN_ENABLE_D3D11 OFF CACHE BOOL "" FORCE)
733710
endif()
734711
endif()
712+
if (onnxruntime_CUSTOM_DAWN_SRC_PATH)
713+
# use the custom dawn source path if provided
714+
#
715+
# specified as:
716+
# build.py --use_webgpu --cmake_extra_defines "onnxruntime_CUSTOM_DAWN_SRC_PATH=<PATH_TO_DAWN_SRC_ROOT>"
717+
onnxruntime_fetchcontent_declare(
718+
dawn
719+
SOURCE_DIR ${onnxruntime_CUSTOM_DAWN_SRC_PATH}
720+
EXCLUDE_FROM_ALL
721+
)
722+
else()
723+
onnxruntime_fetchcontent_declare(
724+
dawn
725+
URL ${DEP_URL_dawn}
726+
URL_HASH SHA1=${DEP_SHA1_dawn}
727+
# # All previous patches are merged into the upstream dawn project. We don't need to apply any patches right now.
728+
# # if we need to apply patches in the future, we can uncomment the following line.
729+
#
730+
# The dawn.patch contains the following changes:
731+
# - https://dawn-review.googlesource.com/c/dawn/+/225514
732+
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn.patch
733+
EXCLUDE_FROM_ALL
734+
)
735+
endif()
735736

736737
onnxruntime_fetchcontent_makeavailable(dawn)
737738

@@ -747,7 +748,7 @@ if (onnxruntime_USE_WEBGPU)
747748
endif()
748749

749750
if (onnxruntime_ENABLE_PIX_FOR_WEBGPU_EP)
750-
list(APPEND onnxruntime_EXTERNAL_LIBRARIES glfw webgpu_glfw)
751+
list(APPEND onnxruntime_EXTERNAL_LIBRARIES webgpu_glfw glfw)
751752
endif()
752753
endif()
753754

cmake/onnxruntime_providers_coreml.cmake

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ elseif(TARGET nlohmann_json::nlohmann_json)
169169
endif()
170170

171171
if(fp16_SOURCE_DIR)
172-
target_include_directories(onnxruntime_providers_coreml PRIVATE ${fp16_SOURCE_DIR}/include)
172+
set(FP16_INCLUDE_DIRS ${fp16_SOURCE_DIR}/include)
173173
else()
174-
message(FATAL_ERROR "Cannot find fp16's source code")
174+
find_path(FP16_INCLUDE_DIRS "fp16.h")
175175
endif()
176+
target_include_directories(onnxruntime_providers_coreml PRIVATE ${FP16_INCLUDE_DIRS})
176177

177178
onnxruntime_add_include_to_target(onnxruntime_providers_coreml coreml_proto)
178179
target_link_libraries(onnxruntime_providers_coreml PRIVATE coreml_proto)
@@ -184,26 +185,16 @@ endif()
184185

185186

186187

187-
# need to tweak the include paths to match what the coreml source code expects
188-
target_include_directories(onnxruntime_providers_coreml PRIVATE
188+
# need to tweak the include paths to match what the coreml source code expects
189+
target_include_directories(onnxruntime_providers_coreml PRIVATE
189190
${coremltools_SOURCE_DIR}
190191
${coremltools_SOURCE_DIR}/mlmodel/src/
191192
${coremltools_SOURCE_DIR}/modelpackage/src/
192-
)
193-
194-
# need to tweak the include paths to match what the coreml source code expects
195-
target_include_directories(onnxruntime_providers_coreml PRIVATE
196-
${fp16_SOURCE_DIR}/include
197-
${nlohmann_json_SOURCE_DIR}/single_include/nlohmann
198-
${coremltools_SOURCE_DIR}
199-
${coremltools_SOURCE_DIR}/mlmodel/src/
200-
${coremltools_SOURCE_DIR}/modelpackage/src/
201193
)
202194

203-
204-
if (LINUX)
205-
target_link_libraries(onnxruntime_providers_coreml PRIVATE uuid)
206-
endif()
195+
if (LINUX)
196+
target_link_libraries(onnxruntime_providers_coreml PRIVATE uuid)
197+
endif()
207198

208199

209200

cmake/onnxruntime_providers_dml.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
onnxruntime_add_include_to_target(onnxruntime_providers_dml
1212
onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers Boost::mp11 safeint_interface ${WIL_TARGET}
1313
)
14+
if(TARGET Microsoft::DirectX-Headers)
15+
onnxruntime_add_include_to_target(onnxruntime_providers_dml Microsoft::DirectX-Headers)
16+
endif()
1417
add_dependencies(onnxruntime_providers_dml ${onnxruntime_EXTERNAL_DEPENDENCIES})
1518
target_include_directories(onnxruntime_providers_dml PRIVATE
1619
${ONNXRUNTIME_ROOT}

cmake/onnxruntime_webassembly.cmake

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ if (NOT onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
9393
set_property(TARGET re2 PROPERTY COMPILE_OPTIONS )
9494
endif()
9595

96-
target_compile_options(onnx PRIVATE -Wno-unused-parameter -Wno-unused-variable)
96+
if (NOT onnxruntime_USE_VCPKG)
97+
target_compile_options(onnx PRIVATE -Wno-unused-parameter -Wno-unused-variable)
98+
endif()
9799

98100
if (onnxruntime_BUILD_WEBASSEMBLY_STATIC_LIB)
99101
bundle_static_library(onnxruntime_webassembly
@@ -404,14 +406,21 @@ jsepDownload:_pp_")
404406
endif()
405407

406408
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
407-
target_link_options(onnxruntime_webassembly PRIVATE
408-
# NOTE: use "SHELL:-s ASSERTIONS=2" to enable more strict assertions, which may help debugging segfaults.
409-
# However, it may be very slow.
410-
# "SHELL:-s ASSERTIONS=2"
411-
"SHELL:-s ASSERTIONS=1"
412-
"SHELL:-s SAFE_HEAP=1"
413-
"SHELL:-s STACK_OVERFLOW_CHECK=2"
414-
)
409+
if (CMAKE_CXX_FLAGS MATCHES "sanitize=address")
410+
# The integer value below might often need be adjusted.
411+
target_link_options(onnxruntime_webassembly PRIVATE "-sINITIAL_MEMORY=786432000")
412+
target_link_options(onnxruntime_webassembly PRIVATE "-sASSERTIONS=2")
413+
else()
414+
# Enable SAFE_HEAP in debug build
415+
target_link_options(onnxruntime_webassembly PRIVATE
416+
# NOTE: use "SHELL:-s ASSERTIONS=2" to enable more strict assertions, which may help debugging segfaults.
417+
# However, it may be very slow.
418+
# "SHELL:-s ASSERTIONS=2"
419+
"SHELL:-s ASSERTIONS=1"
420+
"SHELL:-s SAFE_HEAP=1"
421+
"SHELL:-s STACK_OVERFLOW_CHECK=2"
422+
)
423+
endif()
415424
else()
416425
target_link_options(onnxruntime_webassembly PRIVATE
417426
"SHELL:-s ASSERTIONS=0"

cmake/vcpkg-configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"default-registry": {
33
"kind": "git",
44
"repository": "https://github.com/Microsoft/vcpkg",
5-
"baseline": "d504de05dcd7b55df34976be1c824324ec6bca2b"
5+
"baseline": "a29711cc86340a43c054cd37b8bd2871332a01e9"
66
},
77
"overlay-ports": [
88
"./vcpkg-ports"
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index d15d97ed..a483255f 100644
2+
index d15d97ed..fe4bd27f 100644
33
--- a/CMakeLists.txt
44
+++ b/CMakeLists.txt
5-
@@ -496,6 +496,7 @@ if (MSVC)
6-
endif()
7-
else()
8-
# On non-Windows, hide all symbols we don't need
9-
+ set(EXTRA_FLAGS "-Wno-unused-parameter")
10-
set(ONNX_API_DEFINE "-DONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
11-
set_target_properties(onnx_proto PROPERTIES CXX_VISIBILITY_PRESET hidden)
12-
set_target_properties(onnx_proto PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
13-
@@ -631,20 +632,9 @@ endif()
5+
@@ -631,20 +631,9 @@ endif()
146
if(MSVC)
157
target_compile_options(onnx_proto
168
PRIVATE /MP

0 commit comments

Comments
 (0)