Repository navigation
fix: declare every @cuda target when no CUDA toolkit is found - #511
Merged
cloudhan merged 1 commit intoOct 12, 2026
Merged
Conversation
Without a toolkit, @cuda only defined the targets the disabled toolchain uses, so a select() branch naming any other @cuda target broke plain bazel query, which loads every branch. Generate the disabled BUILD with an incompatible placeholder for each target an enabled @cuda exposes. Fixes bazel-contrib#510
Spikhalskiy
requested review from
cloudhan,
jsharpe and
ryanleary
as code owners
October 11, 2026 15:22
There was a problem hiding this comment.
🟢 Approval recommended
The implementation matches the stated behavior and includes focused integration coverage.
0 open findings
What changed in this PR
Generates a complete disabled @cuda repository so Bazel queries can resolve optional CUDA targets when no toolkit exists.
Changes:
- Generates incompatible placeholders from
REGISTRYand repository-level CUDA targets. - Uses the generated disabled BUILD file during toolkit configuration.
- Adds integration coverage for querying and conditionally building CUDA dependencies.
| File | Description |
|---|---|
cuda/private/template_helper.bzl |
Generates disabled-repository placeholders. |
cuda/private/repositories.bzl |
Uses the new generator when CUDA is unavailable. |
tests/integration/BUILD.to_symlink |
Adds an optional CUDA dependency target. |
tests/integration/test_all.sh |
Tests query and build behavior without CUDA. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #510.
Without a toolkit,
@cuda//BUILDwasBUILD.cuda_disabled, which defines only the targets the disabled toolchain uses. Aselect()branch naming any other@cudatarget broke plainbazel query.The disabled
@cuda//BUILDis now generated: the same template, plus an incompatible placeholder for every targetREGISTRYexposes under@cudaand for the repo-levelcuda_headers,cuda_all_files,cuda_licenseandcuda_device_runtime_static_libs. Targets the template already defines (cuda_runtime,compiler_root, ...) keep their definitions, so the disabled toolchain is unchanged. Building a placeholder fails as incompatible instead of silently linking nothing.Tested in
toolchain_none: aselect()naming@cuda//:cuda_headersand@cuda//:cuda_runtime_staticnow passesbazel query 'deps(...)', builds with--@rules_cuda//cuda:enable=False, and fails as incompatible with CUDA enabled.