Skip to content

Create CMake option onnxruntime_USE_VCPKG - #21348

Merged
snnn merged 24 commits into
microsoft:mainfrom
luncliff:support/vcpkg
Sep 10, 2024
Merged

Create CMake option onnxruntime_USE_VCPKG#21348
snnn merged 24 commits into
microsoft:mainfrom
luncliff:support/vcpkg

Conversation

@luncliff

@luncliff luncliff commented Jul 13, 2024

Copy link
Copy Markdown
Contributor

Changes

  1. CMake option onnxruntime_USE_VCPKG. It will be used in the vcpkg port
    • Unit test may fail because this option leads to a mixture of unexpected external library versions.
      Especially ONNX, Protobuf, and Flatbuffers version can be different
  2. Overhaul of onnxruntime_external_deps.cmake
    • Make FetchContent_Declare to try find_package.
      See https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html
    • Relocated FetchContent_Declare and FetchContent_MakeAvailable(or onnxruntime_fetchcontent_makeavailable) to closer lines.
      It was too hard to navigate the entire file to search related sections...
    • Alias IMPORTED targets like build targets (e.g. ONNX::onnx --> onnx)
# The script uses `find_package` with the changes.
# In this case, use vcpkg to search dependencies
# See https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html
include(external/onnxruntime_external_deps.cmake)
  1. Create CMakePresets.json and presets to run vcpkg in manifest mode
    • Currently, it's NOT for training build
    • Main triplets are x64-windows and x64-osx
Push-Location "cmake"
    cmake --preset "x64-windows-vcpkg"
    cmake --build --preset "x64-windows-vcpkg-debug"
Pop-Location
pushd "cmake"
    cmake --preset "x64-osx-vcpkg"
    cmake --build --preset "x64-osx-vcpkg-debug"
popd
  1. Updated tools/ci_build/build.py
    • --use_vcpkg option: it needs CMAKE_TOOLCHAIN_FILE with vcpkg.cmake toolchain script
    • --compile_no_warning_as_error is recommended because library version differences will cause unexpected compiler warnings
python ./tools/ci_build/build.py \
    --compile_no_warning_as_error \
    --use_vcpkg \
    --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
    --cmake_extra_defines "VCPKG_TARGET_TRIPLET=..."
  1. Created Job Vcpkg for Windows and macOS
    • Show how to setup and use vcpkg.
      Similar to the CMakePresets.json usage

Motivation and Context

Future Works?

More feature coverage with the vcpkg supported libraries

  • CUDA feature support
  • Training feature support

@luncliff
luncliff marked this pull request as draft July 13, 2024 18:15
@luncliff luncliff changed the title Create files and CMake option to support vcpkg and CMakePresets.json to test it Create files and CMake option to support vcpkg Jul 13, 2024
@snnn

snnn commented Jul 15, 2024

Copy link
Copy Markdown
Contributor

I think cmake is a great choice.
Which cmake triplet this PR is going to support?

Besides, we might decouple the work. You may create a vcpkg config file, then install all the packages via "vcpkg install", then let cmake search installed packages there when running ONNX Runtime's build.py script. Then in theory you don't need to modify any ONNX Runtime's cmake file. No matter which way you choose to go, we always greatly appreciate your contribution.

@luncliff

Copy link
Copy Markdown
Contributor Author

36919b0 New GitHub Actions jobs for vcpkg build

6227f5f Trying to merge onnxruntime_vcpkg_deps.cmake into onnxruntime_external_deps.cmake using FIND_PACKAGE_ARGS .
Currently I have some problems with pb.h,pb.cc generation

Comment thread cmake/vcpkg-configuration.json Outdated
luncliff added 3 commits July 24, 2024 22:44
* Detect protoc path for build.py
* Run vcpkg for each build.py run

Reorganized vcpkg install folder and CMake build directory
@luncliff luncliff changed the title Create files and CMake option to support vcpkg Create CMake option onnxruntime_USE_VCPKG Jul 24, 2024
* CUDA build will be tried next time...
* Remove onnxruntime_vcpkg_deps.cmake
@luncliff
luncliff marked this pull request as ready for review July 24, 2024 17:56
@luncliff
luncliff requested a review from a team July 24, 2024 17:56
@luncliff

Copy link
Copy Markdown
Contributor Author

Updated note and title.

Dropped CUDA feature support in this PR.
I felt like making too huge changes here. I would make another PR for other features

* add dropped changes
@snnn

snnn commented Jul 24, 2024

Copy link
Copy Markdown
Contributor

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline

@snnn

snnn commented Jul 24, 2024

Copy link
Copy Markdown
Contributor

/azp run Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 9 pipeline(s).

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 9 pipeline(s).

@snnn

snnn commented Jul 24, 2024

Copy link
Copy Markdown
Contributor

We probably need to wait for the next absl release.

@luncliff

Copy link
Copy Markdown
Contributor Author

absl::demangle_rust was not intended one. I saw absl::demangle_internal in my fork, but not the one in the log. I will check again

