Skip to content

mxpv/rules_vulkan

Repository files navigation

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:

bazelisk run @vk_sdk//:spirv_cross -- --help
bazelisk run @vk_sdk//:glslc -- --version
bazelisk run @vk_sdk//:dxc -- --version
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.

About

Bazel rules to build Vulkan applications

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Languages