Skip to content

Commit

Permalink
[onnx-optimizer] Update to 0.3.19 (#299)
Browse files Browse the repository at this point in the history
* [onnx-optimizer] create a new port with 0.3.19

* https://github.com/onnx/optimizer/releases/tag/v0.3.19

* [onnx-optimizer] prepare 'python' feature support

* [onnx-optimizer] update baseline
  • Loading branch information
luncliff authored Nov 23, 2024
1 parent de5b848 commit 74c57aa
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ports/onnx-optimizer/fix-cmakelists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0063385..e9ad9ff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,7 +26,7 @@ if(NOT ONNX_OPT_USE_SYSTEM_PROTOBUF)
add_subdirectory_if_no_target(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake libprotobuf)
endif()

-
+find_package(ONNX CONFIG REQUIRED) # ONNX::onnx
set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx)
add_subdirectory_if_no_target(${ONNX_ROOT} ${ONNX_TARGET_NAME})

diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 6cca9f3..a735434 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -1,4 +1,10 @@
-include(${PROJECT_SOURCE_DIR}/third_party/onnx/cmake/Utils.cmake)
+function(add_msvc_runtime_flag lib)
+ if(ONNX_USE_MSVC_STATIC_RUNTIME)
+ target_compile_options(${lib} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MT> $<$<CONFIG:Debug>:/MTd>)
+ else()
+ target_compile_options(${lib} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MD> $<$<CONFIG:Debug>:/MDd>)
+ endif()
+endfunction()

# Poor man's FetchContent
function(add_subdirectory_if_no_target dir target)
65 changes: 65 additions & 0 deletions ports/onnx-optimizer/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO onnx/optimizer
REF "v${VERSION}"
SHA512 552d6fa261c3ce2db2e0938a5b5261676335bce9bd828b46a1e2631f3b362c748ae9a6cfe7d62072fc3774b3f506bc54aa5827b52241e6f48d78a08dea1d9316
HEAD_REF master
PATCHES
fix-cmakelists.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
python BUILD_ONNX_PYTHON
)

if("python" IN_LIST FEATURES)
x_vcpkg_get_python_packages(
PYTHON_VERSION 3
PACKAGES typing-extensions pyyaml numpy pybind11
OUT_PYTHON_VAR PYTHON3
)
message(STATUS "Using Python3: ${PYTHON3}")

function(get_python_site_packages PYTHON OUT_PATH)
execute_process(
COMMAND "${PYTHON}" -c "import site; print(site.getsitepackages()[0])"
OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${OUT_PATH} "${output}" PARENT_SCOPE)
endfunction()
get_python_site_packages("${PYTHON3}" SITE_PACKAGES_DIR)

get_filename_component(pybind11_DIR "${SITE_PACKAGES_DIR}/pybind11/share/cmake/pybind11" ABSOLUTE)
message(STATUS "Using pybind11: ${pybind11_DIR}")

list(APPEND FEATURE_OPTIONS
"-DPython_EXECUTABLE:FILEPATH=${PYTHON3}"
"-Dpybind11_DIR:PATH=${pybind11_DIR}"
)
endif()

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

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
-DONNX_OPT_USE_SYSTEM_PROTOBUF=ON
-DONNX_TARGET_NAME=ONNX::onnx
${FEATURE_OPTIONS}
MAYBE_UNUSED_VARIABLES
ONNX_USE_MSVC_STATIC_RUNTIME # use in add_msvc_runtime_flag
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup(PACKAGE_NAME ONNXOptimizer CONFIG_PATH lib/cmake/ONNXOptimizer)

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/include/onnxoptimizer/test"
)
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
18 changes: 18 additions & 0 deletions ports/onnx-optimizer/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "onnx-optimizer",
"version-semver": "0.3.19",
"description": "Actively maintained ONNX Optimizer",
"homepage": "https://github.com/onnx/optimizer",
"license": "Apache-2.0",
"dependencies": [
"onnx",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
"baseline": "1.16.2",
"port-version": 1
},
"onnx-optimizer": {
"baseline": "0.3.19",
"port-version": 0
},
"onnxruntime": {
"baseline": "1.20.0",
"port-version": 0
Expand Down
9 changes: 9 additions & 0 deletions versions/o-/onnx-optimizer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "e65b2debee538ecf4ff39347d3692a17d4ac9725",
"version-semver": "0.3.19",
"port-version": 0
}
]
}

0 comments on commit 74c57aa

Please sign in to comment.