@luncliff
luncliff marked this pull request as draft July 24, 2024 18:37
* cmake: use eigen from FetchContent
* ONNX will be used with FetchContent
  Current vcpkg upstream doesn't support onnx 1.16.0+.
  Here, we will mix FetchContent and vcpkg-supported find_package
Comment thread cmake/vcpkg-configuration.json
@snnn

snnn commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn

snnn commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline

1 similar comment
@snnn

snnn commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 7 pipeline(s).

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 7 pipeline(s).

@snnn

snnn commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

/azp run Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 7 pipeline(s).

@snnn
snnn merged commit f633caa into microsoft:main Sep 10, 2024
@snnn

snnn commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

Thank you!

@luncliff

Copy link
Copy Markdown
Contributor Author

Thank you, @snnn. I will submit another PR if microsoft/vcpkg needs it.

@luncliff
luncliff deleted the support/vcpkg branch September 11, 2024 01:11
snnn pushed a commit that referenced this pull request Jan 8, 2025
### Description

Changes vcpkg manifest and configuration file (vcpkg.json &
vcpkg-configuration.json)

* Update vcpkg version to
https://github.com/microsoft/vcpkg/releases/tag/2024.12.16
* Use protobuf 3.21.12(= `v21.12`) to sync with
[cmake/deps.txt](https://github.com/microsoft/onnxruntime/blob/main/cmake/deps.txt)
  * Resolve #22750
* Add `onnx` to vcpkg manifest so `find_package(ONNX)` and
`find_dependency(Protobuf)` can work as expected.
  * Currently, It uses 1.16.2
* v1.17.0 will become available after
microsoft/vcpkg#42942

However, `onnx` in vcpkg doesn't configure
`ONNX_DISABLE_STATIC_REGISTRATION` build option.

* microsoft/vcpkg#38879
* Create "cmake/vcpkg-triplets/" folder and triplet files which use
`VCPKG_CMAKE_CONFIGURE_OPTIONS` for the option
* This requires `VCPKG_OVERLAY_TRIPLETS` environment variable for CI
steps, which is a bit inconvenient.
     I will try to find simple way to get same result

### Motivation and Context

* Help #23158 
  * "ONNX is not consumed from vcpkg"
* "Mismatch protobuf version. When vcpkg is enabled , we should not
fetch protoc from Github which may cause version mismatches."
* microsoft/vcpkg#43126
* #21348
snnn pushed a commit that referenced this pull request Jan 8, 2025
### Description

Changes vcpkg manifest and configuration file (vcpkg.json &
vcpkg-configuration.json)

* Update vcpkg version to
https://github.com/microsoft/vcpkg/releases/tag/2024.12.16
* Use protobuf 3.21.12(= `v21.12`) to sync with
[cmake/deps.txt](https://github.com/microsoft/onnxruntime/blob/main/cmake/deps.txt)
  * Resolve #22750
* Add `onnx` to vcpkg manifest so `find_package(ONNX)` and
`find_dependency(Protobuf)` can work as expected.
  * Currently, It uses 1.16.2
* v1.17.0 will become available after
microsoft/vcpkg#42942

However, `onnx` in vcpkg doesn't configure
`ONNX_DISABLE_STATIC_REGISTRATION` build option.

* microsoft/vcpkg#38879
* Create "cmake/vcpkg-triplets/" folder and triplet files which use
`VCPKG_CMAKE_CONFIGURE_OPTIONS` for the option
* This requires `VCPKG_OVERLAY_TRIPLETS` environment variable for CI
steps, which is a bit inconvenient.
     I will try to find simple way to get same result

### Motivation and Context

* Help #23158 
  * "ONNX is not consumed from vcpkg"
* "Mismatch protobuf version. When vcpkg is enabled , we should not
fetch protoc from Github which may cause version mismatches."
* microsoft/vcpkg#43126
* #21348
tarekziade pushed a commit to tarekziade/onnxruntime that referenced this pull request Jan 10, 2025
### Description

Changes vcpkg manifest and configuration file (vcpkg.json &
vcpkg-configuration.json)

* Update vcpkg version to
https://github.com/microsoft/vcpkg/releases/tag/2024.12.16
* Use protobuf 3.21.12(= `v21.12`) to sync with
[cmake/deps.txt](https://github.com/microsoft/onnxruntime/blob/main/cmake/deps.txt)
  * Resolve microsoft#22750
* Add `onnx` to vcpkg manifest so `find_package(ONNX)` and
`find_dependency(Protobuf)` can work as expected.
  * Currently, It uses 1.16.2
* v1.17.0 will become available after
microsoft/vcpkg#42942

However, `onnx` in vcpkg doesn't configure
`ONNX_DISABLE_STATIC_REGISTRATION` build option.

* microsoft/vcpkg#38879
* Create "cmake/vcpkg-triplets/" folder and triplet files which use
`VCPKG_CMAKE_CONFIGURE_OPTIONS` for the option
* This requires `VCPKG_OVERLAY_TRIPLETS` environment variable for CI
steps, which is a bit inconvenient.
     I will try to find simple way to get same result

### Motivation and Context

* Help microsoft#23158 
  * "ONNX is not consumed from vcpkg"
* "Mismatch protobuf version. When vcpkg is enabled , we should not
fetch protoc from Github which may cause version mismatches."
* microsoft/vcpkg#43126
* microsoft#21348
guschmue pushed a commit that referenced this pull request Jan 12, 2025
### Description

Changes vcpkg manifest and configuration file (vcpkg.json &
vcpkg-configuration.json)

* Update vcpkg version to
https://github.com/microsoft/vcpkg/releases/tag/2024.12.16
* Use protobuf 3.21.12(= `v21.12`) to sync with
[cmake/deps.txt](https://github.com/microsoft/onnxruntime/blob/main/cmake/deps.txt)
  * Resolve #22750
* Add `onnx` to vcpkg manifest so `find_package(ONNX)` and
`find_dependency(Protobuf)` can work as expected.
  * Currently, It uses 1.16.2
* v1.17.0 will become available after
microsoft/vcpkg#42942

However, `onnx` in vcpkg doesn't configure
`ONNX_DISABLE_STATIC_REGISTRATION` build option.

* microsoft/vcpkg#38879
* Create "cmake/vcpkg-triplets/" folder and triplet files which use
`VCPKG_CMAKE_CONFIGURE_OPTIONS` for the option
* This requires `VCPKG_OVERLAY_TRIPLETS` environment variable for CI
steps, which is a bit inconvenient.
     I will try to find simple way to get same result

### Motivation and Context

* Help #23158 
  * "ONNX is not consumed from vcpkg"
* "Mismatch protobuf version. When vcpkg is enabled , we should not
fetch protoc from Github which may cause version mismatches."
* microsoft/vcpkg#43126
* #21348
ashrit-ms pushed a commit that referenced this pull request Mar 17, 2025
### Description

Changes vcpkg manifest and configuration file (vcpkg.json &
vcpkg-configuration.json)

* Update vcpkg version to
https://github.com/microsoft/vcpkg/releases/tag/2024.12.16
* Use protobuf 3.21.12(= `v21.12`) to sync with
[cmake/deps.txt](https://github.com/microsoft/onnxruntime/blob/main/cmake/deps.txt)
  * Resolve #22750
* Add `onnx` to vcpkg manifest so `find_package(ONNX)` and
`find_dependency(Protobuf)` can work as expected.
  * Currently, It uses 1.16.2
* v1.17.0 will become available after
microsoft/vcpkg#42942

However, `onnx` in vcpkg doesn't configure
`ONNX_DISABLE_STATIC_REGISTRATION` build option.

* microsoft/vcpkg#38879
* Create "cmake/vcpkg-triplets/" folder and triplet files which use
`VCPKG_CMAKE_CONFIGURE_OPTIONS` for the option
* This requires `VCPKG_OVERLAY_TRIPLETS` environment variable for CI
steps, which is a bit inconvenient.
     I will try to find simple way to get same result

### Motivation and Context

* Help #23158 
  * "ONNX is not consumed from vcpkg"
* "Mismatch protobuf version. When vcpkg is enabled , we should not
fetch protoc from Github which may cause version mismatches."
* microsoft/vcpkg#43126
* #21348
snnn pushed a commit that referenced this pull request May 14, 2025
### Description

See the [example
repository](https://github.com/jordanozang/onnxruntime_minimal_static)
for a minimal example of using the static CMake Config.
- Add libraries built during the static onnxruntime build
(onnxruntime_common, onnxruntime_mlas, etc.) to the onnxruntime export
set. Additionally, add an onnxruntime::onnxruntime interface target that
behaves much the same as that target in the shared build case.
``find_package(onnxruntime REQUIRED)``
``target_link_libraries(example PRIVATE onnxruntime::onnxruntime)``
should now work.
- Minor modifications to ensure that dependency targets like Boost::mp11
are treated as imported targets and not part of the build interface.
- Static webgpu builds will currently not generate this CMake export




### Motivation and Context
- Resolves Issue #21351
- Builds on Pull Request #21348
ankus-qti pushed a commit to CodeLinaro/onnxruntime that referenced this pull request Nov 25, 2025
### Description

See the [example
repository](https://github.com/jordanozang/onnxruntime_minimal_static)
for a minimal example of using the static CMake Config.
- Add libraries built during the static onnxruntime build
(onnxruntime_common, onnxruntime_mlas, etc.) to the onnxruntime export
set. Additionally, add an onnxruntime::onnxruntime interface target that
behaves much the same as that target in the shared build case.
``find_package(onnxruntime REQUIRED)``
``target_link_libraries(example PRIVATE onnxruntime::onnxruntime)``
should now work.
- Minor modifications to ensure that dependency targets like Boost::mp11
are treated as imported targets and not part of the build interface.
- Static webgpu builds will currently not generate this CMake export




### Motivation and Context
- Resolves Issue microsoft#21351
- Builds on Pull Request microsoft#21348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants