Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shaderc: migrate to Conan v2, simplify patching, add v2023.6 #18807

Merged
merged 10 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 0 additions & 7 deletions recipes/shaderc/all/CMakeLists.txt

This file was deleted.

32 changes: 22 additions & 10 deletions recipes/shaderc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
sources:
"2023.6":
url: "https://github.com/google/shaderc/archive/refs/tags/v2023.6.tar.gz"
sha256: "e40fd4a87a56f6610e223122179f086d5c4f11a7e0e2aa461f0325c3a0acc6ae"
"2021.1":
url: "https://github.com/google/shaderc/archive/v2021.1.tar.gz"
sha256: "047113bc4628da164a3cb845efc20d442728873f6054a68ab56d04a053f2c32b"
"2019.0":
url: "https://github.com/google/shaderc/archive/v2019.0.tar.gz"
sha256: "1018cd02be52295272fdbffa056ee24b881be277c83d039ad554d91230f4e11b"
patches:
"2023.6":
- patch_file: "patches/2023.6/use-conan-dependencies.patch"
patch_description: "Replace third_party with Conan dependencies"
patch_type: "conan"
- patch_file: "patches/2021.1/adapt-update_build_version.py.patch"
patch_description: "Adapt update_build_version.py for Conan"
patch_type: "conan"
- patch_file: "patches/2021.1/install-shaderc_util.patch"
patch_description: "install() shaderc_util"
patch_type: "conan"
"2021.1":
- patch_file: "patches/2021.1/fix-cmake.patch"
base_path: "source_subfolder"
"2019.0":
- patch_file: "patches/2019.0/fix-cmake.patch"
base_path: "source_subfolder"
- patch_file: "patches/2019.0/fix-spvc.patch"
base_path: "source_subfolder"
- patch_file: "patches/2021.1/use-conan-dependencies.patch"
patch_description: "Replace third_party with Conan dependencies"
patch_type: "conan"
- patch_file: "patches/2021.1/adapt-update_build_version.py.patch"
patch_description: "Adapt update_build_version.py for Conan"
patch_type: "conan"
- patch_file: "patches/2021.1/install-shaderc_util.patch"
patch_description: "install() shaderc_util"
patch_type: "conan"
163 changes: 84 additions & 79 deletions recipes/shaderc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,131 +1,136 @@
from conans import ConanFile, CMake, tools
import os

required_conan_version = ">=1.36.0"
from conan import ConanFile
from conan.tools.build import check_min_cppstd, stdcpp_library
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime

required_conan_version = ">=1.53.0"


class ShadercConan(ConanFile):
name = "shaderc"
description = "A collection of tools, libraries and tests for shader compilation."
license = "Apache-2.0"
topics = ("glsl", "hlsl", "msl", "spirv", "spir-v", "glslc", "spvc")
homepage = "https://github.com/google/shaderc"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/google/shaderc"
topics = ("glsl", "hlsl", "msl", "spirv", "spir-v", "glslc")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"spvc": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"spvc": False,
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if tools.Version(self.version) >= "2020.4":
del self.options.spvc

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

@property
def _get_compatible_spirv_tools_version(self):
return {
"2021.1": "2021.2",
"2019.0": "2020.5"
}.get(str(self.version), False)
def layout(self):
cmake_layout(self, src_folder="src")

@property
def _get_compatible_glslang_version(self):
def _spirv_version(self):
return {
"2021.1": "11.5.0",
"2019.0": "8.13.3559"
}.get(str(self.version), False)
# TODO: bump me once newer versions are available on CCI
# "2023.6": "1.3.261.1",
"2023.6": "1.3.239.0",
"2021.1": "1.3.224.0",
}[str(self.version)]

def requirements(self):
self.requires("glslang/{}".format(self._get_compatible_glslang_version))
self.requires("spirv-tools/{}".format(self._get_compatible_spirv_tools_version))
if self.options.get_safe("spvc", False):
self.requires("spirv-cross/20210115")
# transitive_headers=True is not required for any of the dependencies
self.requires(f"glslang/{self._spirv_version}")
self.requires(f"spirv-tools/{self._spirv_version}")
self.requires(f"spirv-headers/{self._spirv_version}")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)

def build_requirements(self):
self.tool_requires("cmake/[>=3.17.2 <4]")

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

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

tc = CMakeToolchain(self)
tc.cache_variables["SHADERC_SKIP_INSTALL"] = False
tc.cache_variables["SHADERC_SKIP_EXAMPLES"] = True
tc.cache_variables["SHADERC_SKIP_TESTS"] = True
tc.cache_variables["ENABLE_CODE_COVERAGE"] = False
tc.cache_variables["SHADERC_ENABLE_WERROR_COMPILE"] = False
if is_msvc(self):
tc.cache_variables["SHADERC_ENABLE_SHARED_CRT"] = not is_msvc_static_runtime(self)
tc.generate()

self.dependencies["glslang"].cpp_info.components["glslang-core"].includedirs.append(
os.path.join(self.dependencies["glslang"].package_folder, "include", "glslang")
)

deps = CMakeDeps(self)
deps.set_property("glslang::glslang-core", "cmake_target_name", "glslang")
deps.set_property("glslang::osdependent", "cmake_target_name", "OSDependent")
deps.set_property("glslang::oglcompiler", "cmake_target_name", "OGLCompiler")
deps.set_property("glslang::hlsl", "cmake_target_name", "HLSL")
deps.set_property("glslang::spirv", "cmake_target_name", "SPIRV")
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
self._cmake.definitions["SHADERC_ENABLE_SPVC"] = self.options.get_safe("spvc", False)
self._cmake.definitions["SHADERC_SKIP_INSTALL"] = False
self._cmake.definitions["SHADERC_SKIP_TESTS"] = True
self._cmake.definitions["SHADERC_SPVC_ENABLE_DIRECT_LOGGING"] = False
self._cmake.definitions["SHADERC_SPVC_DISABLE_CONTEXT_LOGGING"] = False
self._cmake.definitions["SHADERC_ENABLE_WERROR_COMPILE"] = False
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["SHADERC_ENABLE_SHARED_CRT"] = str(self.settings.compiler.runtime).startswith("MD")
self._cmake.definitions["ENABLE_CODE_COVERAGE"] = False
if tools.is_apple_os(self.settings.os):
self._cmake.definitions["CMAKE_MACOSX_BUNDLE"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "shaderc" if self.options.shared else "shaderc_static")
self.cpp_info.libs = self._get_ordered_libs()
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
if not self.options.shared and tools.stdcpp_library(self):
self.cpp_info.system_libs.append(tools.stdcpp_library(self))
if self.options.shared:
self.cpp_info.set_property("pkg_config_name", "shaderc")
self.cpp_info.libs = ["shaderc_shared"]
self.cpp_info.defines.append("SHADERC_SHAREDLIB")
else:
self.cpp_info.set_property("pkg_config_name", "shaderc_static")
self.cpp_info.libs = ["shaderc", "shaderc_util"]
if stdcpp_library(self):
self.cpp_info.system_libs.append(stdcpp_library(self))

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")

self.cpp_info.requires = [
"glslang::glslang-core",
"glslang::osdependent",
"glslang::oglcompiler",
"glslang::hlsl",
"glslang::spirv",
"spirv-tools::spirv-tools-core",
"spirv-tools::spirv-tools-opt",
"spirv-headers::spirv-headers"
]

# TODO: to remove in conan v2
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)

def _get_ordered_libs(self):
libs = ["shaderc_shared" if self.options.shared else "shaderc"]
if not self.options.shared:
libs.append("shaderc_util")
if self.options.get_safe("spvc", False):
libs.append("shaderc_spvc_shared" if self.options.shared else "shaderc_spvc")
return libs
Loading
Loading