From 6da2b35b60aee8086c7ad1ee1c1492ed5e730a92 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 2 Aug 2021 12:17:38 +0200 Subject: gnu: Add onnx-optimizer. * gnu/packages/machine-learning.scm (onnx-optimizer): New variable. * gnu/packages/patches/onnx-optimizer-system-library.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. --- .../patches/onnx-optimizer-system-library.patch | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 gnu/packages/patches/onnx-optimizer-system-library.patch (limited to 'gnu/packages/patches') diff --git a/gnu/packages/patches/onnx-optimizer-system-library.patch b/gnu/packages/patches/onnx-optimizer-system-library.patch new file mode 100644 index 0000000000..5c592597e0 --- /dev/null +++ b/gnu/packages/patches/onnx-optimizer-system-library.patch @@ -0,0 +1,53 @@ +Arrange so that onnx-optimizer (1) uses our own ONNX build, +(2) builds as a shared library, and (3) links against the shared +libraries of ONNX. + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c2e48b35..8af51076 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,8 +9,6 @@ endif(NOT MSVC) + + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +-set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx) +-add_subdirectory(${ONNX_ROOT}) + + file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" ONNX_OPTIMIZER_VERSION) + string(STRIP "${ONNX_OPTIMIZER_VERSION}" ONNX_OPTIMIZER_VERSION) +@@ -21,14 +19,18 @@ file(GLOB_RECURSE onnx_opt_srcs "onnxoptimizer/*.cc" + list(REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR}/onnxoptimizer/cpp2py_export.cc") + + add_library(onnx_optimizer ${onnx_opt_srcs}) +-target_link_libraries(onnx_optimizer PUBLIC onnx) ++target_link_libraries(onnx_optimizer PUBLIC onnx onnx_proto) + target_include_directories(onnx_optimizer PUBLIC + $ + $ + ) + ++# These cpp macros must be defined so the ONNX headers behave ++# correctly. ++set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DONNX_ML=1 -DONNX_NAMESPACE=onnx") ++ + add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp) +-target_link_libraries(onnx_optimizer_exec onnx_optimizer) ++target_link_libraries(onnx_optimizer_exec onnx_optimizer protobuf) + + if(BUILD_ONNX_PYTHON) + if("${PY_EXT_SUFFIX}" STREQUAL "") +@@ -79,11 +81,10 @@ if(BUILD_ONNX_PYTHON) + PRIVATE $) + else() + # Assume everything else is like gcc +- target_link_libraries(onnx_opt_cpp2py_export +- PRIVATE "-Wl,--whole-archive" $ +- "-Wl,--no-whole-archive") ++ target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer) + set_target_properties(onnx_opt_cpp2py_export +- PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL") ++ PROPERTIES LINK_FLAGS ++ "-Wl,-rpath=${CMAKE_INSTALL_PREFIX}/lib") + endif() + + target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer) -- cgit v1.2.3