Skip to content

fix: declare every @cuda target when no CUDA toolkit is found - #511

Merged
cloudhan merged 1 commit into
bazel-contrib:mainfrom
Spikhalskiy:disabled-cuda-repo-targets
Oct 12, 2026
Merged

cloudhan merged 1 commit into
bazel-contrib:mainfrom
Spikhalskiy:disabled-cuda-repo-targets

Conversation

@Spikhalskiy

Copy link
Copy Markdown
Contributor

Fixes #510.

Without a toolkit, @cuda//BUILD was BUILD.cuda_disabled, which defines only the targets the disabled toolchain uses. A select() branch naming any other @cuda target broke plain bazel query.

The disabled @cuda//BUILD is now generated: the same template, plus an incompatible placeholder for every target REGISTRY exposes under @cuda and for the repo-level cuda_headers, cuda_all_files, cuda_license and cuda_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: a select() naming @cuda//:cuda_headers and @cuda//:cuda_runtime_static now passes bazel query 'deps(...)', builds with --@rules_cuda//cuda:enable=False, and fails as incompatible with CUDA enabled.

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
Copilot AI balanced review requested due to automatic review settings October 11, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 REGISTRY and 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.

@cloudhan cloudhan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@cloudhan
cloudhan merged commit d12c4ea into bazel-contrib:main Oct 12, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stub @cuda repo lacks toolkit targets, so bazel query 'deps(...)' fails without CUDA

3 participants