Skip to content

Commit

Permalink
[onnx] Support test build and rename features (#207)
Browse files Browse the repository at this point in the history
* [onnx] change feature names

* fix mistype, use INVERTED_FEATURES

* [onnx] create patch for test build

* [onnx] update baseline

* ci: test onnx with its features
  • Loading branch information
luncliff authored May 25, 2024
1 parent 0311468 commit 72ff1aa
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 23 deletions.
15 changes: 10 additions & 5 deletions ports/onnx/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vcpkg_from_github(
SHA512 b46a4ab70af88053318eba45251c1f71528f15e45a33042877570e8d857febd3ec66e2e811fcda2105a4f17b84c9a1c6a0aaa22756c3287321b3ea29e83127fd
PATCHES
fix-cmakelists.patch
support-test.patch
)

string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME)
Expand All @@ -27,10 +28,12 @@ message(STATUS "Using protoc: ${PROTOC}")

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
python BUILD_ONNX_PYTHON
protobuf-lite ONNX_USE_LITE_PROTO
disable-exception ONNX_DISABLE_EXCEPTIONS
disable-static-generation ONNX_DISABLE_STATIC_REGISTRATION
python BUILD_ONNX_PYTHON
protobuf-lite ONNX_USE_LITE_PROTO
test ONNX_BUILD_TESTS
INVERTED_FEATURES
exception ONNX_DISABLE_EXCEPTIONS
static-registration ONNX_DISABLE_STATIC_REGISTRATION
)

