Skip to content
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

[onnx,onnx-optimizier] Remove "python3" dependency and "pybind11" feature #43236

Merged
merged 10 commits into from
Jan 30, 2025
34 changes: 2 additions & 32 deletions ports/onnx-optimizer/fix-cmakelists.patch
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,6 @@ index 0063385..f1522bc 100644
target_include_directories(onnx_optimizer PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
@@ -70,7 +77,7 @@ if(BUILD_ONNX_PYTHON)
set(PY_EXT_SUFFIX ".so")
endif()
endif()
- find_package(Python COMPONENTS Interpreter REQUIRED)
+ find_package(Python3 COMPONENTS Development REQUIRED)

onnxopt_add_library(onnx_opt_cpp2py_export MODULE "onnxoptimizer/cpp2py_export.cc")
set_target_properties(onnx_opt_cpp2py_export PROPERTIES PREFIX "")
@@ -84,7 +91,7 @@ if(BUILD_ONNX_PYTHON)
$<INSTALL_INTERFACE:include>
${Python_INCLUDE_DIR})
# pybind11 is a header only lib
- find_package(pybind11 2.2)
+ find_package(pybind11 2.2 CONFIG REQUIRED)
if(pybind11_FOUND)
target_include_directories(onnx_opt_cpp2py_export PUBLIC
${pybind11_INCLUDE_DIRS})
@@ -121,9 +128,9 @@ if(BUILD_ONNX_PYTHON)

target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)

+ target_link_directories(onnx_opt_cpp2py_export PRIVATE ${Python3_LIBRARY_DIRS})
+ target_link_libraries(onnx_opt_cpp2py_export PRIVATE ${Python3_LIBRARIES})
if(MSVC)
- find_package(Python COMPONENTS Interpreter Development REQUIRED)
- target_link_libraries(onnx_opt_cpp2py_export PRIVATE ${Python_LIBRARIES})
target_compile_options(onnx_opt_cpp2py_export
PRIVATE /MP
/WX
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 6cca9f3..9d79f1a 100644
--- a/cmake/utils.cmake
Expand All @@ -91,8 +61,8 @@ index 72dcc88..c5639c8 100644
# as well as ONNX Optimizer targets for other cmake libraries to use.

+include(CMakeFindDependencyMacro)
+find_dependency(onnx CONFIG)
+
+find_dependency(protobuf CONFIG)
+find_dependency(ONNX CONFIG)
# library version information
set(ONNX_OPTIMIZER_VERSION "@ONNX_OPTIMIZER_VERSION@")

17 changes: 1 addition & 16 deletions ports/onnx-optimizer/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,15 @@ vcpkg_from_github(

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

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
pybind11 BUILD_ONNX_PYTHON
)
if("pybind11" IN_LIST FEATURES)
vcpkg_find_acquire_program(PYTHON3)
list(APPEND FEATURE_OPTIONS
-DPython3_EXECUTABLE=${PYTHON3}
-DONNX_USE_PROTOBUF_SHARED_LIBS=ON # /wd4251
)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
-DONNX_OPT_USE_SYSTEM_PROTOBUF=ON
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
)
if("pybind11" IN_LIST FEATURES)
# This target is not in install/export
vcpkg_cmake_build(TARGET onnx_opt_cpp2py_export)
endif()
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup(PACKAGE_NAME ONNXOptimizer CONFIG_PATH lib/cmake/ONNXOptimizer)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
Expand Down
16 changes: 2 additions & 14 deletions ports/onnx-optimizer/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "onnx-optimizer",
"version-semver": "0.3.19",
"port-version": 1,
"description": "Actively maintained ONNX Optimizer",
"homepage": "https://github.com/onnx/optimizer",
"license": "Apache-2.0",
Expand All @@ -14,18 +15,5 @@
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"pybind11": {
"description": "Build Python binaries",
"dependencies": [
{
"name": "onnx",
"features": [
"pybind11"
]
}
]
}
}
]
}
42 changes: 3 additions & 39 deletions ports/onnx/fix-cmakelists.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4dd56b6..2ff3e29 100644
index b666eec..66c234d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,27 @@ endif()
@@ -63,6 +63,16 @@ endif()

include(GNUInstallDirs)

Expand All @@ -15,22 +15,11 @@ index 4dd56b6..2ff3e29 100644
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-operators-ml.proto3
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnx
+)
+# install python files
+if(BUILD_ONNX_PYTHON)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_data_pb.py
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_data_pb2.py
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_ml_pb2.py
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_operators_ml_pb2.py
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_operators_pb.py
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx_pb.py
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnx
+ )
+endif()
+
set(ONNX_ROOT ${PROJECT_SOURCE_DIR})

# Read ONNX version
@@ -116,7 +137,8 @@ endif()
@@ -104,7 +114,8 @@ endif()
# find_package Python has replaced PythonInterp and PythonLibs since cmake 3.12
# Use the following command in the future; now this is only compatible with the latest pybind11
# find_package(Python ${PY_VERSION} COMPONENTS Interpreter Development REQUIRED)
Expand All @@ -40,28 +29,3 @@ index 4dd56b6..2ff3e29 100644
if(BUILD_ONNX_PYTHON)
find_package(PythonLibs ${PY_VERSION})
endif()
@@ -434,6 +456,7 @@ target_link_libraries(onnx PUBLIC onnx_proto)
add_onnx_global_defines(onnx)

