From b0d44efc79106715f03e196a23acf04808fe0c55 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 12 Apr 2026 22:25:42 +0000 Subject: [PATCH] Sirv-Cross Reviewed-on: https://git.romainboullard.com/BigfootDev/ConanPackages/pulls/9 Co-authored-by: Romain BOULLARD Co-committed-by: Romain BOULLARD --- .gitea/workflows/ci.yml | 1 + spirv-cross/all/conandata.yml | 38 ++++ spirv-cross/all/conanfile.py | 206 ++++++++++++++++++++ spirv-cross/all/test_package/CMakeLists.txt | 12 ++ spirv-cross/all/test_package/conanfile.py | 26 +++ spirv-cross/all/test_package/test_package.c | 15 ++ spirv-cross/config.yml | 25 +++ 7 files changed, 323 insertions(+) create mode 100644 spirv-cross/all/conandata.yml create mode 100644 spirv-cross/all/conanfile.py create mode 100644 spirv-cross/all/test_package/CMakeLists.txt create mode 100644 spirv-cross/all/test_package/conanfile.py create mode 100644 spirv-cross/all/test_package/test_package.c create mode 100644 spirv-cross/config.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index ec59fda..99f9df2 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: { name: "vulkan-headers", version: "1.4.341.0", location: "all" }, { name: "spirv-headers", version: "1.4.341.0", location: "all" }, + { name: "spirv-cross", version: "1.4.341.0", location: "all" }, { name: "pixelmatch-cpp17", version: "1.0.3", location: "all" }, { name: "lodepng", version: "cci.20260210", location: "all" }, diff --git a/spirv-cross/all/conandata.yml b/spirv-cross/all/conandata.yml new file mode 100644 index 0000000..5658344 --- /dev/null +++ b/spirv-cross/all/conandata.yml @@ -0,0 +1,38 @@ +sources: + "1.4.341.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.4.341.0.tar.gz" + sha256: "b2665ac9ddb65ff75a7ca2f6d410e73da443692742a1e3a5b7728ca6069a400c" + "1.4.321.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.4.321.0.tar.gz" + sha256: "6037555620c27105bf1d4068a6eeb4b0d7953630d556a1ca9799dfe06fd2fb68" + "1.4.313.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.4.313.0.tar.gz" + sha256: "7d1de24918bea9897753f7561d4d154f68ec89c36bb70c13598222b8039d4212" + "1.4.309.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.4.309.0.tar.gz" + sha256: "cf4f12a767d63f63024e61750e372ffdc95567513b99ed9be6f21f474b328ddd" + "1.3.296.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.3.296.0.tar.gz" + sha256: "4f7f9a8a643e6694f155712016b9b572c13a9444e65b3f43b27bb464c0ab76e0" + "1.3.268.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/vulkan-sdk-1.3.268.0.tar.gz" + sha256: "dd656a51ba4c229c1a0bb220b7470723e8fd4b68abb7f2cf2ca4027df824f4a0" + "1.3.261.1": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/sdk-1.3.261.1.tar.gz" + sha256: "a5cf99ed62e93800232e50b782890321d4d7e053dcaa71bd8efc0c48a00bd1dd" + "1.3.250.1": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/sdk-1.3.250.1.tar.gz" + sha256: "5b7402d7078eeffca0926875b1dcd0f5dd78791a30529de7c8456686f6fc52ce" + "1.3.246.1": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/sdk-1.3.246.1.tar.gz" + sha256: "44d1aef7e6e247b4b7ec6a1ef0bbb43cc9b681ee689393db90ac815d240808b1" + "1.3.243.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/sdk-1.3.243.0.tar.gz" + sha256: "549fff809de2b3484bcc5d710ccd76ca29cbd764dd304c3687252e2f3d034e06" + "1.3.239.0": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/refs/tags/sdk-1.3.239.0.tar.gz" + sha256: "a1695022880e7ef3c2d407647f79876045dc2a3ed012753adc71ead5cc5178ba" + # commit used in Vulkan SDK 1.2.198.0 + "cci.20211113": + url: "https://github.com/KhronosGroup/SPIRV-Cross/archive/7c3cb0b12c9965497b08403c82ac1b82846fa7be.tar.gz" + sha256: "5bb6837e2b75db1a9e36e7d6eac40d905e3460ff3b5234f391adc6bdf6aadcdf" diff --git a/spirv-cross/all/conanfile.py b/spirv-cross/all/conanfile.py new file mode 100644 index 0000000..d98d3ab --- /dev/null +++ b/spirv-cross/all/conanfile.py @@ -0,0 +1,206 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import stdcpp_library +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, save +import os +import textwrap + +required_conan_version = ">=1.54.0" + + +class SpirvCrossConan(ConanFile): + name = "spirv-cross" + description = "SPIRV-Cross is a practical tool and library for performing " \ + "reflection on SPIR-V and disassembling SPIR-V back to high level languages." + license = "Apache-2.0" + topics = ("reflection", "disassembler", "spirv", "spir-v", "glsl", "hlsl") + homepage = "https://github.com/KhronosGroup/SPIRV-Cross" + url = "https://github.com/conan-io/conan-center-index" + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "build_executable": [True, False], + "exceptions": [True, False], + "glsl": [True, False], + "hlsl": [True, False], + "msl": [True, False], + "cpp": [True, False], + "reflect": [True, False], + "c_api": [True, False], + "util": [True, False], + "namespace": ["ANY"], + } + default_options = { + "shared": False, + "fPIC": True, + "build_executable": True, + "exceptions": True, + "glsl": True, + "hlsl": True, + "msl": True, + "cpp": True, + "reflect": True, + "c_api": True, + "util": True, + "namespace": "spirv_cross", + } + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + # these options don't contribute to shared binary + del self.options.c_api + del self.options.util + + def layout(self): + cmake_layout(self, src_folder="src") + + def validate(self): + if not self.options.glsl and \ + (self.options.hlsl or self.options.msl or self.options.cpp or self.options.reflect): + raise ConanInvalidConfiguration("hlsl, msl, cpp and reflect require glsl enabled") + + if self.options.build_executable and \ + not (self.options.glsl and self.options.hlsl and self.options.msl and + self.options.cpp and self.options.reflect and self.options.get_safe("util", True)): + raise ConanInvalidConfiguration("executable can't be built without glsl, hlsl, msl, cpp, reflect and util") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS"] = not self.options.exceptions + tc.variables["SPIRV_CROSS_SHARED"] = self.options.shared + tc.variables["SPIRV_CROSS_STATIC"] = not self.options.shared or self.options.build_executable + tc.variables["SPIRV_CROSS_CLI"] = self.options.build_executable + tc.variables["SPIRV_CROSS_ENABLE_TESTS"] = False + tc.variables["SPIRV_CROSS_ENABLE_GLSL"] = self.options.glsl + tc.variables["SPIRV_CROSS_ENABLE_HLSL"] = self.options.hlsl + tc.variables["SPIRV_CROSS_ENABLE_MSL"] = self.options.msl + tc.variables["SPIRV_CROSS_ENABLE_CPP"] = self.options.cpp + tc.variables["SPIRV_CROSS_ENABLE_REFLECT"] = self.options.reflect + tc.variables["SPIRV_CROSS_ENABLE_C_API"] = self.options.get_safe("c_api", True) + tc.variables["SPIRV_CROSS_ENABLE_UTIL"] = self.options.get_safe("util", False) or self.options.build_executable + tc.variables["SPIRV_CROSS_SKIP_INSTALL"] = False + tc.variables["SPIRV_CROSS_FORCE_PIC"] = self.options.get_safe("fPIC", True) + tc.variables["SPIRV_CROSS_NAMESPACE_OVERRIDE"] = self.options.namespace + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.ilk", os.path.join(self.package_folder, "bin")) + rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + if self.options.shared and self.options.build_executable: + for static_lib in [ + "spirv-cross-core", "spirv-cross-glsl", "spirv-cross-hlsl", "spirv-cross-msl", + "spirv-cross-cpp", "spirv-cross-reflect", "spirv-cross-c", "spirv-cross-util", + ]: + rm(self, f"*{static_lib}.*", os.path.join(self.package_folder, "lib")) + + # 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), + {target: f"spirv-cross::{target}" for target in self._spirv_cross_components.keys()}, + ) + + 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 _spirv_cross_components(self): + components = {} + if self.options.shared: + components.update({"spirv-cross-c-shared": []}) + else: + components.update({"spirv-cross-core": []}) + if self.options.glsl: + components.update({"spirv-cross-glsl": ["spirv-cross-core"]}) + if self.options.hlsl: + components.update({"spirv-cross-hlsl": ["spirv-cross-glsl"]}) + if self.options.msl: + components.update({"spirv-cross-msl": ["spirv-cross-glsl"]}) + if self.options.cpp: + components.update({"spirv-cross-cpp": ["spirv-cross-glsl"]}) + if self.options.reflect: + components.update({"spirv-cross-reflect": []}) + if self.options.c_api: + c_api_requires = [] + if self.options.glsl: + c_api_requires.append("spirv-cross-glsl") + if self.options.hlsl: + c_api_requires.append("spirv-cross-hlsl") + if self.options.msl: + c_api_requires.append("spirv-cross-msl") + if self.options.cpp: + c_api_requires.append("spirv-cross-cpp") + if self.options.reflect: + c_api_requires.append("spirv-cross-reflect") + components.update({"spirv-cross-c": c_api_requires}) + if self.options.util: + components.update({"spirv-cross-util": ["spirv-cross-core"]}) + return components + + def package_info(self): + # FIXME: we should provide one CMake config file per target (waiting for an implementation of https://github.com/conan-io/conan/issues/9000) + def _register_component(target_lib, requires): + self.cpp_info.components[target_lib].set_property("cmake_target_name", target_lib) + if self.options.shared: + self.cpp_info.components[target_lib].set_property("pkg_config_name", target_lib) + prefix = "d" if self.settings.os == "Windows" and self.settings.build_type == "Debug" else "" + self.cpp_info.components[target_lib].libs = [f"{target_lib}{prefix}"] + self.cpp_info.components[target_lib].includedirs.append(os.path.join("include", "spirv_cross")) + self.cpp_info.components[target_lib].defines.append(f"SPIRV_CROSS_NAMESPACE_OVERRIDE={self.options.namespace}") + self.cpp_info.components[target_lib].requires = requires + if self.settings.os in ["Linux", "FreeBSD"] and self.options.glsl: + self.cpp_info.components[target_lib].system_libs.append("m") + if not self.options.shared and self.options.c_api: + libcxx = stdcpp_library(self) + if libcxx: + self.cpp_info.components[target_lib].system_libs.append(libcxx) + + # TODO: to remove in conan v2 once legacy generators removed + self.cpp_info.components[target_lib].names["cmake_find_package"] = target_lib + self.cpp_info.components[target_lib].names["cmake_find_package_multi"] = target_lib + self.cpp_info.components[target_lib].build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.components[target_lib].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] + + for target_lib, requires in self._spirv_cross_components.items(): + _register_component(target_lib, requires) + + # TODO: to remove in conan v2 once legacy generators removed + if self.options.build_executable: + self.env_info.PATH.append(os.path.join(self.package_folder, "bin")) diff --git a/spirv-cross/all/test_package/CMakeLists.txt b/spirv-cross/all/test_package/CMakeLists.txt new file mode 100644 index 0000000..c3b57d8 --- /dev/null +++ b/spirv-cross/all/test_package/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +# FIXME: this is not the official way to find spirv-cross components +find_package(spirv-cross REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +if(TARGET spirv-cross-c) + target_link_libraries(${PROJECT_NAME} PRIVATE spirv-cross-c) +elseif(TARGET spirv-cross-c-shared) + target_link_libraries(${PROJECT_NAME} PRIVATE spirv-cross-c-shared) +endif() diff --git a/spirv-cross/all/test_package/conanfile.py b/spirv-cross/all/test_package/conanfile.py new file mode 100644 index 0000000..0a6bc68 --- /dev/null +++ b/spirv-cross/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, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + 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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/spirv-cross/all/test_package/test_package.c b/spirv-cross/all/test_package/test_package.c new file mode 100644 index 0000000..dd59cdc --- /dev/null +++ b/spirv-cross/all/test_package/test_package.c @@ -0,0 +1,15 @@ +#include + +#include + +int main() { + spvc_context context; + spvc_context_create(&context); + spvc_context_destroy(context); + + unsigned major, minor, patch; + spvc_get_version(&major, &minor, &patch); + printf("SPIRV-Cross: C API version %u.%u.%u\n", major, minor, patch); + + return 0; +} diff --git a/spirv-cross/config.yml b/spirv-cross/config.yml new file mode 100644 index 0000000..2bd9418 --- /dev/null +++ b/spirv-cross/config.yml @@ -0,0 +1,25 @@ +versions: + "1.4.341.0": + folder: all + "1.4.321.0": + folder: all + "1.4.313.0": + folder: all + "1.4.309.0": + folder: all + "1.3.296.0": + folder: all + "1.3.268.0": + folder: all + "1.3.261.1": + folder: all + "1.3.250.1": + folder: all + "1.3.246.1": + folder: all + "1.3.243.0": + folder: all + "1.3.239.0": + folder: all + "cci.20211113": + folder: all