1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 """Repository rule to statically link against the Vulkan SDK.
7 Requires installing the Vulkan SDK from https://vulkan.lunarg.com/.
9 If the Vulkan SDK is not installed, this generates an empty rule and you may
10 encounter linker errors like `error: undefined reference to 'vkCreateInstance'`.
13 def _impl(repository_ctx):
14 if "VULKAN_SDK" in repository_ctx.os.environ:
15 sdk_path = repository_ctx.os.environ["VULKAN_SDK"]
16 repository_ctx.symlink(sdk_path, "vulkan-sdk")
18 repository_ctx.file("BUILD", """
22 "@bazel_tools//src/conditions:windows": [
23 "vulkan-sdk/Lib/vulkan-1.lib"
25 "//conditions:default": [
26 "vulkan-sdk/lib/libvulkan.so.1",
29 visibility = ["//visibility:public"],
32 # Empty rule. Will fail to link for just targets that use Vulkan.
33 repository_ctx.file("BUILD", """
37 visibility = ["//visibility:public"],
40 vulkan_sdk_setup = repository_rule(
41 implementation = _impl,