Skip to content
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

Create CMake option onnxruntime_USE_VCPKG #21348

Merged
merged 24 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d0e440b
build: support vcpkg in cmake-presets
luncliff Jul 13, 2024
c41c244
use `std::string` for `abseil::raw_hash_map` `find`
luncliff Jul 13, 2024
6223414
fix case mismatch
luncliff Jul 13, 2024
ff97583
use later version of vcpkg
luncliff Jul 13, 2024
fabe7d9
cmake: check option in CUDA provider file
luncliff Jul 13, 2024
4b8bc45
build.py: create --use_vcpkg option and workflow for Windows
luncliff Jul 20, 2024
36919b0
gh-actions: jobs for each vcpkg triplet
luncliff Jul 20, 2024
310aaa6
vcpkg: update manifest
luncliff Jul 21, 2024
6227f5f
cmake: try merge of onnxruntime_external_*.cmake
luncliff Jul 21, 2024
091ea11
python: apply lintrunner suggestions
luncliff Jul 23, 2024
ba5bb5c
ci: update vcpkg-configuration
luncliff Jul 23, 2024
e37f9d6
ci: use vcpkg installed flatc, protoc
luncliff Jul 23, 2024
68920d9
cmake: remove unused parts
luncliff Jul 24, 2024
d97ec19
cmake: use vcpkg 2024.07.12
luncliff Jul 24, 2024
bdee0a9
vcpkg: use abseil 20240722.rc1
luncliff Jul 27, 2024
b39343a
Merge branch 'main' into support/vcpkg
luncliff Jul 27, 2024
cc3bd14
cmake: correct library search in vcpkg
luncliff Aug 4, 2024
779ff2b
cmake: alias Boost::headers to Boost::mp11
luncliff Aug 4, 2024
47551f6
Merge branch 'main' into support/vcpkg
luncliff Aug 4, 2024
2889abf
vcpkg: use eigen3 from vcpkg-registry
luncliff Aug 5, 2024
52154c4
vcpkg: override eigen3 version
luncliff Aug 9, 2024
4faeeee
cmake: fix preset cacheVariables
luncliff Aug 5, 2024
dba1862
vcpkg: use 2024.08.23
luncliff Sep 10, 2024
a67dd2d
vcpkg: remove eigen3, onnx in manifest
luncliff Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,90 @@ jobs:
--use_xnnpack \
--use_binskim_compliant_compile_flags

Vcpkg:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}

- name: "Run vcpkg(x64-osx)"
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: "${{ runner.temp }}/vcpkg"
vcpkgGitCommitId: "1de2026f28ead93ff1773e6e680387643e914ea1" # 2024.07.12
runVcpkgInstall: true
vcpkgJsonGlob: "cmake/vcpkg.json"
vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json"
env:
VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build"
VCPKG_DEFAULT_TRIPLET: "x64-osx"
# VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching

- name: "Run compile_schema.py"
run: |
# Runner's host triplet should be x64-osx or arm64-osx
export FLATC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-osx/tools/flatbuffers"
export PATH="$FLATC_DIR:$PATH"
flatc --version
python onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc "$(which flatc)"

- name: "Detect protoc"
id: protoc-detect
run: |
export PROTOC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-osx/tools/protobuf"
export PATH="$PROTOC_DIR:$PATH"
protoc --version
echo "protoc_path=$(which protoc)" >> "$GITHUB_OUTPUT"

- name: "Run build.py(x64-osx)"
run: |
python ./tools/ci_build/build.py \
--build_dir "build/x64-osx" \
--skip_submodule_sync \
--skip_tests \
--compile_no_warning_as_error \
--parallel \
--path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" \
--osx_arch x86_64 \
--use_vcpkg \
--cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
--cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-osx" \
--cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" \
--cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests"
shell: bash

- name: "Run vcpkg(arm64-osx)"
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: "${{ runner.temp }}/vcpkg"
vcpkgGitCommitId: "1de2026f28ead93ff1773e6e680387643e914ea1" # 2024.07.12
runVcpkgInstall: true
vcpkgJsonGlob: "cmake/vcpkg.json"
vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json"
env:
VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build"
VCPKG_DEFAULT_TRIPLET: "arm64-osx"
# VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching

