Skip to content

Commit f0cdfd3

Browse files
committed
refactor(driver): consume ONNX Runtime via the onnxruntime-builds package
Drop the third-party/ + SYNTHRT_ORT_DIR path probing in favor of find_package(onnxruntime-builds CONFIG): srt-driver and srt-onnxdriver now read ONNXRUNTIME_BUILDS_INCLUDE_DIR / RUNTIME_DIR / CUDA_RUNTIME_DIR from the vcpkg overlay port. Graceful degradation is preserved: when the package is absent, srt-driver excludes onnx sources and the onnx plugin is skipped.
1 parent 3994685 commit f0cdfd3

2 files changed

Lines changed: 23 additions & 48 deletions

File tree

lib/Driver/CMakeLists.txt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,17 @@ find_package(stdcorelib CONFIG REQUIRED)
1616
# Import onnxruntime headers for OnnxTensor (zero-copy Ort::Value backend).
1717
# With ORT_API_MANUAL_INIT the C++ wrapper is header-only; no onnxruntime
1818
# library link is required (the shared library is loaded at runtime by the
19-
# OnnxDriver plugin).
20-
# Locate ONNX Runtime: check SYNTHRT_ORT_DIR (CI), then third-party/ (local), then build dir
21-
if(DEFINED SYNTHRT_ORT_DIR AND IS_DIRECTORY "${SYNTHRT_ORT_DIR}/default")
22-
set(_onnxruntime_dir ${SYNTHRT_ORT_DIR})
23-
elseif(IS_DIRECTORY ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime/default)
24-
set(_onnxruntime_dir ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime)
25-
elseif(IS_DIRECTORY ${CMAKE_BINARY_DIR}/onnxruntime/default)
26-
set(_onnxruntime_dir ${CMAKE_BINARY_DIR}/onnxruntime)
27-
else()
28-
set(_onnxruntime_dir ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime)
29-
endif()
30-
set(_onnxruntime_default_dir ${_onnxruntime_dir}/default)
31-
19+
# OnnxDriver plugin). ONNX Runtime is provided by the onnxruntime-builds CMake
20+
# package (vcpkg overlay port); find_package locates headers with no port-side
21+
# path. Without the package, OnnxTensor sources are excluded as before.
22+
find_package(onnxruntime-builds CONFIG QUIET)
3223
set(_onnx_include_dirs "")
3324
set(_onnx_defines "")
34-
if(IS_DIRECTORY ${_onnxruntime_default_dir})
35-
set(_onnx_include_dirs ${_onnxruntime_default_dir}/include)
25+
if(TARGET onnxruntime-builds::default)
26+
set(_onnx_include_dirs "${ONNXRUNTIME_BUILDS_INCLUDE_DIR}")
3627
set(_onnx_defines ORT_API_MANUAL_INIT)
3728
else()
38-
message(WARNING "ONNX runtime not found at ${_onnxruntime_default_dir}. OnnxTensor sources will be excluded.")
29+
message(WARNING "ONNX Runtime package (onnxruntime-builds) not found. OnnxTensor sources will be excluded.")
3930

4031
# Filter out onnx-specific sources when onnxruntime is unavailable so the
4132
# srt-driver library can still build without ONNX support.

plugins/Driver/onnx/CMakeLists.txt

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,13 @@ if(NOT TARGET srt::driver)
1111
endif()
1212

1313
# Require onnxruntime headers.
14-
# Locate ONNX Runtime: check SYNTHRT_ORT_DIR (CI), then third-party/ (local), then build dir
15-
if(DEFINED SYNTHRT_ORT_DIR AND IS_DIRECTORY "${SYNTHRT_ORT_DIR}/default")
16-
set(_onnxruntime_dir ${SYNTHRT_ORT_DIR})
17-
elseif(IS_DIRECTORY ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime/default)
18-
set(_onnxruntime_dir ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime)
19-
elseif(IS_DIRECTORY ${CMAKE_BINARY_DIR}/onnxruntime/default)
20-
set(_onnxruntime_dir ${CMAKE_BINARY_DIR}/onnxruntime)
21-
else()
22-
set(_onnxruntime_dir ${SYNTHRT_SOURCE_DIR}/third-party/onnxruntime)
23-
endif()
24-
25-
# Normalize to forward slashes for portability. On Windows CI the workspace
26-
# path may contain backslashes (e.g. "D:\a\synthrt") which break CMake string
27-
# parsing when the path is embedded in a list argument ("\a" is an invalid
28-
# escape). file(TO_CMAKE_PATH) converts native separators to "/".
29-
file(TO_CMAKE_PATH "${_onnxruntime_dir}" _onnxruntime_dir)
30-
31-
set(_onnxruntime_default_dir ${_onnxruntime_dir}/default)
32-
33-
if(NOT IS_DIRECTORY ${_onnxruntime_default_dir})
34-
message(WARNING "OnnxDriver plugin will not be built: ONNX runtime not found at ${_onnxruntime_default_dir}.")
14+
# ONNX Runtime is provided by the onnxruntime-builds CMake package (vcpkg
15+
# overlay port derived from its own scripts/setup-onnxruntime.cmake); find it
16+
# here so consumers never pass paths from the port. Without the package the
17+
# plugin degrades to not being built (same behavior as before the split).
18+
find_package(onnxruntime-builds CONFIG QUIET)
19+
if(NOT TARGET onnxruntime-builds::default)
20+
message(WARNING "OnnxDriver plugin will not be built: ONNX Runtime package (onnxruntime-builds) not found.")
3521
return()
3622
endif()
3723