if(BUILD_ONNX_PYTHON)
+ find_package(Python3 ${PY_VERSION} COMPONENTS Development REQUIRED)
if("${PY_EXT_SUFFIX}" STREQUAL "")
if(MSVC)
set(PY_EXT_SUFFIX ".pyd")
@@ -452,10 +475,14 @@ if(BUILD_ONNX_PYTHON)
target_include_directories(onnx_cpp2py_export PRIVATE
$<BUILD_INTERFACE:${ONNX_ROOT}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
- $<INSTALL_INTERFACE:include>)
+ ${Python3_INCLUDE_DIRS})
+ target_link_directories(onnx_cpp2py_export PRIVATE
+ ${Python3_LIBRARY_DIRS})
+ target_link_libraries(onnx_cpp2py_export PRIVATE
+ ${Python3_LIBRARIES})

# pybind11 is a header only lib
- find_package(pybind11 2.2 CONFIG)
+ find_package(pybind11 2.2 CONFIG REQUIRED)
if(NOT pybind11_FOUND)
if(EXISTS "${ONNX_ROOT}/third_party/pybind11/include/pybind11/pybind11.h")
add_subdirectory("${ONNX_ROOT}/third_party/pybind11")
32 changes: 7 additions & 25 deletions ports/onnx/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ vcpkg_from_github(

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

# ONNX_CUSTOM_PROTOC_EXECUTABLE
find_program(PROTOC NAMES protoc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH)

# ONNX_USE_PROTOBUF_SHARED_LIBS: find the library and check its file extension
find_library(PROTOBUF_LIBPATH NAMES protobuf PATHS "${CURRENT_INSTALLED_DIR}/bin" "${CURRENT_INSTALLED_DIR}/lib" REQUIRED)
get_filename_component(PROTOBUF_LIBNAME "${PROTOBUF_LIBPATH}" NAME)
Expand All @@ -22,32 +25,16 @@ else()
set(USE_PROTOBUF_SHARED OFF)
endif()

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
pybind11 BUILD_ONNX_PYTHON
)

# Like protoc, python is required for codegen.
vcpkg_find_acquire_program(PYTHON3)

# PATH for .bat scripts so it can find 'python'
get_filename_component(PYTHON_DIR "${PYTHON3}" PATH)
vcpkg_add_to_path(PREPEND "${PYTHON_DIR}")

if("pybind11" IN_LIST FEATURES)
# When BUILD_ONNX_PYTHON, we need Development component. Give a hint for FindPython3
list(APPEND FEATURE_OPTIONS
"-DPython3_ROOT_DIR=${CURRENT_INSTALLED_DIR}"
)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
-DPython3_EXECUTABLE=${PYTHON3}
"-DPython3_EXECUTABLE:FILEPATH=${PYTHON3}"
"-DONNX_CUSTOM_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}"
"-DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}"
-DONNX_ML=ON
-DONNX_GEN_PB_TYPE_STUBS=ON
-DONNX_USE_PROTOBUF_SHARED_LIBS=${USE_PROTOBUF_SHARED}
-DONNX_USE_LITE_PROTO=OFF
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
Expand All @@ -56,13 +43,8 @@ vcpkg_cmake_configure(
MAYBE_UNUSED_VARIABLES
ONNX_USE_MSVC_STATIC_RUNTIME
)

if("pybind11" IN_LIST FEATURES)
# This target is not in install/export
vcpkg_cmake_build(TARGET onnx_cpp2py_export)
endif()
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX)
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX PACKAGE_NAME ONNX)

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

Expand Down
16 changes: 2 additions & 14 deletions ports/onnx/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"name": "onnx",
"version-semver": "1.17.0",
"port-version": 1,
"description": "Open standard for machine learning interoperability",
"homepage": "https://onnx.ai",
"license": "Apache-2.0",
"supports": "!uwp",
"dependencies": [
"protobuf",
{
"name": "protobuf",
"host": true
},
{
"name": "python3",
"host": true
},
{
"name": "vcpkg-cmake",
"host": true
Expand All @@ -23,13 +19,5 @@
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"pybind11": {
"description": "Build Python binaries",
"dependencies": [
"pybind11"
]
}
}
]
}
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6610,11 +6610,11 @@
},
"onnx": {
"baseline": "1.17.0",
"port-version": 0
"port-version": 1
},
"onnx-optimizer": {
"baseline": "0.3.19",
"port-version": 0
"port-version": 1
},
"onnxruntime-gpu": {
"baseline": "1.19.2",
Expand Down
5 changes: 5 additions & 0 deletions versions/o-/onnx-optimizer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "df755dc18bda1d4c02a54db6cef63e46021ce872",
"version-semver": "0.3.19",
"port-version": 1
},
{
"git-tree": "126bfc519dc0c50fc52ed0b19a0bd88663bae87f",
"version-semver": "0.3.19",
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": "1ae91479c59de528eae6e6db5235b8ff0460e222",
"version-semver": "1.17.0",
"port-version": 1
},
{
"git-tree": "9849fadc0639a430cf9c49434b60cbeb08989112",
"version-semver": "1.17.0",
Expand Down