- name: "Run build.py(arm64-osx)"
run: |
python ./tools/ci_build/build.py \
--build_dir "build/arm64-osx" \
--skip_submodule_sync \
--skip_tests \
--compile_no_warning_as_error \
--parallel \
--path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" \
--osx_arch arm64 \
--use_vcpkg \
--cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
--cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-osx" \
--cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" \
--cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests"
shell: bash

Objective-C-StaticAnalysis:
runs-on: macos-14

Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,90 @@ jobs:
# The build machine doesn't have a GPU. So the value of CMAKE_CUDA_ARCHITECTURES doesn't matter.
- name: Build code
run: python tools\ci_build\build.py --windows_sdk_version 10.0.22621.0 --enable_training --build_java --config Debug --build_dir D:\b --skip_submodule_sync --build_csharp --update --build --parallel --cmake_generator "Visual Studio 17 2022" --build_shared_lib --enable_pybind --use_cuda --cuda_home=${{ github.workspace }}\cuda_sdk\v12.2 --enable_cuda_profiling --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=75

Vcpkg:
runs-on: "windows-latest"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11.x'
architecture: 'x64'

- name: "Run vcpkg(x64-windows)"
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: "C:/vcpkg" # use VCPKG_INSTALLATION_ROOT of the image
doNotUpdateVcpkg: true
runVcpkgInstall: true
vcpkgJsonGlob: "cmake/vcpkg.json"
vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json"
env:
VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build"
VCPKG_DEFAULT_TRIPLET: "x64-windows"
# VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching

- name: "Run compile_schema.py"
run: |
# Runner's host triplet should be x64-windows or arm64-windows
$FLATC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-windows/tools/flatbuffers"
$env:PATH="$FLATC_DIR;$env:PATH"
flatc --version
$FLATC_PATH = Join-Path "$FLATC_DIR" "flatc.exe"
python onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc "$FLATC_PATH"
shell: pwsh

- name: "Detect protoc"
id: protoc-detect
run: |
$PROTOC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-windows/tools/protobuf"
$env:PATH="$PROTOC_DIR;$env:PATH"
protoc --version
$PROTOC_PATH = Join-Path "$PROTOC_DIR" "protoc.exe"
"protoc_path=$PROTOC_PATH" >> $env:GITHUB_OUTPUT
shell: pwsh

- name: "Run build.py(x64-windows)"
run: |
python tools\ci_build\build.py `
--build_dir "cmake_build/x64-windows" `
--skip_submodule_sync `
--skip_tests `
--compile_no_warning_as_error `
--parallel `
--path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" `
--use_vcpkg `
--cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
--cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-windows" `
--cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" `
--cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests"
shell: pwsh

- name: "Run vcpkg(arm64-windows)"
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: "C:/vcpkg" # use VCPKG_INSTALLATION_ROOT of the image
doNotUpdateVcpkg: true
runVcpkgInstall: true
vcpkgJsonGlob: "cmake/vcpkg.json"
vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json"
env:
VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build"
VCPKG_DEFAULT_TRIPLET: "arm64-windows"
# VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching

- name: "Run build.py(arm64-windows)"
run: |
python tools\ci_build\build.py `
--build_dir "cmake_build/arm64-windows" --arm64 `
--skip_submodule_sync `
--skip_tests `
--compile_no_warning_as_error `
--parallel `
--path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" `
--use_vcpkg `
--cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
--cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-windows" `
--cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" `
--cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests"
shell: pwsh
3 changes: 3 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include(CheckLanguage)
include(CMakeDependentOption)
include(FetchContent)
include(CheckFunctionExists)
include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables

# TODO: update this once all system adapt c++20
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand Down Expand Up @@ -69,6 +70,7 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_
endif()

# Options
option(onnxruntime_USE_VCPKG "Build with the vcpkg package manager" OFF)
option(onnxruntime_RUN_ONNX_TESTS "Enable ONNX Compatibility Testing" OFF)
option(onnxruntime_GENERATE_TEST_REPORTS "Enable test report generation" OFF)
option(onnxruntime_ENABLE_STATIC_ANALYSIS "Enable static analysis" OFF)
Expand Down Expand Up @@ -595,6 +597,7 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE)
get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE)
set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external)
include(external/onnxruntime_external_deps.cmake)