@@ -42,8 +28,6 @@ project(srt-onnxdriver
4228

4329
file(GLOB_RECURSE _src CONFIGURE_DEPENDS *.h *.cpp)
4430

45-
set(_onnxruntime_cuda_dir ${_onnxruntime_dir}/cuda)
46-
4731
if(WIN32 AND SRT_DRIVER_ENABLE_DIRECTML)
4832
set(_onnxdriver_ep_macro_dml "ONNXDRIVER_ENABLE_DML")
4933
endif()
@@ -65,7 +49,7 @@ synthrt_add_plugin(${PROJECT_NAME} inferencedrivers ${PROJECT_NAME} NO_EXPORT
6549
FEATURES cxx_std_20
6650
LINKS srt::driver srt::core
6751
LINKS_PRIVATE stduuid BLAKE3::blake3
68-
INCLUDE_PRIVATE * ${_onnxruntime_default_dir}/include
52+
INCLUDE_PRIVATE * ${ONNXRUNTIME_BUILDS_INCLUDE_DIR}
6953
DEFINES ORT_API_MANUAL_INIT ${_onnxdriver_ep_macros}
7054
)
7155

@@ -74,12 +58,12 @@ synthrt_add_plugin(${PROJECT_NAME} inferencedrivers ${PROJECT_NAME} NO_EXPORT
7458
# install(FILES ...) receives actual file paths — install(FILES ...) does
7559
# not expand glob patterns itself.
7660
if(WIN32)
77-
file(GLOB _ort_default_lib_files ${_onnxruntime_default_dir}/lib/*.dll)
61+
file(GLOB _ort_default_lib_files ${ONNXRUNTIME_BUILDS_RUNTIME_DIR}/*.dll)
7862
elseif(APPLE)
79-
file(GLOB _ort_default_lib_files ${_onnxruntime_default_dir}/lib/*.dylib)
63+
file(GLOB _ort_default_lib_files ${ONNXRUNTIME_BUILDS_RUNTIME_DIR}/*.dylib)
8064
else()
81-
file(GLOB _ort_default_lib_files ${_onnxruntime_default_dir}/lib/*.so
82-
${_onnxruntime_default_dir}/lib/*.so.*)
65+
file(GLOB _ort_default_lib_files ${ONNXRUNTIME_BUILDS_RUNTIME_DIR}/*.so
66+
${ONNXRUNTIME_BUILDS_RUNTIME_DIR}/*.so.*)
8367
endif()
8468

8569
# Build-phase copy: place runtimes next to the plugin output directory.
@@ -103,12 +87,12 @@ if(_ort_default_lib_files)
10387
)
10488
endif()
10589

106-
if(EXISTS ${_onnxruntime_cuda_dir} AND IS_DIRECTORY ${_onnxruntime_cuda_dir})
90+
if(ONNXRUNTIME_BUILDS_CUDA_RUNTIME_DIR)
10791
if(WIN32)
108-
file(GLOB _ort_cuda_lib_files ${_onnxruntime_cuda_dir}/lib/*.dll)
92+
file(GLOB _ort_cuda_lib_files ${ONNXRUNTIME_BUILDS_CUDA_RUNTIME_DIR}/*.dll)
10993
else()
110-
file(GLOB _ort_cuda_lib_files ${_onnxruntime_cuda_dir}/lib/*.so
111-
${_onnxruntime_cuda_dir}/lib/*.so.*)
94+
file(GLOB _ort_cuda_lib_files ${ONNXRUNTIME_BUILDS_CUDA_RUNTIME_DIR}/*.so
95+
${ONNXRUNTIME_BUILDS_CUDA_RUNTIME_DIR}/*.so.*)
11296
endif()
11397

11498
if(NOT APPLE AND _ort_cuda_lib_files)

0 commit comments

Comments
 (0)