-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Create dependencies.md for improving build document #23786
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
987f0a4
Create dependencies.md
b24601f
Update dependencies documentation for ONNX Runtime
9647381
Update dependencies.md
eba811e
Update dependencies.md
0cbeb14
Update dependencies.md
53f82c9
Update dependencies.md
976d738
Update dependencies.md
6c602e5
Update dependencies.md
4aef3f6
Update dependencies.md
c330486
Update dependencies.md
0a3ffb4
Update inferencing.md
8b6f57f
Update inferencing.md
bb5174e
Update inferencing.md
be2921f
Update dependency management documentation in ONNX Runtime
5c2dbc2
Update dependencies.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| Dependency Management in ONNX Runtime | ||
| This document provides supplement information to CMake’s [“Using Dependencies Guide”](https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html) and it is more ONNX Runtime specific. | ||
| Overall, there are three ways to get dependencies for an ONNX Runtime build: | ||
|
|
||
| 1. [Use VCPKG](#vcpkg) (Recommended) | ||
| 2. [Build everything from source](#build-everything-from-source) | ||
| 3. [Use preinstalled packages](#use-preinstalled-packages) (For Advanced Users) | ||
|
|
||
| # VCPKG | ||
|
|
||
| ## What is VCPKG? | ||
|
|
||
| VCPKG is a free and open-source C/C++ package manager maintained by Microsoft and the C++ community. It was mainly developed by the Visual Studio team at Microsoft. It helps developers manage their C++ dependencies in a simple and declarative way. It is based on CMake and can be integrated into your CMake project or used separately before building. ONNX Runtime uses the former approach, known as manifest mode. | ||
| VCPKG provides better support for cross-compiling. For example, if you are building ONNX Runtime for ARM64 on a x64 machine, VCPKG will compile protoc in x64, simplifying the build process. | ||
|
|
||
| ## Prerequisites for using VCPKG | ||
|
|
||
| Refer to the VCPKG documentation for supported hosts: https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/concepts/supported-hosts.md. For example, on Ubuntu, you need to install the following packages: | ||
| apt-get install git curl zip unzip pkgconfig ninja-build | ||
|
|
||
| ## How to build ONNX Runtime with VCPKG | ||
|
|
||
| Just add “--use_vcpkg” to your build command. The build script(build.py) will check out a fresh vcpkg repo into your build directory and bootstrap the vcpkg tool. If you encounter any errors, you may need to manually get VCPKG using the following steps: | ||
| 1. Install Git and Run “git clone https://github.com/microsoft/vcpkg.git” | ||
| 2. Navigate to the VCPKG directory and run the bootstrap script: | ||
| - On Windows: bootstrap-vcpkg.bat | ||
| - On other systems: bootstrap-vcpkg.sh | ||
|
|
||
| If the script cannot find some prerequisites, install the missing software and try again. | ||
| 3. Set the environment variable VCPKG_INSTALLATION_ROOT to the VCPKG directory, then go back to the ONNX Runtime source folder and run the build script again. | ||
| For more details, see: https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/get_started/includes/setup-vcpkg.md. If you get blocked on bootstrapping VCPKG, please contact the VCPKG team for support. | ||
|
|
||
| ### VCPKG ports, triplets and toolchains | ||
|
|
||
| A package in VCPKG is called a VCPKG port. The build scripts for a port can be find at http://github.com/microsoft/vcpkg/tree/master/ports . ONNX Runtime also has some custom ports that are hosted at https://github.com/microsoft/onnxruntime/tree/main/cmake/vcpkg-ports. The custom ports have higher priority than the official ports. The files in a port's directory contains configurations that is specific to that port. For example, whether enable CUDA or not. | ||
|
|
||
| A triplet is a cmake file that contains configurations that are applied to all ports in the current build. For example, whether enable C++ exception or not. It is only used for building dependencies. It won't affect the build flags of ONNX Runtime's source code. The compiler flags and cmake variables set in tools/ci_build/build.py are for ONNX Runtime only and are not applicable to vcpkg ports. Therefore we need to use custom triplet files to make the settings consistent. | ||
|
|
||
| A toolchain file is for setting up compilers/linkers etc, which is more powerful. | ||
|
|
||
| # Build everything from source | ||
|
|
||
| Add “--cmake_extra_defines FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER” to your build command. When VCPKG is not enabled, we use CMake’s FetchContent to manage dependencies. All such dependencies are listed in cmake/deps.txt, allowing you to customize versions and download URLs. This is useful for meeting network isolation requirements or upgrading/downgrading library versions. | ||
| When declaring a dependency in ONNX Runtime’s CMake files, if FIND_PACKAGE arguments are provided, FetchContent will use CMake’s FindPackage module to find dependencies from system locations. Add --cmake_extra_defines FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER to disable this behavior. | ||
|
|
||
| # Use preinstalled packages | ||
snnn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This is the default mode when building ONNX Runtime from source. If a build has neither '--use_vcpkg' nor '--cmake_extra_defines FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER', it will be in this mode. It is because FetchContent is a wrapper around various CMake Dependency Providers. By default it prefers to use [find_package](https://cmake.org/cmake/help/latest/command/find_package.html) if FIND_PACKAGE arguments are provided for the dependency. If you are integrating ONNX Runtime into a package manager(like dnf), you will need to use this approach. However, it has some caveats: | ||
|
|
||
| 1. ONNX Runtime has local patches for dependencies that will not be applied to your preinstalled libraries. Most patches are not necessary for basic functionality. | ||
| 2. If you have installed a library version different from what ONNX Runtime expects, the build script cannot warn you. This may lead to strange build failures. | ||
| 3. Each library can be built in different ways. For example, ONNX Runtime expects ONNX is built with “-DONNX_DISABLE_STATIC_REGISTRATION=ON”. If you have got a prebuilt ONNX library from somewhere, most likely it was not built in this way. | ||
|
|
||
| Therefore we say it is for advanced users. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.