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] create a new port #18073

Merged
merged 19 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions ports/onnx/fix-cmakelists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 628dcaa..300e4ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,8 +111,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)
-find_package(PythonInterp ${PY_VERSION} REQUIRED)
-find_package(PythonLibs ${PY_VERSION})
+find_package(Python3 ${PY_VERSION} COMPONENTS Interpreter REQUIRED)
+set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})

if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
@@ -422,6 +422,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")
@@ -441,10 +442,13 @@ if(BUILD_ONNX_PYTHON)
$<BUILD_INTERFACE:${ONNX_ROOT}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
- ${PYTHON_INCLUDE_DIR})
-
+ ${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)
+ find_package(pybind11 2.2 CONFIG REQUIRED)
if(pybind11_FOUND)
target_include_directories(onnx_cpp2py_export PUBLIC
${pybind11_INCLUDE_DIRS})
@@ -687,6 +691,27 @@ endif()

include(GNUInstallDirs)

+# install protobuf files
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-data.proto
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-data.proto3
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-ml.proto
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-ml.proto3
+ ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-operators-ml.proto
+ ${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()
+
install(DIRECTORY ${ONNX_ROOT}/onnx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
98 changes: 98 additions & 0 deletions ports/onnx/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# uwp: LOAD_LIBRARY_SEARCH_DEFAULT_DIRS undefined identifier
vcpkg_fail_port_install(ON_TARGET "uwp")
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO onnx/onnx
REF v1.9.0
SHA512 a3eecc74ce4f22524603fb86367d21c87a143ba27eef93ef4bd2e2868c2cadeb724b84df58a429286e7824adebdeba7fa059095b7ab29df8dcea8777bd7f4101
PATCHES
fix-cmakelists.patch
wrap-onnxifi-targets.patch
)

if(VCPKG_TARGET_IS_WINDOWS)
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME)
list(APPEND PLATFORM_OPTIONS
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
)
endif()

# 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)
if(PROTOBUF_LIBNAME MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(USE_PROTOBUF_SHARED ON)
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 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} ${PLATFORM_OPTIONS}
-DPython3_EXECUTABLE=${PYTHON3}
-DONNX_ML=ON
-DONNX_GEN_PB_TYPE_STUBS=ON
-DONNX_USE_PROTOBUF_SHARED_LIBS=${USE_PROTOBUF_SHARED}
-DONNX_USE_LITE_PROTO=OFF
-DONNXIFI_ENABLE_EXT=OFF
-DONNX_BUILD_TESTS=OFF
-DONNX_BUILD_BENCHMARKS=OFF
)

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)

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
# the others are empty
"${CURRENT_PACKAGES_DIR}/include/onnx/onnx_ml"
"${CURRENT_PACKAGES_DIR}/include/onnx/onnx_data"
"${CURRENT_PACKAGES_DIR}/include/onnx/onnx_operators_ml"
"${CURRENT_PACKAGES_DIR}/include/onnx/onnx_cpp2py_export"
"${CURRENT_PACKAGES_DIR}/include/onnx/backend"
"${CURRENT_PACKAGES_DIR}/include/onnx/tools"
"${CURRENT_PACKAGES_DIR}/include/onnx/test"
"${CURRENT_PACKAGES_DIR}/include/onnx/bin"
"${CURRENT_PACKAGES_DIR}/include/onnx/examples"
"${CURRENT_PACKAGES_DIR}/include/onnx/frontend"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/controlflow"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/generator"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/logical"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/math"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/nn"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/object_detection"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/quantization"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/reduction"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/rnn"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/sequence"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/traditionalml"
"${CURRENT_PACKAGES_DIR}/include/onnx/defs/training"
)
luncliff marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions ports/onnx/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "onnx",
"version-semver": "1.9.0",
"description": "Open standard for machine learning interoperability",
"homepage": "https://onnx.ai",
"supports": "!uwp",
"dependencies": [
"protobuf",
{
"name": "protobuf",
"host": true
},
{
"name": "python3",
"host": true
},
Comment on lines +13 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being added because of vcpkg_find_acquire_program(PYTHON3), or is there some other use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part is for find_package(Python3 COMPONENTS Interpreter). And for cross compile scenario, it uses find_package(Python3 COMPONENTS Development). The dependency is solved by pybind11.

{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"pybind11": {
"description": "Build Python binaries",
"dependencies": [
"pybind11"
]
}
}
}
44 changes: 44 additions & 0 deletions ports/onnx/wrap-onnxifi-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 300e4ea..155dd0d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -614,6 +614,7 @@ if(APPLE)
set_target_properties(onnx PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()

+if(ONNXIFI_ENABLE_EXT)
# ---[ ONNX Interface for Framework Integratin (ONNXIFI)
add_library(onnxifi INTERFACE)
target_include_directories(onnxifi INTERFACE
@@ -688,6 +689,7 @@ if(MSVC)
# lists from 'identifier2'
)
endif()
+endif() # ONNXIFI_ENABLE_EXT

include(GNUInstallDirs)

@@ -737,8 +739,14 @@ install(FILES
install(EXPORT ONNXTargets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ONNX")
install(TARGETS
onnx onnx_proto
- onnxifi onnxifi_dummy onnxifi_loader
EXPORT ONNXTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})
+if(ONNXIFI_ENABLE_EXT)
+ install(TARGETS
+ onnxifi onnxifi_dummy onnxifi_loader
+ EXPORT ONNXTargets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(NOT ANDROID AND NOT IOS)
install(TARGETS onnxifi_wrapper
@@ -748,6 +756,7 @@ endif()
if(ONNXIFI_DUMMY_BACKEND)
add_definitions(-DONNXIFI_DUMMY_BACKEND=1)
endif()
+endif() # ONNXIFI_ENABLE_EXT

if(ONNX_BUILD_TESTS)
include(${ONNX_ROOT}/cmake/unittest.cmake)
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,10 @@
"baseline": "6.9.4",
"port-version": 0
},
"onnx": {
"baseline": "1.9.0",
"port-version": 0
},
"onnxruntime-gpu": {
"baseline": "1.5.1",
"port-version": 0
Expand Down
9 changes: 9 additions & 0 deletions versions/o-/onnx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "b53c9c9e969928def925c57ea5ddcdfb09293693",
"version-semver": "1.9.0",
"port-version": 0
}
]
}