if("python" IN_LIST FEATURES)
Expand Down Expand Up @@ -69,7 +72,6 @@ vcpkg_cmake_configure(
-DONNX_GEN_PB_TYPE_STUBS=ON
-DONNX_USE_PROTOBUF_SHARED_LIBS=${USE_PROTOBUF_SHARED}
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
-DONNX_BUILD_TESTS=OFF
-DONNX_BUILD_BENCHMARKS=OFF
MAYBE_UNUSED_VARIABLES
ONNX_USE_MSVC_STATIC_RUNTIME
Expand All @@ -78,6 +80,9 @@ vcpkg_cmake_configure(

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX PACKAGE_NAME ONNX)
if("test" IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES onnx_gtests AUTO_CLEAN)
endif()

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
Expand Down
54 changes: 54 additions & 0 deletions ports/onnx/support-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd9fba2..651cb4e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -125,8 +125,7 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
endif()

if(ONNX_BUILD_TESTS)
- list(APPEND CMAKE_MODULE_PATH ${ONNX_ROOT}/cmake/external)
- include(googletest)
+ find_package(GTest CONFIG REQUIRED)
endif()

if((ONNX_USE_LITE_PROTO AND TARGET protobuf::libprotobuf-lite) OR ((NOT ONNX_USE_LITE_PROTO) AND TARGET protobuf::libprotobuf))
diff --git a/cmake/unittest.cmake b/cmake/unittest.cmake
index e71b92a..afccacf 100644
--- a/cmake/unittest.cmake
+++ b/cmake/unittest.cmake
@@ -22,7 +22,7 @@ function(AddTest)
list(REMOVE_DUPLICATES _UT_SOURCES)

add_executable(${_UT_TARGET} ${_UT_SOURCES})
- add_dependencies(${_UT_TARGET} onnx onnx_proto googletest)
+ add_dependencies(${_UT_TARGET} onnx onnx_proto)

target_include_directories(${_UT_TARGET}
PUBLIC ${googletest_INCLUDE_DIRS}
@@ -30,7 +30,7 @@ function(AddTest)
${PROTOBUF_INCLUDE_DIRS}
${ONNX_ROOT}
${CMAKE_CURRENT_BINARY_DIR})
- target_link_libraries(${_UT_TARGET} ${_UT_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+ target_link_libraries(${_UT_TARGET} ${_UT_LIBS} ${CMAKE_THREAD_LIBS_INIT} GTest::gtest)
if(TARGET protobuf::libprotobuf)
target_link_libraries(${_UT_TARGET} protobuf::libprotobuf)
else()
@@ -84,3 +84,4 @@ function(AddTest)
endfunction(AddTest)

addtest(TARGET ${UT_NAME} SOURCES ${${UT_NAME}_src} LIBS ${${UT_NAME}_libs})
+install(TARGETS ${UT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/onnx/test/cpp/test_main.cc b/onnx/test/cpp/test_main.cc
index cee5e79..d77d2f2 100644
--- a/onnx/test/cpp/test_main.cc
+++ b/onnx/test/cpp/test_main.cc
@@ -8,7 +8,7 @@

#include "gtest/gtest.h"

-GTEST_API_ int main(int argc, char** argv) {
+int main(int argc, char** argv) {
std::cout << "Running main() from test_main.cc" << std::endl;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
20 changes: 15 additions & 5 deletions ports/onnx/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "onnx",
"version-semver": "1.15.0",
"port-version": 1,
"description": "Open standard for machine learning interoperability",
"homepage": "https://onnx.ai",
"license": "Apache-2.0",
Expand All @@ -19,12 +20,12 @@
"host": true
}
],
"default-features": [
"exception"
],
"features": {
"disable-exception": {
"description": "Disable exception handling"
},
"disable-static-generation": {
"description": "Disable static registration for onnx operator schemas"
"exception": {
"description": "Enable exception handling"
},
"python": {
"description": "Build Python binaries",
Expand All @@ -35,6 +36,15 @@
"host": true
}
]
},
"static-registration": {
"description": "Enable static registration for onnx operator schemas"
},
"test": {
"description": "Enable exception handling",
"dependencies": [
"gtest"
]
}
}
}
27 changes: 17 additions & 10 deletions test/self-hosted-cuda.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "test",
"version-date": "2024-05-13",
"version-date": "2024-05-25",
"description": "vcpkg registry maintained by @luncliff",
"homepage": "https://github.com/luncliff/vcpkg-registry",
"supports": "windows",
Expand All @@ -13,19 +13,26 @@
],
"platform": "x64 & windows"
},
{
"name": "onnxruntime",
"features": [
"cuda"
],
"platform": "x64 & windows"
},
"nvidia-cnmem",
"nvidia-cutlass",
"nvidia-nvbench",
"nvidia-tools-extension-sdk",
"nvidia-triton-client",
"nvidia-triton-common",
"nvidia-triton-core",
"nvidia-triton-client"
{
"name": "onnx",
"features": [
"static-registration",
"test"
]
},
{
"name": "onnxruntime",
"features": [
"cuda"
],
"platform": "x64 & windows"
}
]
}
}
9 changes: 8 additions & 1 deletion test/self-hosted.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "test",
"version-date": "2024-05-18",
"version-date": "2024-05-25",
"description": "vcpkg registry maintained by @luncliff",
"homepage": "https://github.com/luncliff/vcpkg-registry",
"supports": "windows",
Expand All @@ -14,6 +14,13 @@
"platform": "x64 & windows"
},
"liblzma",
{
"name": "onnx",
"features": [
"static-registration",
"test"
]
},
{
"name": "onnxruntime",
"features": [
Expand Down
9 changes: 8 additions & 1 deletion test/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "test",
"version-date": "2024-05-18",
"version-date": "2024-05-25",
"description": "vcpkg registry maintained by @luncliff",
"homepage": "https://github.com/luncliff/vcpkg-registry",
"supports": "windows | linux | osx | ios",
Expand Down Expand Up @@ -54,6 +54,13 @@
"platform": "osx | ios"
},
"miniaudio",
{
"name": "onnx",
"features": [
"static-registration",
"test"
]
},
{
"name": "onnxruntime",
"features": [
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
},
"onnx": {
"baseline": "1.15.0",
"port-version": 0
"port-version": 1
},
"onnxruntime": {
"baseline": "1.17.3",
Expand Down
5 changes: 5 additions & 0 deletions versions/o-/onnx.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "fd1d8cd2b64f75ba7c9d34f1d4364ba3d038ac73",
"version-semver": "1.15.0",
"port-version": 1
},
{
"git-tree": "18fa90d742ae729066d99e418a07a4a8f00e34be",
"version-semver": "1.15.0",
Expand Down

0 comments on commit 72ff1aa

Please sign in to comment.