Skip to content

Commit 5755e1e

Browse files
authored
[onnx,onnx-optimizier] Remove "python3" dependency and "pybind11" feature (#43236)
1 parent 7145665 commit 5755e1e

File tree

9 files changed

+29
-142
lines changed

9 files changed

+29
-142
lines changed

ports/onnx-optimizer/fix-cmakelists.patch

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,6 @@ index 0063385..f1522bc 100644
4242
target_include_directories(onnx_optimizer PUBLIC
4343
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
4444
$<INSTALL_INTERFACE:include>
45-
@@ -70,7 +77,7 @@ if(BUILD_ONNX_PYTHON)
46-
set(PY_EXT_SUFFIX ".so")
47-
endif()
48-
endif()
49-
- find_package(Python COMPONENTS Interpreter REQUIRED)
50-
+ find_package(Python3 COMPONENTS Development REQUIRED)
51-
52-
onnxopt_add_library(onnx_opt_cpp2py_export MODULE "onnxoptimizer/cpp2py_export.cc")
53-
set_target_properties(onnx_opt_cpp2py_export PROPERTIES PREFIX "")
54-
@@ -84,7 +91,7 @@ if(BUILD_ONNX_PYTHON)
55-
$<INSTALL_INTERFACE:include>
56-
${Python_INCLUDE_DIR})
57-
# pybind11 is a header only lib
58-
- find_package(pybind11 2.2)
59-
+ find_package(pybind11 2.2 CONFIG REQUIRED)
60-
if(pybind11_FOUND)
61-
target_include_directories(onnx_opt_cpp2py_export PUBLIC
62-
${pybind11_INCLUDE_DIRS})
63-
@@ -121,9 +128,9 @@ if(BUILD_ONNX_PYTHON)
64-
65-
target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)
66-
67-
+ target_link_directories(onnx_opt_cpp2py_export PRIVATE ${Python3_LIBRARY_DIRS})
68-
+ target_link_libraries(onnx_opt_cpp2py_export PRIVATE ${Python3_LIBRARIES})
69-
if(MSVC)
70-
- find_package(Python COMPONENTS Interpreter Development REQUIRED)
71-
- target_link_libraries(onnx_opt_cpp2py_export PRIVATE ${Python_LIBRARIES})
72-
target_compile_options(onnx_opt_cpp2py_export
73-
PRIVATE /MP
74-
/WX
7545
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
7646
index 6cca9f3..9d79f1a 100644
7747
--- a/cmake/utils.cmake
@@ -91,8 +61,8 @@ index 72dcc88..c5639c8 100644
9161
# as well as ONNX Optimizer targets for other cmake libraries to use.
9262

9363
+include(CMakeFindDependencyMacro)
94-
+find_dependency(onnx CONFIG)
95-
+
64+
+find_dependency(protobuf CONFIG)
65+
+find_dependency(ONNX CONFIG)
9666
# library version information
9767
set(ONNX_OPTIMIZER_VERSION "@ONNX_OPTIMIZER_VERSION@")
9868

ports/onnx-optimizer/portfile.cmake

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,15 @@ vcpkg_from_github(
1212

1313
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME)
1414

15-
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
16-
FEATURES
17-
pybind11 BUILD_ONNX_PYTHON
18-
)
19-
if("pybind11" IN_LIST FEATURES)
20-
vcpkg_find_acquire_program(PYTHON3)
21-
list(APPEND FEATURE_OPTIONS
22-
-DPython3_EXECUTABLE=${PYTHON3}
23-
-DONNX_USE_PROTOBUF_SHARED_LIBS=ON # /wd4251
24-
)
25-
endif()
2615

2716
vcpkg_cmake_configure(
2817
SOURCE_PATH "${SOURCE_PATH}"
2918
OPTIONS
3019
${FEATURE_OPTIONS}
20+
-DONNX_OPT_USE_SYSTEM_PROTOBUF=ON
3121
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
3222
)
33-
if("pybind11" IN_LIST FEATURES)
34-
# This target is not in install/export
35-
vcpkg_cmake_build(TARGET onnx_opt_cpp2py_export)
36-
endif()
3723
vcpkg_cmake_install()
38-
vcpkg_copy_pdbs()
3924
vcpkg_cmake_config_fixup(PACKAGE_NAME ONNXOptimizer CONFIG_PATH lib/cmake/ONNXOptimizer)
4025

4126
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

