rules_vulkan
v0.1.1
published 2 months ago
3 stars
1 forks
0 watchers
Apache License 2.0
public
2 assets
4,900 downloads
53 KB
Compatibility level unknown
iFBrnPbqLLfbkV2klU5goyY+md/3ZJ1TvFKNNgKFhlo=
Maintained byMaksym Pavlenko
v0.1.1
June 10, 2025
[expand for release notes]

rules_vulkan

CI License Release

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.

Features

  • Fully automated SDK installation.
  • Maintains a list of currently available SDK versions on LunarG with automated nightly updates.
  • Toolchains and rules for GLSL, HLSL, and Slang.
  • Unit and integration tests on CI.
  • Available on BCR.
  • A nice-looking AI-generated logo!

🔰 Getting started

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",
    spirv = True,
    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",
    }),
)

âš¡ Direct Binary Invocation

You can invoke SDK binaries directly using their pre-configured targets:

# Run spirv-cross directly
bazelisk run @vk_sdk//:spirv_cross -- --help

# Run glslc directly
bazelisk run @vk_sdk//:glslc -- --version

# Run dxc directly
bazelisk run @vk_sdk//:dxc -- --version

# Run slangc directly
bazelisk run @vk_sdk//:slangc -- -h

Refer to e2e project here for a more complete setup.

License

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.