rules_vulkan is a set of Bazel rules for integrating the Vulkan SDK
into your builds. It streamlines downloading, installing, and using Vulkan SDKs across major platforms.
- Fully automated SDK installation.
- Maintains a list of currently available SDK versions on
LunarGwith automated nightly updates. - Toolchains and rules for
GLSL,HLSL, andSlang. - Supports optional SDK components such as Volk and VMA.
- Unit and integration tests on CI.
- Available on BCR.
- A nice-looking AI-generated logo!
To get started, you’ll need to fetch the Vulkan SDK and register the toolchains.
Add the following to your MODULE.bazel file:
bazel_dep(name = "rules_vulkan", version = "0.1")
vulkan_sdk = use_extension("@rules_vulkan//vulkan:extensions.bzl", "vulkan_sdk")
vulkan_sdk.toolchain(version = "1.4.313")
use_repo(vulkan_sdk, "vulkan_sdk_1.4.313")
register_toolchains("@vulkan_sdk_1.4.313//:all")Then use it in your BUILD files:
load("@rules_vulkan//vulkan:defs.bzl", "hlsl_shader", "glsl_shader")
hlsl_shader(
name = "hello_hlsl",
src = "shader.hlsl",
entry = "CSMain",
target = "cs_6_0",
opts = ["-spirv"],
hdrs = [":common_headers"],
)
glsl_shader(
name = "hello_glsl",
src = "shader.glsl",
stage = "comp",
)
cc_binary(
name = "app",
srcs = ["main.c"],
data = [":hello_hlsl", ":hello_glsl"],
deps = ["@vulkan_sdk_1.4.313//:vulkan"],
)
# Since the SDK repo exports all binaries, you can manually wrap any SDK binary not directly exposed
native_binary(
name = "spirv_cross",
src = select({
"@platforms//os:windows": "@vulkan_sdk_1.4.313//:sdk/Bin/spirv-cross.exe",
"//conditions:default": "@vulkan_sdk_1.4.313//:sdk/bin/spirv-cross",
}),
)Warning
This project is under active development and no API stability is guaranteed until 1.0. Expect breaking changes
during upgrades. Breaking changes are marked with the
breaking label on pull requests.
You can invoke SDK binaries directly using their pre-configured targets:
bazelisk run @vk_sdk//:spirv_cross -- --help
bazelisk run @vk_sdk//:glslc -- --version
bazelisk run @vk_sdk//:dxc -- --version
bazelisk run @vk_sdk//:slangc -- -hRefer to e2e project here for a more complete setup.
The project itself is licensed under Apache 2.0 license.
Note
This project downloads packages from LunarG, please ensure you comply with their license terms.