ports/onnx-optimizer/vcpkg.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "onnx-optimizer",
33
"version-semver": "0.3.19",
4+
"port-version": 1,
45
"description": "Actively maintained ONNX Optimizer",
56
"homepage": "https://github.com/onnx/optimizer",
67
"license": "Apache-2.0",
@@ -14,18 +15,5 @@
1415
"name": "vcpkg-cmake-config",
1516
"host": true
1617
}
17-
],
18-
"features": {
19-
"pybind11": {
20-
"description": "Build Python binaries",
21-
"dependencies": [
22-
{
23-
"name": "onnx",
24-
"features": [
25-
"pybind11"
26-
]
27-
}
28-
]
29-
}
30-
}
18+
]
3119
}

ports/onnx/fix-cmakelists.patch

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index 4dd56b6..2ff3e29 100644
2+
index b666eec..66c234d 100644
33
--- a/CMakeLists.txt
44
+++ b/CMakeLists.txt
5-
@@ -65,6 +65,27 @@ endif()
5+
@@ -63,6 +63,16 @@ endif()
66

77
include(GNUInstallDirs)
88

@@ -15,22 +15,11 @@ index 4dd56b6..2ff3e29 100644
1515
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-operators-ml.proto3
1616
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnx
1717
+)
18-
+# install python files
19-
+if(BUILD_ONNX_PYTHON)
20-
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_data_pb.py
21-
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_data_pb2.py
22-
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_ml_pb2.py
23-
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_operators_ml_pb2.py
24-
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_operators_pb.py
25-
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_pb.py
26-
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnx
27-
+ )
28-
+endif()
2918
+
3019
set(ONNX_ROOT ${PROJECT_SOURCE_DIR})
3120

3221
# Read ONNX version
33-
@@ -116,7 +137,8 @@ endif()
22+
@@ -104,7 +114,8 @@ endif()
3423
# find_package Python has replaced PythonInterp and PythonLibs since cmake 3.12
3524
# Use the following command in the future; now this is only compatible with the latest pybind11
3625
# find_package(Python ${PY_VERSION} COMPONENTS Interpreter Development REQUIRED)
@@ -40,28 +29,3 @@ index 4dd56b6..2ff3e29 100644
4029
if(BUILD_ONNX_PYTHON)
4130
find_package(PythonLibs ${PY_VERSION})
4231
endif()
43-
@@ -434,6 +456,7 @@ target_link_libraries(onnx PUBLIC onnx_proto)
44-
add_onnx_global_defines(onnx)
45-
46-
if(BUILD_ONNX_PYTHON)
47-
+ find_package(Python3 ${PY_VERSION} COMPONENTS Development REQUIRED)
48-
if("${PY_EXT_SUFFIX}" STREQUAL "")
49-
if(MSVC)
50-
set(PY_EXT_SUFFIX ".pyd")
51-
@@ -452,10 +475,14 @@ if(BUILD_ONNX_PYTHON)
52-
target_include_directories(onnx_cpp2py_export PRIVATE
53-
$<BUILD_INTERFACE:${ONNX_ROOT}>
54-
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
55-
- $<INSTALL_INTERFACE:include>)
56-
+ ${Python3_INCLUDE_DIRS})
57-
+ target_link_directories(onnx_cpp2py_export PRIVATE
58-
+ ${Python3_LIBRARY_DIRS})
59-
+ target_link_libraries(onnx_cpp2py_export PRIVATE
60-
+ ${Python3_LIBRARIES})
61-
62-
# pybind11 is a header only lib
63-
- find_package(pybind11 2.2 CONFIG)
64-
+ find_package(pybind11 2.2 CONFIG REQUIRED)
65-
if(NOT pybind11_FOUND)
66-
if(EXISTS "${ONNX_ROOT}/third_party/pybind11/include/pybind11/pybind11.h")
67-
add_subdirectory("${ONNX_ROOT}/third_party/pybind11")

ports/onnx/portfile.cmake

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ vcpkg_from_github(
1313

1414
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME)
1515

16+
# ONNX_CUSTOM_PROTOC_EXECUTABLE
17+
find_program(PROTOC NAMES protoc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH)
18+
1619
# ONNX_USE_PROTOBUF_SHARED_LIBS: find the library and check its file extension
1720
find_library(PROTOBUF_LIBPATH NAMES protobuf PATHS "${CURRENT_INSTALLED_DIR}/bin" "${CURRENT_INSTALLED_DIR}/lib" REQUIRED)
1821
get_filename_component(PROTOBUF_LIBNAME "${PROTOBUF_LIBPATH}" NAME)
@@ -22,32 +25,16 @@ else()
2225
set(USE_PROTOBUF_SHARED OFF)
2326
endif()
2427

25-
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
26-
FEATURES
27-
pybind11 BUILD_ONNX_PYTHON
28-
)
29-
30-
# Like protoc, python is required for codegen.
3128
vcpkg_find_acquire_program(PYTHON3)
3229

33-
# PATH for .bat scripts so it can find 'python'
34-
get_filename_component(PYTHON_DIR "${PYTHON3}" PATH)
35-
vcpkg_add_to_path(PREPEND "${PYTHON_DIR}")
36-
37-
if("pybind11" IN_LIST FEATURES)
38-
# When BUILD_ONNX_PYTHON, we need Development component. Give a hint for FindPython3
39-
list(APPEND FEATURE_OPTIONS
40-
"-DPython3_ROOT_DIR=${CURRENT_INSTALLED_DIR}"
41-
)
42-
endif()
43-
4430
vcpkg_cmake_configure(
4531
SOURCE_PATH "${SOURCE_PATH}"
4632
OPTIONS
4733
${FEATURE_OPTIONS}
48-
-DPython3_EXECUTABLE=${PYTHON3}
34+
"-DPython3_EXECUTABLE:FILEPATH=${PYTHON3}"
35+
"-DONNX_CUSTOM_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}"
36+
"-DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}"
4937
-DONNX_ML=ON
50-
-DONNX_GEN_PB_TYPE_STUBS=ON
5138
-DONNX_USE_PROTOBUF_SHARED_LIBS=${USE_PROTOBUF_SHARED}
5239
-DONNX_USE_LITE_PROTO=OFF
5340
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
@@ -56,13 +43,8 @@ vcpkg_cmake_configure(
5643
MAYBE_UNUSED_VARIABLES
5744
ONNX_USE_MSVC_STATIC_RUNTIME
5845
)
59-
60-
if("pybind11" IN_LIST FEATURES)
61-
# This target is not in install/export
62-
vcpkg_cmake_build(TARGET onnx_cpp2py_export)
63-
endif()
6446
vcpkg_cmake_install()
65-
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX)
47+
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX PACKAGE_NAME ONNX)
6648

6749
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
6850

ports/onnx/vcpkg.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
{
22
"name": "onnx",
33
"version-semver": "1.17.0",
4+
"port-version": 1,
45
"description": "Open standard for machine learning interoperability",
56
"homepage": "https://onnx.ai",
67
"license": "Apache-2.0",
7-
"supports": "!uwp",
88
"dependencies": [
99
"protobuf",
1010
{
1111
"name": "protobuf",
1212
"host": true
1313
},
14-
{
15-
"name": "python3",
16-
"host": true
17-
},
1814
{
1915
"name": "vcpkg-cmake",
2016
"host": true
@@ -23,13 +19,5 @@
2319
"name": "vcpkg-cmake-config",
2420
"host": true
2521
}
26-
],
27-
"features": {
28-
"pybind11": {
29-
"description": "Build Python binaries",
30-
"dependencies": [
31-
"pybind11"
32-
]
33-
}
34-
}
22+
]
3523
}

versions/baseline.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6610,11 +6610,11 @@
66106610
},
66116611
"onnx": {
66126612
"baseline": "1.17.0",
6613-
"port-version": 0
6613+
"port-version": 1
66146614
},
66156615
"onnx-optimizer": {
66166616
"baseline": "0.3.19",
6617-
"port-version": 0
6617+
"port-version": 1
66186618
},
66196619
"onnxruntime-gpu": {
66206620
"baseline": "1.19.2",

versions/o-/onnx-optimizer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "df755dc18bda1d4c02a54db6cef63e46021ce872",
5+
"version-semver": "0.3.19",
6+
"port-version": 1
7+
},
38
{
49
"git-tree": "126bfc519dc0c50fc52ed0b19a0bd88663bae87f",
510
"version-semver": "0.3.19",

versions/o-/onnx.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "1ae91479c59de528eae6e6db5235b8ff0460e222",
5+
"version-semver": "1.17.0",
6+
"port-version": 1
7+
},
38
{
49
"git-tree": "9849fadc0639a430cf9c49434b60cbeb08989112",
510
"version-semver": "1.17.0",

0 commit comments

Comments
 (0)