Skip to content
Open
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
46 changes: 5 additions & 41 deletions recipes/onnx/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
sources:
"1.18.0":
url: "https://github.com/onnx/onnx/archive/v1.18.0.tar.gz"
sha256: "b466af96fd8d9f485d1bb14f9bbdd2dfb8421bc5544583f014088fb941a1d21e"
"1.17.0":
url: "https://github.com/onnx/onnx/archive/v1.17.0.tar.gz"
sha256: "8d5e983c36037003615e5a02d36b18fc286541bf52de1a78f6cf9f32005a820e"
"1.16.2":
url: "https://github.com/onnx/onnx/archive/v1.16.2.tar.gz"
sha256: "84fc1c3d6133417f8a13af6643ed50983c91dacde5ffba16cc8bb39b22c2acbb"
"1.16.1":
url: "https://github.com/onnx/onnx/archive/v1.16.1.tar.gz"
sha256: "0e6aa2c0a59bb2d90858ad0040ea1807117cc2f05b97702170f18e6cd6b66fb3"
"1.16.0":
url: "https://github.com/onnx/onnx/archive/v1.16.0.tar.gz"
sha256: "0ce153e26ce2c00afca01c331a447d86fbf21b166b640551fe04258b4acfc6a4"
"1.15.0":
url: "https://github.com/onnx/onnx/archive/v1.15.0.tar.gz"
sha256: "c757132e018dd0dd171499ef74fca88b74c5430a20781ec53da19eb7f937ef68"
"1.14.1":
url: "https://github.com/onnx/onnx/archive/v1.14.1.tar.gz"
sha256: "e296f8867951fa6e71417a18f2e550a730550f8829bd35e947b4df5e3e777aa1"
"1.14.0":
url: "https://github.com/onnx/onnx/archive/v1.14.0.tar.gz"
sha256: "1b02ad523f79d83f9678c749d5a3f63f0bcd0934550d5e0d7b895f9a29320003"
"1.13.1":
url: "https://github.com/onnx/onnx/archive/refs/tags/v1.13.1.tar.gz"
sha256: "090d3e10ec662a98a2a72f1bf053f793efc645824f0d4b779e0ce47468a0890e"
"1.20.0":
url: "https://github.com/onnx/onnx/archive/refs/tags/v1.20.0.tar.gz"
sha256: "e9e9273cd39d460348aa3e2eb370a444b510e138c5f45dfa86ce50461901257b"
patches:
"1.18.0":
- patch_file: "patches/0001-1.18.0-fix-protobuf-dependencies.patch"
"1.17.0":
- patch_description: "Fix CMakelist.txt to allow protobuf to get its own dependencies"
patch_file: "patches/0001-1.17.0-fix-protobuf-dependencies.patch"
"1.16.2":
- patch_description: "Fix CMakelist.txt to allow protobuf to get its own dependencies"
patch_file: "patches/0001-1.16.2-fix-protobuf-dependencies.patch"
"1.16.1":
- patch_description: "Fix CMakelist.txt to allow protobuf to get its own dependencies"
patch_file: "patches/0001-1.16.2-fix-protobuf-dependencies.patch"
"1.15.0":
- patch_description: "Fix CMakelist.txt to allow protobuf to get its own dependencies"
patch_file: "patches/0001-1.15.0-fix-protobuf-dependencies.patch"
"1.20.0":
- patch_file: "patches/cmake-absl-proto-targets.patch"
222 changes: 83 additions & 139 deletions recipes/onnx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os
import sys

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, save
from conan.tools.files import copy, get, rmdir, export_conandata_patches, apply_conandata_patches
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
import sys
import textwrap

required_conan_version = ">=1.60.0 <2.0 || >=2.0.5"
required_conan_version = ">=2.0.5"


class OnnxConan(ConanFile):
Expand All @@ -35,40 +32,6 @@ class OnnxConan(ConanFile):
"disable_static_registration": True,
}

@property
def _is_legacy_one_profile(self):
return not hasattr(self, "settings_build")

