From 0226df59d673008d369013e835b69f3ebf4895aa Mon Sep 17 00:00:00 2001 From: Tatyana Vaneeva Date: Wed, 28 Aug 2024 16:11:15 +0200 Subject: [PATCH] [level-zero] added new recipe --- recipes/level-zero/all/conandata.yml | 9 ++ recipes/level-zero/all/conanfile.py | 95 +++++++++++++++++++ .../1.17.39/001-patch-remove-qspectre.patch | 17 ++++ .../all/test_package/CMakeLists.txt | 9 ++ .../level-zero/all/test_package/conanfile.py | 26 +++++ .../all/test_package/test_package.cpp | 5 + recipes/level-zero/config.yml | 3 + 7 files changed, 164 insertions(+) create mode 100644 recipes/level-zero/all/conandata.yml create mode 100644 recipes/level-zero/all/conanfile.py create mode 100644 recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch create mode 100644 recipes/level-zero/all/test_package/CMakeLists.txt create mode 100644 recipes/level-zero/all/test_package/conanfile.py create mode 100644 recipes/level-zero/all/test_package/test_package.cpp create mode 100644 recipes/level-zero/config.yml diff --git a/recipes/level-zero/all/conandata.yml b/recipes/level-zero/all/conandata.yml new file mode 100644 index 00000000000000..239ec80fcfb554 --- /dev/null +++ b/recipes/level-zero/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "1.17.39": + url: "https://github.com/oneapi-src/level-zero/archive/refs/tags/v1.17.39.tar.gz" + sha256: "70473c7262eee80dbe7c17974684ba9d3e34efc15ecba919b85e3cea7b1e180e" +patches: + "1.17.39": + - patch_file: "patches/1.17.39/001-patch-remove-qspectre.patch" + patch_description: "Removed /Qspectre" + patch_type: "portability" \ No newline at end of file diff --git a/recipes/level-zero/all/conanfile.py b/recipes/level-zero/all/conanfile.py new file mode 100644 index 00000000000000..abfe14b4701b64 --- /dev/null +++ b/recipes/level-zero/all/conanfile.py @@ -0,0 +1,95 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.env import VirtualBuildEnv +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps +from conan.tools.files import get, apply_conandata_patches, copy, export_conandata_patches +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +import os + + +class LevelZeroConan(ConanFile): + name = "level-zero" + license = "MIT" + homepage = "https://github.com/oneapi-src/level-zero" + url = "https://github.com/conan-io/conan-center-index" + description = "OneAPI Level Zero Specification Headers and Loader" + topics = ("api-headers", "loader", "level-zero", "oneapi") + package_type = "shared-library" + + # Binary configuration + settings = "os", "arch", "compiler", "build_type" + + @property + def _min_cppstd(self): + return 14 + + @property + def _compilers_minimum_version(self): + return { + "apple-clang": "10", + "clang": "7", + "gcc": "7", + "msvc": "190", + "Visual Studio": "15", + } + + def requirements(self): + self.requires("spdlog/1.14.1") + + def source(self): + version_data = self.conan_data["sources"][self.version] + get(self, **version_data, strip_root=True) + + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + cmake_layout(self, src_folder="src") + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + apply_conandata_patches(self) + deps = CMakeDeps(self) + deps.generate() + + toolchain = CMakeToolchain(self) + toolchain.generate() + + def validate(self): + if self.settings.os == "Macos": + raise ConanInvalidConfiguration("This recipe doesn't prepared for macOS.") + if self.settings.os == "Windows": + if self.settings.get_safe("subsystem") == "uwp": + raise ConanInvalidConfiguration(f"{self.ref} does not support UWP on Windows.") + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + 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." + ) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + + def package_info(self): + self.cpp_info.components["ze-loader"].libs = ["ze_loader"] + self.cpp_info.components["ze-loader"].includedirs = ["include", "include/level_zero"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["ze-loader"].system_libs = ["pthread"] + elif self.settings.os == "Windows": + self.cpp_info.components["ze-loader"].system_libs = ["cfgmgr32"] + self.cpp_info.components["ze-loader"].set_property("pkg_config_name", "libze_loader") + self.cpp_info.components["level-zero"].requires = ["ze-loader"] + self.cpp_info.components["level-zero"].set_property("pkg_config_name", "level-zero") + diff --git a/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch b/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch new file mode 100644 index 00000000000000..997ca7a844e962 --- /dev/null +++ b/recipes/level-zero/all/patches/1.17.39/001-patch-remove-qspectre.patch @@ -0,0 +1,17 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ac2ab9f..5282757 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -132,12 +132,6 @@ if(MSVC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf") + # enable Spectre Mitigation, not supported by clang-cl +- if((NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang) AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM)) +- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre") +- endif() +- if((NOT CMAKE_C_COMPILER_ID STREQUAL Clang) AND NOT (CMAKE_C_COMPILER_ID STREQUAL IntelLLVM)) +- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre") +- endif() + endif() + + #CXX compiler support diff --git a/recipes/level-zero/all/test_package/CMakeLists.txt b/recipes/level-zero/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..6b92e033f045aa --- /dev/null +++ b/recipes/level-zero/all/test_package/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.2.0) +project(test_package LANGUAGES CXX) + +find_package(level-zero CONFIG REQUIRED) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE level-zero::level-zero) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) \ No newline at end of file diff --git a/recipes/level-zero/all/test_package/conanfile.py b/recipes/level-zero/all/test_package/conanfile.py new file mode 100644 index 00000000000000..0ac491f64a94fb --- /dev/null +++ b/recipes/level-zero/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/level-zero/all/test_package/test_package.cpp b/recipes/level-zero/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..11a8c3580b4d2d --- /dev/null +++ b/recipes/level-zero/all/test_package/test_package.cpp @@ -0,0 +1,5 @@ +#include "ze_api.h" + +int main() { + zeInit(0); +} diff --git a/recipes/level-zero/config.yml b/recipes/level-zero/config.yml new file mode 100644 index 00000000000000..6cac94c96d3b82 --- /dev/null +++ b/recipes/level-zero/config.yml @@ -0,0 +1,3 @@ +versions: + "1.17.39": + folder: "all"