Skip to content

Commit 987f0a4

Browse files
author
Changming Sun
authored
Create dependencies.md
1 parent ce66e07 commit 987f0a4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/build/dependencies.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Dependency Management in ONNX Runtime
2+
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.
3+
Overall, there are three ways to get dependencies for an ONNX Runtime build:
4+
5+
1. Use VCPKG (Recommended)
6+
2. Build everything from source
7+
3. Use preinstalled packages (Advanced Users Only)
8+
9+
This document will have one section for each above.
10+
11+
# VCPKG
12+
13+
## What is VCPKG?
14+
15+
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.
16+
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.
17+
18+
## Prerequisites for using VCPKG
19+
20+
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:
21+
apt-get install git curl zip unzip pkgconfig ninja-build
22+
23+
## How to build ONNX Runtime with VCPKG
24+
25+
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:
26+
1. Install Git and Run “git clone https://github.com/microsoft/vcpkg.git”
27+
2. Navigate to the VCPKG directory and run the bootstrap script:
28+
- On Windows: bootstrap-vcpkg.bat
29+
- On other systems: bootstrap-vcpkg.sh
30+
31+
If the script cannot find some prerequisites, install the missing software and try again.
32+
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.
33+
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.
34+
35+
# Build everything from source
36+
37+
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.
38+
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.
39+
40+
# Use preinstalled packages
41+
FetchContent is a wrapper around various CMake Dependency Providers. By default, it prefers to use FindPackage. However, there are some caveats:
42+
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.
43+
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.
44+
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.

0 commit comments

Comments
 (0)