diff --git a/recipes/dawn/all/conan_deps.cmake b/recipes/dawn/all/conan_deps.cmake new file mode 100644 index 0000000000000..8b80ea95cbe88 --- /dev/null +++ b/recipes/dawn/all/conan_deps.cmake @@ -0,0 +1,6 @@ +find_package(absl REQUIRED CONFIG) +find_package(glslang REQUIRED CONFIG) +find_package(glfw3 REQUIRED CONFIG) +find_package(SPIRV-Headers REQUIRED CONFIG) +find_package(Vulkan-Headers REQUIRED CONFIG) +find_package(VulkanUtilityHeaders REQUIRED CONFIG) diff --git a/recipes/dawn/all/conandata.yml b/recipes/dawn/all/conandata.yml new file mode 100644 index 0000000000000..1ba50f5479c46 --- /dev/null +++ b/recipes/dawn/all/conandata.yml @@ -0,0 +1,14 @@ +sources: + "cci.20240726": + url: "https://github.com/google/dawn/archive/076d076106a07f8a68ea7566f6b9f64fbe0c0687.tar.gz" + sha256: "14a4ecc52f7ec5acbbf2156a8b2f1c76a6950a86bb379812923ed1d043893c3d" +patches: + "cci.20240726": + - patch_file: "patches/0001-unvendor-third-party.patch" +spirv-tools-sources: + "1.3.290.0": + url: "https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/vulkan-sdk-1.3.290.0.tar.gz" + sha256: "8f8b487e20e062c3abfbc86c4541faf767588d167b395ec94f2a7f996ef40efe" + "1.3.268.0": + url: "https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/vulkan-sdk-1.3.268.0.tar.gz" + sha256: "4c19fdcffb5fe8ef8dc93d7a65ae78b64edc7a5688893ee381c57f70be77deaf" diff --git a/recipes/dawn/all/conanfile.py b/recipes/dawn/all/conanfile.py new file mode 100644 index 0000000000000..481ba427727ca --- /dev/null +++ b/recipes/dawn/all/conanfile.py @@ -0,0 +1,102 @@ +import os +from pathlib import Path + +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, rmdir, export_conandata_patches, apply_conandata_patches, save + +required_conan_version = ">=1.53.0" + + +class DawnConan(ConanFile): + name = "dawn" + description = ("Dawn is an open-source and cross-platform implementation of the work-in-progress WebGPU standard." + " It exposes a C/C++ API that maps almost one-to-one to the WebGPU IDL and" + " can be managed as part of a larger system such as a Web browser.") + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://dawn.googlesource.com/dawn" + topics = ("webgpu", "graphics", "gpgpu") + + package_type = "shared-library" + settings = "os", "arch", "compiler", "build_type" + + def export_sources(self): + export_conandata_patches(self) + copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("abseil/20240116.2") + self.requires("spirv-headers/1.3.290.0", transitive_headers=True) + self.requires("glslang/1.3.290.0") + self.requires("glfw/3.4") + self.requires("vulkan-headers/1.3.290.0") + self.requires("vulkan-utility-libraries/1.3.290.0") + self.requires("opengl-registry/20240721") + # Remove SPIRV-Tools from the dependency graph + self.requires("spirv-tools/1.3.290.0", headers=False, libs=False, visible=False) + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, 11) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + # Dawn uses SPIRV-Tools internals, so we need to provide a vendored version + get(self, **self.conan_data["spirv-tools-sources"][str(self.dependencies["spirv-tools"].ref.version)], strip_root=True, + destination=os.path.join(self.source_folder, "third_party", "spirv-tools", "src")) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["CMAKE_PROJECT_Dawn_INCLUDE"] = "conan_deps.cmake" + tc.variables["DAWN_BUILD_MONOLITHIC_LIBRARY"] = True # TODO: the default behavior, but might want to expose as an option + tc.variables["DAWN_ENABLE_INSTALL"] = True + tc.variables["DAWN_BUILD_SAMPLES"] = False + tc.variables["TINT_ENABLE_INSTALL"] = False + tc.variables["TINT_BUILD_TESTS"] = False + tc.variables["SPIRV_TOOLS_BUILD_STATIC"] = True + tc.variables["SPIRV-Headers_SOURCE_DIR"] = self.dependencies["spirv-headers"].package_folder.replace("\\", "/") + tc.variables["OPENGL_REGISTRY_DATA_DIR"] = self.dependencies["opengl-registry"].cpp_info.resdirs[0].replace("\\", "/") + tc.generate() + + deps = CMakeDeps(self) + deps.set_property("spirv-headers", "cmake_target_name", "SPIRV-Headers") + deps.set_property("glslang", "cmake_target_name", "glslang") + deps.set_property("glslang::glslang-default-resource-limits", "cmake_target_name", "glslang-default-resource-limits") + deps.set_property("glfw", "cmake_target_name", "glfw") + deps.set_property("vulkan-headers", "cmake_file_name", "Vulkan-Headers") + deps.set_property("vulkan-headers", "cmake_target_name", "Vulkan-Headers") + deps.set_property("vulkan-utility-libraries", "cmake_file_name", "VulkanUtilityHeaders") + deps.set_property("vulkan-utility-libraries::UtilityHeaders", "cmake_target_name", "VulkanUtilityHeaders") + deps.generate() + # Avoid conflicts with SPIRV-Tools target names + save(self, "SPIRV-ToolsConfig.cmake", "set(SPIRV-Tools_FOUND TRUE)") + + def _patch_sources(self): + apply_conandata_patches(self) + # Make sure everything is unvendored + for path in Path(self.source_folder, "third_party").iterdir(): + if path.is_dir() and path.name != "spirv-tools": + rmdir(self, path) + save(self, os.path.join(self.source_folder, "third_party", "vulkan-utility-libraries", "src", "CMakeLists.txt"), "") + + def build(self): + self._patch_sources() + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Dawn") + self.cpp_info.set_property("cmake_target_name", "dawn::webgpu_dawn") + self.cpp_info.libs = ["webgpu_dawn"] diff --git a/recipes/dawn/all/patches/0001-unvendor-third-party.patch b/recipes/dawn/all/patches/0001-unvendor-third-party.patch new file mode 100644 index 0000000000000..24dc19c03e02f --- /dev/null +++ b/recipes/dawn/all/patches/0001-unvendor-third-party.patch @@ -0,0 +1,26 @@ +diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt +--- a/src/dawn/native/CMakeLists.txt ++++ b/src/dawn/native/CMakeLists.txt +@@ -572,7 +572,7 @@ + SCRIPT "${Dawn_SOURCE_DIR}/generator/opengl_loader_generator.py" + PRINT_NAME "OpenGL function loader" + EXTRA_PARAMETERS "--gl-xml" +- "${Dawn_SOURCE_DIR}/third_party/khronos/OpenGL-Registry/xml/gl.xml" ++ "${OPENGL_REGISTRY_DATA_DIR}/xml/gl.xml" + "--supported-extensions" + "${Dawn_SOURCE_DIR}/src/dawn/native/opengl/supported_extensions.json" + OUTPUT_HEADERS DAWN_NATIVE_OPENGL_AUTOGEN_HEADERS +diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt +--- a/third_party/CMakeLists.txt ++++ b/third_party/CMakeLists.txt +@@ -132,8 +132,8 @@ + if (DAWN_ENABLE_DESKTOP_GL OR DAWN_ENABLE_OPENGLES) + # Header-only library for khrplatform.h + add_library(dawn_khronos_platform INTERFACE) +- target_sources(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api/KHR/khrplatform.h") +- target_include_directories(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api") ++ find_package(opengl-registry REQUIRED CONFIG) ++ target_link_libraries(dawn_khronos_platform INTERFACE opengl-registry::opengl-registry) + endif() + + if (NOT TARGET Vulkan-Headers AND DAWN_ENABLE_VULKAN) diff --git a/recipes/dawn/all/test_package/CMakeLists.txt b/recipes/dawn/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..89470b57279ca --- /dev/null +++ b/recipes/dawn/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(Dawn REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE dawn::webgpu_dawn) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/dawn/all/test_package/conanfile.py b/recipes/dawn/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3a91c9439218e --- /dev/null +++ b/recipes/dawn/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_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "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.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/dawn/all/test_package/test_package.cpp b/recipes/dawn/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..d6c5639752a18 --- /dev/null +++ b/recipes/dawn/all/test_package/test_package.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + wgpu::InstanceDescriptor instanceDescriptor{}; + wgpu::Instance instance = wgpu::CreateInstance(&instanceDescriptor); +} diff --git a/recipes/dawn/config.yml b/recipes/dawn/config.yml new file mode 100644 index 0000000000000..d316b260dbb70 --- /dev/null +++ b/recipes/dawn/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20240726": + folder: all