llvm-project
43 строки · 1.3 Кб
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
4
5"""Repository rule to statically link against the Vulkan SDK.
6
7Requires installing the Vulkan SDK from https://vulkan.lunarg.com/.
8
9If the Vulkan SDK is not installed, this generates an empty rule and you may
10encounter linker errors like `error: undefined reference to 'vkCreateInstance'`.
11"""
12
13def _impl(repository_ctx):
14if "VULKAN_SDK" in repository_ctx.os.environ:
15sdk_path = repository_ctx.os.environ["VULKAN_SDK"]
16repository_ctx.symlink(sdk_path, "vulkan-sdk")
17
18repository_ctx.file("BUILD", """
19cc_library(
20name = "sdk",
21srcs = select({
22"@platforms//os:windows": [
23"vulkan-sdk/Lib/vulkan-1.lib"
24],
25"//conditions:default": [
26"vulkan-sdk/lib/libvulkan.so.1",
27],
28}),
29visibility = ["//visibility:public"],
30)""")
31else:
32# Empty rule. Will fail to link for just targets that use Vulkan.
33repository_ctx.file("BUILD", """
34cc_library(
35name = "sdk",
36srcs = [],
37visibility = ["//visibility:public"],
38)""")
39
40vulkan_sdk_setup = repository_rule(
41implementation = _impl,
42local = True,
43)
44