set(ORT_WARNING_FLAGS)
Expand Down
192 changes: 192 additions & 0 deletions cmake/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "vcpkg-manifest",
"hidden": true,
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"VCPKG_INSTALLED_DIR": "${sourceParentDir}/.build"
},
"environment": {
"VCPKG_FEATURE_FLGAS": "manifests,versions"
}
},
{
"name": "msvc-static-runtime",
"hidden": true,
"cacheVariables": {
"ONNX_USE_MSVC_STATIC_RUNTIME": true,
"protobuf_MSVC_STATIC_RUNTIME": true,
"gtest_force_shared_crt": false,
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>"
}
},
{
"name": "unit-test",
"hidden": true,
"cacheVariables": {
"onnxruntime_RUN_ONNX_TESTS": true,
"onnxruntime_BUILD_BENCHMARKS": true,
"onnxruntime_BUILD_UNIT_TESTS": true,
"onnxruntime_GENERATE_TEST_REPORTS": true
}
},
{
"name": "x64-windows",
"inherits": [
"msvc-static-runtime",
"unit-test"
],
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"binaryDir": "${sourceParentDir}/cmake_build/x64-windows",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"onnxruntime_USE_XNNPACK": true,
"onnxruntime_USE_DML": true,
"onnxruntime_BUILD_SHARED_LIB": true,
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-msvc-x64"
}
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-windows-vcpkg",
"inherits": [
"unit-test",
"vcpkg-manifest"
],
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"binaryDir": "${sourceParentDir}/cmake_build/x64-windows",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"onnxruntime_USE_VCPKG": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_DML": false,
"onnxruntime_BUILD_SHARED_LIB": true,
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
"VCPKG_INSTALL_OPTIONS": "--x-feature=tests",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
},
{
"name": "x64-osx",
"inherits": [
"unit-test"
],
"generator": "Xcode",
"binaryDir": "${sourceParentDir}/cmake_build/x64-osx",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "x86_64",
"onnxruntime_BUILD_SHARED_LIB": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_COREML": true,
"onnxruntime_BUILD_OBJC": true,
"onnxruntime_BUILD_APPLE_FRAMEWORK": true,
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "x64-osx-vcpkg",
"inherits": [
"x64-osx",
"vcpkg-manifest"
],
"cacheVariables": {
"onnxruntime_USE_VCPKG": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_COREML": false,
"onnxruntime_BUILD_OBJC": false,
"onnxruntime_BUILD_APPLE_FRAMEWORK": false,
"VCPKG_INSTALL_OPTIONS": "--x-feature=tests",
"VCPKG_TARGET_TRIPLET": "x64-osx"
}
}
],
"buildPresets": [
{
"name": "x64-windows-debug",
"configurePreset": "x64-windows",
"configuration": "Debug"
},
{
"name": "x64-windows-vcpkg-debug",
"configurePreset": "x64-windows-vcpkg",
"configuration": "Debug"
},
{
"name": "x64-osx-debug",
"configurePreset": "x64-osx",
"configuration": "Debug"
},
{
"name": "x64-osx-vcpkg-debug",
"configurePreset": "x64-osx-vcpkg",
"configuration": "Debug"
}
],
"testPresets": [
{
"name": "x64-windows-debug",
"configurePreset": "x64-windows",
"configuration": "Debug",
"output": {
"verbosity": "default",
"outputJUnitFile": "TEST-x64-windows-debug.xml",
"outputLogFile": "TEST-x64-windows-debug.log",
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "x64-windows-vcpkg-debug",
"inherits": "x64-windows-debug",
"configurePreset": "x64-windows-vcpkg"
},
{
"name": "x64-osx-debug",
"configurePreset": "x64-osx",
"configuration": "Debug",
"output": {
"verbosity": "default",
"outputJUnitFile": "TEST-x64-osx-debug.xml",
"outputLogFile": "TEST-x64-osx-debug.log",
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "x64-osx-vcpkg-debug",
"inherits": "x64-osx-debug",
"configurePreset": "x64-osx-vcpkg"
}
]
}
Loading
Loading