@property
def _min_cppstd(self):
if Version(self.version) >= "1.15.0":
return 17
if Version(self.version) >= "1.13.0" and is_msvc(self):
return 17
return 11

@property
def _compilers_minimum_version(self):
if Version(self.version) < "1.16.0":
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "7",
"clang": "5",
"apple-clang": "10",
}
# 1.16.0+ requires <filesystem> header available with gcc8+
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "8",
"clang": "5",
"apple-clang": "10",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -80,58 +43,47 @@ def configure(self):
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

def export_sources(self):
export_conandata_patches(self)

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True)
self.requires("protobuf/[>=4.25.3 <7]", transitive_headers=True, transitive_libs=True)
self.requires("abseil/[>=20230802.1 <=20250814.0]")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
if self._min_cppstd > 11:
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
check_min_cppstd(self, 17)

def build_requirements(self):
self.tool_requires("cmake/[>=3.18 <4]")
if not self._is_legacy_one_profile:
self.tool_requires("protobuf/<host_version>")
self.tool_requires("cmake/[>=3.18]")
self.tool_requires("protobuf/<host_version>")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if self._is_legacy_one_profile:
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = CMakeToolchain(self)
# https://cmake.org/cmake/help/v3.28/module/FindPythonInterp.html
# https://github.com/onnx/onnx/blob/1014f41f17ecc778d63e760a994579d96ba471ff/CMakeLists.txt#L119C1-L119C50
tc.variables["PYTHON_EXECUTABLE"] = sys.executable.replace("\\", "/")
tc.variables["ONNX_USE_PROTOBUF_SHARED_LIBS"] = self.dependencies.host["protobuf"].options.shared
tc.variables["BUILD_ONNX_PYTHON"] = False
tc.variables["ONNX_GEN_PB_TYPE_STUBS"] = False
tc.variables["ONNX_WERROR"] = False
tc.variables["ONNX_COVERAGE"] = False
tc.variables["ONNX_BUILD_TESTS"] = False
tc.variables["ONNX_USE_LITE_PROTO"] = self.dependencies.host["protobuf"].options.lite
tc.variables["ONNX_ML"] = True
tc.variables["ONNX_VERIFY_PROTO3"] = Version(self.dependencies.host["protobuf"].ref.version).major == "3"
tc.cache_variables["ONNX_USE_PROTOBUF_SHARED_LIBS"] = self.dependencies.host["protobuf"].options.shared
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.get_safe("shared", False)
tc.cache_variables["ONNX_BUILD_PYTHON"] = False
tc.cache_variables["ONNX_GEN_PB_TYPE_STUBS"] = False
tc.cache_variables["ONNX_WERROR"] = False
tc.cache_variables["ONNX_COVERAGE"] = False
tc.cache_variables["ONNX_BUILD_TESTS"] = False
tc.cache_variables["ONNX_USE_LITE_PROTO"] = self.dependencies.host["protobuf"].options.lite
tc.cache_variables["ONNX_ML"] = True
tc.cache_variables["ONNX_VERIFY_PROTO3"] = False
if is_msvc(self):
tc.variables["ONNX_USE_MSVC_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
tc.variables["ONNX_DISABLE_STATIC_REGISTRATION"] = self.options.get_safe('disable_static_registration')
tc.cache_variables["ONNX_USE_MSVC_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
tc.cache_variables["ONNX_DISABLE_STATIC_REGISTRATION"] = self.options.disable_static_registration
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()
Expand All @@ -143,70 +95,62 @@ def package(self):
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
fix_apple_shared_install_name(self)

# TODO: to remove in conan v2 once legacy generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{component["target"]:f"ONNX::{component['target']}" for component in self._onnx_components.values()}
)

def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""")
save(self, module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

@property
def _onnx_components(self):
components = {
"libonnx": {
"target": "onnx",
"libs": ["onnx"],
"defines": ["ONNX_NAMESPACE=onnx", "ONNX_ML=1"],
"requires": ["onnx_proto"]
},
"onnx_proto": {
"target": "onnx_proto",
"libs": ["onnx_proto"],
"defines": ["ONNX_NAMESPACE=onnx", "ONNX_ML=1"],
"requires": ["protobuf::libprotobuf"]
}
}
components["libonnx"]["defines"].append("__STDC_FORMAT_MACROS")
return components

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "ONNX")

def _register_components(components):
for comp_name, comp_values in components.items():
target = comp_values["target"]
libs = comp_values.get("libs", [])
defines = comp_values.get("defines", [])
requires = comp_values.get("requires", [])
system_libs = [l for cond, sys_libs in comp_values.get("system_libs", []) if cond for l in sys_libs]
self.cpp_info.components[comp_name].set_property("cmake_target_name", target)
self.cpp_info.components[comp_name].libs = libs
self.cpp_info.components[comp_name].defines = defines
self.cpp_info.components[comp_name].requires = requires
self.cpp_info.components[comp_name].system_libs = system_libs

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components[comp_name].names["cmake_find_package"] = target
self.cpp_info.components[comp_name].names["cmake_find_package_multi"] = target
self.cpp_info.components[comp_name].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components[comp_name].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]

_register_components(self._onnx_components)

# TODO: to remove in conan v2 once legacy generators removed
self.cpp_info.names["cmake_find_package"] = "ONNX"
self.cpp_info.names["cmake_find_package_multi"] = "ONNX"
requires = [
"protobuf::libprotobuf",
"abseil::absl_absl_check",
"abseil::absl_absl_log",
"abseil::absl_algorithm",
"abseil::absl_base",
"abseil::absl_bind_front",
"abseil::absl_bits",
"abseil::absl_btree",
"abseil::absl_cleanup",
"abseil::absl_cord",
"abseil::absl_core_headers",
"abseil::absl_debugging",
"abseil::absl_die_if_null",
"abseil::absl_dynamic_annotations",
"abseil::absl_flags",
"abseil::absl_flat_hash_map",
"abseil::absl_flat_hash_set",
"abseil::absl_function_ref",
"abseil::absl_hash",
"abseil::absl_layout",
"abseil::absl_log_initialize",
"abseil::absl_log_severity",
"abseil::absl_memory",
"abseil::absl_node_hash_map",
"abseil::absl_node_hash_set",
"abseil::absl_optional",
"abseil::absl_span",
"abseil::absl_status",
"abseil::absl_statusor",
"abseil::absl_strings",
"abseil::absl_synchronization",
"abseil::absl_time",
"abseil::absl_type_traits",
"abseil::absl_utility",
"abseil::absl_variant"
]
host_protobuf = self.dependencies.host["protobuf"]
if "utf8_range" in host_protobuf.cpp_info.components:
requires += ["protobuf::utf8_range", "protobuf::utf8_validity"]
defines = ["ONNX_NAMESPACE=onnx", "ONNX_ML=1"]
if self.options.disable_static_registration:
defines.append("__ONNX_DISABLE_STATIC_REGISTRATION")
if host_protobuf.options.lite:
defines.append("ONNX_USE_LITE_PROTO=1")
# onnx
self.cpp_info.components["libonnx"].set_property("cmake_target_name", "ONNX::onnx")
self.cpp_info.components["libonnx"].set_property("cmake_target_aliases", ["onnx"])
self.cpp_info.components["libonnx"].libs = ["onnx"]
self.cpp_info.components["libonnx"].defines = defines
self.cpp_info.components["libonnx"].requires = requires
# onnx_proto
self.cpp_info.components["onnx_proto"].set_property("cmake_target_name", "ONNX::onnx_proto")
self.cpp_info.components["onnx_proto"].set_property("cmake_target_aliases", ["onnx_proto"])
self.cpp_info.components["onnx_proto"].libs = ["onnx_proto"]
self.cpp_info.components["onnx_proto"].defines = defines
self.cpp_info.components["onnx_proto"].requires = requires

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading