# This file defines the Bazel targets used to build Upstream Dawn inside Skia. # It loads flat file lists generated by generate_dawn_files.py and combines them # under platform-specific rules similar to Dawn's native CMake build. # # Core Assumptions: # 1. Unconditional Parsing: generate_dawn_files.py ignores CMake conditionals (if/else) to # remain immune to changes in upstream build logic. # 2. Directory Routing: Flat file lists are routed to platform suffixes (Vulkan, Metal, etc.) # using directory path keywords (e.g., '/vulkan/', '/metal/'), exploiting Dawn's highly # standardized directory structure. # 3. Transitive Header Visibility: To prevent duplicate C++ compiles and bypass Bazel's # strict extension constraints in objc_library targets (failing on inline .inl/.inc files), # we split files strictly into _SRCS and _PRIV_HDRS. Private headers are encapsulated # in helper cc_library targets (e.g. :dawn_native_headers), propagating them transitively # to macOS/iOS objc_library compile sandboxes. # 4. Backend Exclusions: Null (/null/) and WebGPU-on-WebGPU (/webgpu/) subdirectories are # routed to separate suffixes and excluded from compilation to avoid compile-time # dependencies on uncompiled Tint compiler components. load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:objc_library.bzl", "objc_library") load("@rules_python//python:defs.bzl", "py_binary") load( ":dawn_files.bzl", "COMMON_APPLE_PRIV_HDRS", "COMMON_APPLE_SRCS", "COMMON_PRIV_HDRS", "COMMON_SRCS", "COMMON_WIN32_PRIV_HDRS", "COMMON_WIN32_SRCS", "DAWNCPP_HEADERS_GEN_PRIV_HDRS", "DAWNCPP_HEADERS_WEBGPU_HDRS", "DAWNPROC_GEN_SRCS", "GPU_INFO_AUTOGEN_PRIV_HDRS", "GPU_INFO_AUTOGEN_SRCS", "HEADERS_GEN_PRIV_HDRS", "HEADERS_WEBGPU_HDRS", "NATIVE_D3D_SRCS", "NATIVE_OBJECTS_D3D_HDRS", "NATIVE_OBJECTS_D3D_PRIV_HDRS", "NATIVE_OBJECTS_D3D_SRCS", "NATIVE_OBJECTS_HDRS", "NATIVE_OBJECTS_METAL_PRIV_HDRS", "NATIVE_OBJECTS_METAL_SRCS", "NATIVE_OBJECTS_OPENGL_PRIV_HDRS", "NATIVE_OBJECTS_OPENGL_SRCS", "NATIVE_OBJECTS_PRIV_HDRS", "NATIVE_OBJECTS_SRCS", "NATIVE_OBJECTS_UNIX_PRIV_HDRS", "NATIVE_OBJECTS_UNIX_SRCS", "NATIVE_OBJECTS_USE_X11_PRIV_HDRS", "NATIVE_OBJECTS_USE_X11_SRCS", "NATIVE_OBJECTS_VULKAN_PRIV_HDRS", "NATIVE_OBJECTS_VULKAN_SRCS", "NATIVE_SRCS", "NATIVE_UTILS_GEN_PRIV_HDRS", "NATIVE_UTILS_GEN_SRCS", "PARTITION_ALLOC_HDRS", "PLATFORM_HDRS", "PLATFORM_PRIV_HDRS", "PLATFORM_SRCS", "PROC_HDRS", "SYSTEM_UTILS_APPLE_PRIV_HDRS", "SYSTEM_UTILS_APPLE_SRCS", "SYSTEM_UTILS_PRIV_HDRS", "SYSTEM_UTILS_SRCS", "SYSTEM_UTILS_UNIX_SRCS", "SYSTEM_UTILS_WIN32_SRCS", "WIRE_GEN_PRIV_HDRS", "WIRE_GEN_SRCS", "WIRE_HDRS", "WIRE_PRIV_HDRS", "WIRE_SRCS", ) config_setting( name = "debug_build", values = {"compilation_mode": "dbg"}, ) # These are hardcoded to avoid the complexity of linking in the gl xml inputs used by the generator. NATIVE_OPENGL_AUTOGEN_SRCS = [ "src/dawn/native/opengl/OpenGLFunctionsBase_autogen.cpp", "src/dawn/native/opengl/OpenGLFunctionsBase_autogen.h", "src/dawn/native/opengl/opengl_platform_autogen.h", ] # These are also easier to hardcode rather than running the generator. VERSION_AUTOGEN_HEADERS = [ "include/dawn/dawn_version.h", "src/dawn/common/Version_autogen.h", ] DAWN_PUBLIC_HDRS = HEADERS_WEBGPU_HDRS + DAWNCPP_HEADERS_WEBGPU_HDRS + PROC_HDRS DAWN_GENERATED_HDRS = HEADERS_GEN_PRIV_HDRS + DAWNCPP_HEADERS_GEN_PRIV_HDRS + VERSION_AUTOGEN_HEADERS TINT_PUBLIC_HDRS = [ "include/tint/tint.h", ] #### Dawn's Generated Files py_library( name = "generator_lib", srcs = ["generator/generator_lib.py"], imports = ["generator"], deps = [ "@jinja2", "@markupsafe", ], ) py_binary( name = "dawn_json_generator", srcs = [ "generator/dawn_json_generator.py", "generator/webgpu_docs_utility.py", ], deps = [":generator_lib"], ) py_binary( name = "dawn_gpu_info_generator", srcs = ["generator/dawn_gpu_info_generator.py"], deps = [":generator_lib"], ) py_binary( name = "dawn_version_generator", srcs = ["generator/dawn_version_generator.py"], deps = [":generator_lib"], ) py_binary( name = "opengl_loader_generator", srcs = ["generator/opengl_loader_generator.py"], deps = [":generator_lib"], ) DAWN_TEMPLATE_DIR_FLAG = "--template-dir $$(dirname $(execpath generator/templates/api.h))" DAWN_GENERATOR_TEMPLATES = glob( ["generator/templates/**"], allow_empty = False, ) # TODO(https://crbug.com/dawn/878ee25c690101566294e1ddcfd34a152adc9dc2): # Once we no longer need to support Dawn versions older than the commit above, # we can make this mandatory and remove the glob/conditional logic. DAWN_JSON_GENERATOR_SRCS = DAWN_GENERATOR_TEMPLATES + [ "src/dawn/dawn.json", "src/dawn/dawn_wire.json", ] + glob( [ "src/dawn/dawn_native.json", ], allow_empty = True, ) DAWN_JSON_GENERATOR_CMD = ( "$(location :dawn_json_generator) " + "--dawn-json $(location src/dawn/dawn.json) " + "--wire-json $(location src/dawn/dawn_wire.json) " + (" --native-json $(location src/dawn/dawn_native.json) " if glob( ["src/dawn/dawn_native.json"], allow_empty = True, ) else "") + DAWN_TEMPLATE_DIR_FLAG ) genrule( name = "generate_webgpu_cpp", srcs = DAWN_JSON_GENERATOR_SRCS, outs = [ "include/dawn/webgpu_cpp.h", "include/webgpu/webgpu_cpp_chained_struct.h", "include/dawn/webgpu_cpp_print.h", "include/dawn/wire/client/webgpu_cpp.h", "include/dawn/wire/client/webgpu_cpp_print.h", ], cmd = DAWN_JSON_GENERATOR_CMD + " --targets cpp_headers " + " --output-dir $(RULEDIR)", tools = [":dawn_json_generator"], ) genrule( name = "generate_webgpu", srcs = DAWN_JSON_GENERATOR_SRCS, outs = [ "include/dawn/webgpu.h", "include/dawn/dawn_proc_table.h", "include/dawn/wire/client/webgpu.h", ], cmd = DAWN_JSON_GENERATOR_CMD + " --targets headers " + " --output-dir $(RULEDIR)", tools = [":dawn_json_generator"], ) genrule( name = "generate_proc", srcs = DAWN_JSON_GENERATOR_SRCS, outs = [ "src/dawn/dawn_proc.cpp", "src/dawn/dawn_thread_dispatch_proc.cpp", ], cmd = DAWN_JSON_GENERATOR_CMD + " --targets proc " + " --output-dir $(RULEDIR)", tools = [":dawn_json_generator"], ) genrule( name = "generate_utils", srcs = DAWN_JSON_GENERATOR_SRCS, outs = NATIVE_UTILS_GEN_SRCS + NATIVE_UTILS_GEN_PRIV_HDRS, cmd = DAWN_JSON_GENERATOR_CMD + " --targets native_utils " + " --output-dir $(RULEDIR)", tools = [":dawn_json_generator"], ) genrule( name = "generate_wire", srcs = DAWN_JSON_GENERATOR_SRCS, outs = WIRE_GEN_SRCS + WIRE_GEN_PRIV_HDRS, cmd = DAWN_JSON_GENERATOR_CMD + " --targets wire " + " --output-dir $(RULEDIR)", tools = [":dawn_json_generator"], ) genrule( name = "generate_gpuinfo", srcs = DAWN_GENERATOR_TEMPLATES + ["src/dawn/gpu_info.json"], outs = GPU_INFO_AUTOGEN_SRCS + GPU_INFO_AUTOGEN_PRIV_HDRS, cmd = "$(location :dawn_gpu_info_generator) " + "--gpu-info-json $(location src/dawn/gpu_info.json) " + DAWN_TEMPLATE_DIR_FLAG + " --output-dir $(RULEDIR)", tools = [":dawn_gpu_info_generator"], ) genrule( name = "generate_version", srcs = DAWN_GENERATOR_TEMPLATES + ["src/dawn/dawn.json"], outs = VERSION_AUTOGEN_HEADERS, cmd = "$(location :dawn_version_generator) " + DAWN_TEMPLATE_DIR_FLAG + " --dawn-dir $$(dirname $$(dirname $$(dirname $(execpath src/dawn/dawn.json))))" + " --output-dir $(RULEDIR) 2> /dev/null", tools = [":dawn_version_generator"], ) genrule( name = "generate_opengl_loader", srcs = DAWN_GENERATOR_TEMPLATES + [ "@opengl_registry//:xml/gl.xml", "src/dawn/native/opengl/supported_extensions.json", ], outs = NATIVE_OPENGL_AUTOGEN_SRCS, cmd = "$(location :opengl_loader_generator) " + "--gl-xml $(location @opengl_registry//:xml/gl.xml) " + "--supported-extensions $(location src/dawn/native/opengl/supported_extensions.json) " + DAWN_TEMPLATE_DIR_FLAG + " --output-dir $(RULEDIR)", tools = [":opengl_loader_generator"], ) #### Dawn and Tint Configuration DAWN_DEBUG_DEFINES = select({ ":debug_build": ["DAWN_ENABLE_ASSERTS"], "//conditions:default": [], }) TINT_WGSL_DEFINES = [ "TINT_BUILD_WGSL_READER=1", "TINT_BUILD_WGSL_WRITER=1", ] DAWN_LINUX_DEFINES = [ "DAWN_USE_X11", "TINT_BUILD_SPV_READER=1", "TINT_BUILD_SPV_WRITER=1", "TINT_BUILD_NULL_WRITER=1", "TINT_BUILD_GLSL_WRITER=1", "DAWN_ENABLE_BACKEND_VULKAN", "DAWN_ENABLE_BACKEND_OPENGLES", # This is set if we are using OpenGLES (we are) or the "desktop" OpenGL backend (we aren't) "DAWN_ENABLE_BACKEND_OPENGL", ] DAWN_METAL_DEFINES = [ "TINT_BUILD_MSL_WRITER=1", "TINT_BUILD_SPV_READER=0", "TINT_BUILD_SPV_WRITER=0", "DAWN_ENABLE_BACKEND_METAL", ] DAWN_WINDOWS_DEFINES = [ "DAWN_ENABLE_BACKEND_D3D12", "DAWN_ENABLE_BACKEND_D3D11", "DAWN_ENABLE_BACKEND_VULKAN", "TINT_BUILD_HLSL_WRITER=1", "TINT_BUILD_SPV_READER=1", "TINT_BUILD_SPV_WRITER=1", ] DAWN_COPTS = [ "-Wno-assume", # Silence some warnings when building w/o asserts ] #### Dawn Build Targets cc_library( name = "dawn_absl_deps", deps = [ "@abseil_cpp//absl/container:btree", "@abseil_cpp//absl/container:flat_hash_map", "@abseil_cpp//absl/container:flat_hash_set", "@abseil_cpp//absl/container:inlined_vector", "@abseil_cpp//absl/functional:overload", "@abseil_cpp//absl/strings", "@abseil_cpp//absl/strings:str_format", "@abseil_cpp//absl/types:span", "@abseil_cpp//absl/types:variant", ], ) cc_library( name = "dawn_partition_alloc", hdrs = PARTITION_ALLOC_HDRS, includes = ["src/dawn/partition_alloc"], ) # We need the headers available to both the objc and c++ version of this but objc doesn't like # the headers that are .inl. This pattern of having a headers cc_library allows us to work around # that *and* satisfy the dependencies of the headers w/o duplicating a bunch of file lists. cc_library( name = "dawn_common_headers", hdrs = COMMON_PRIV_HDRS + GPU_INFO_AUTOGEN_PRIV_HDRS + DAWN_PUBLIC_HDRS + DAWN_GENERATED_HDRS, includes = [ "include", "src", ], deps = [ ":dawn_absl_deps", ":dawn_partition_alloc", "//src/utils", ], ) cc_library( name = "dawn_common_win", srcs = COMMON_WIN32_SRCS, hdrs = COMMON_WIN32_PRIV_HDRS, copts = DAWN_COPTS, defines = DAWN_DEBUG_DEFINES, deps = [ ":dawn_common_headers", ], ) cc_library( name = "dawn_common", srcs = COMMON_SRCS + GPU_INFO_AUTOGEN_SRCS, copts = DAWN_COPTS, defines = DAWN_DEBUG_DEFINES, deps = [ ":dawn_common_headers", ] + select({ "@platforms//os:windows": [":dawn_common_win"], "@platforms//os:macos": [":dawn_common_objc"], "@platforms//os:ios": [":dawn_common_objc"], "//conditions:default": [], }), ) objc_library( name = "dawn_common_objc", srcs = COMMON_APPLE_SRCS + COMMON_APPLE_PRIV_HDRS, copts = DAWN_COPTS, defines = DAWN_DEBUG_DEFINES, sdk_frameworks = [ "CoreFoundation", "IOKit", "IOSurface", "QuartzCore", ], deps = [ ":dawn_common_headers", ], ) cc_library( name = "dawn_wire", srcs = WIRE_SRCS + WIRE_GEN_SRCS, hdrs = WIRE_HDRS + WIRE_PRIV_HDRS + WIRE_GEN_PRIV_HDRS, copts = DAWN_COPTS, deps = [ ":dawn_common", ":dawn_partition_alloc", ":tint", ], ) cc_library( name = "dawn_system_utils_headers", hdrs = SYSTEM_UTILS_PRIV_HDRS, includes = [ "include", "src", ], deps = [ ":dawn_common_headers", ], ) cc_library( name = "dawn_system_utils", srcs = SYSTEM_UTILS_SRCS + select({ "@platforms//os:linux": SYSTEM_UTILS_UNIX_SRCS, "@platforms//os:ios": SYSTEM_UTILS_UNIX_SRCS, "@platforms//os:macos": SYSTEM_UTILS_UNIX_SRCS, "@platforms//os:windows": SYSTEM_UTILS_WIN32_SRCS, "//conditions:default": [], }), hdrs = [], copts = DAWN_COPTS, deps = [ ":dawn_common", ":dawn_system_utils_headers", ] + select({ "@platforms//os:macos": [":dawn_system_utils_objc"], "@platforms//os:ios": [":dawn_system_utils_objc"], "//conditions:default": [], }), ) objc_library( name = "dawn_system_utils_objc", srcs = SYSTEM_UTILS_APPLE_SRCS + SYSTEM_UTILS_APPLE_PRIV_HDRS, copts = DAWN_COPTS, deps = [ ":dawn_common", ":dawn_system_utils_headers", ], ) cc_library( name = "dawn_platform", srcs = PLATFORM_SRCS, hdrs = PLATFORM_HDRS + DAWN_PUBLIC_HDRS + DAWN_GENERATED_HDRS + PLATFORM_PRIV_HDRS, copts = DAWN_COPTS, deps = [ ":dawn_common", ":dawn_partition_alloc", ], ) cc_library( name = "dawn_native_headers", hdrs = DAWN_GENERATED_HDRS + NATIVE_OBJECTS_HDRS + NATIVE_OBJECTS_PRIV_HDRS + NATIVE_UTILS_GEN_PRIV_HDRS + DAWN_PUBLIC_HDRS + TINT_PUBLIC_HDRS + select({ "@platforms//os:linux": NATIVE_OBJECTS_OPENGL_PRIV_HDRS + NATIVE_OBJECTS_VULKAN_PRIV_HDRS + NATIVE_OBJECTS_USE_X11_PRIV_HDRS + NATIVE_OBJECTS_UNIX_PRIV_HDRS, "@platforms//os:android": [], # TODO(kjlubick) "@platforms//os:windows": NATIVE_OBJECTS_D3D_HDRS + NATIVE_OBJECTS_D3D_PRIV_HDRS + NATIVE_OBJECTS_VULKAN_PRIV_HDRS, "//conditions:default": [], }), includes = [ "include", "src", ], deps = [ ":dawn_common_headers", "@vulkan_headers", ], ) cc_library( name = "dawn_native", srcs = NATIVE_SRCS + NATIVE_OBJECTS_SRCS + NATIVE_UTILS_GEN_SRCS + select({ "@platforms//os:linux": NATIVE_OBJECTS_USE_X11_SRCS + NATIVE_OBJECTS_OPENGL_SRCS + NATIVE_OBJECTS_VULKAN_SRCS + NATIVE_OBJECTS_UNIX_SRCS + NATIVE_OPENGL_AUTOGEN_SRCS, "@platforms//os:android": [], # TODO(kjlubick) "@platforms//os:macos": [], # See dawn_native_objc "@platforms//os:ios": [], # See dawn_native_objc "@platforms//os:windows": NATIVE_D3D_SRCS + NATIVE_OBJECTS_D3D_SRCS + NATIVE_OBJECTS_VULKAN_SRCS, }), hdrs = [], copts = DAWN_COPTS, defines = TINT_WGSL_DEFINES + select({ "@platforms//os:linux": DAWN_LINUX_DEFINES, "@platforms//os:android": [], # TODO(kjlubick) "@platforms//os:macos": DAWN_METAL_DEFINES, "@platforms//os:ios": DAWN_METAL_DEFINES, "@platforms//os:windows": DAWN_WINDOWS_DEFINES, }), linkopts = select({ "@platforms//os:windows": [ "dxguid.lib", "onecore.lib", ], "//conditions:default": [], }), deps = [ ":dawn_common", ":dawn_native_headers", ":dawn_partition_alloc", ":dawn_platform", ":dawn_system_utils", ":tint", "@egl_registry", "@opengl_registry", "@vulkan_headers", "@vulkan_utility_libraries", ] + select({ "@platforms//os:macos": [":dawn_native_objc"], "@platforms//os:ios": [":dawn_native_objc"], "//conditions:default": [], }), ) objc_library( name = "dawn_native_objc", srcs = NATIVE_OBJECTS_METAL_SRCS + NATIVE_OBJECTS_METAL_PRIV_HDRS, hdrs = [], copts = DAWN_COPTS, defines = TINT_WGSL_DEFINES + DAWN_METAL_DEFINES, sdk_frameworks = [ "Metal", "Cocoa", "IOKit", "IOSurface", "QuartzCore", ], deps = [ ":dawn_common", ":dawn_native_headers", ":dawn_partition_alloc", ":dawn_platform", ":dawn_system_utils", ":tint", "@vulkan_headers", ], ) cc_library( name = "dawn_proc", srcs = DAWNPROC_GEN_SRCS, deps = [ ":dawn_common", ":dawn_common_headers", ":dawn_system_utils", ], ) # See @dawn/docs/dawn/overview.md for an overview of the three main components of Dawn. cc_library( name = "dawn", hdrs = DAWN_PUBLIC_HDRS + DAWN_GENERATED_HDRS, visibility = ["//visibility:public"], deps = [ ":dawn_native", ":dawn_proc", ":dawn_wire", ], ) cc_library( name = "tint", hdrs = TINT_PUBLIC_HDRS, defines = [ "TINT_BUILD_WGSL_READER=1", "TINT_BUILD_WGSL_WRITER=1", ], includes = ["include"], visibility = ["//visibility:public"], deps = [ "//src/tint/api", "//src/tint/lang/glsl/writer", "//src/tint/lang/null/writer", ], )