Skip to content

Migrate to Bzlmod and add tool_target parameter for CLI tools#20

Merged
1e100 merged 5 commits intomasterfrom
claude/review-pr-11-deps-45wzr
Apr 1, 2026
Merged

Migrate to Bzlmod and add tool_target parameter for CLI tools#20
1e100 merged 5 commits intomasterfrom
claude/review-pr-11-deps-45wzr

Conversation

@1e100
Copy link
Copy Markdown
Owner

@1e100 1e100 commented Mar 31, 2026

Summary

This PR migrates the cloud_archive project from WORKSPACE-based dependency management to Bzlmod (MODULE.bazel), and adds support for specifying custom CLI tool binaries via a new tool_target parameter across all repository rules.

Key Changes

  • Bzlmod Migration: Moved all repository rule definitions from WORKSPACE to MODULE.bazel, enabling the project to work with Bazel's modern module system

    • Removed --enable_workspace flag from .bazelrc as it's no longer needed
    • Kept WORKSPACE file minimal with just the workspace name declaration
  • Tool Target Parameter: Added optional tool_target attribute to all cloud provider rules (s3_archive, s3_file, gs_archive, gs_file, minio_archive, minio_file, b2_archive, b2_file)

    • Allows users to specify a pre-built CLI binary (e.g., @my_awscli//:aws) instead of relying on tools in $PATH
    • When set, the referenced repository is automatically fetched before rule execution
    • Falls back to $PATH lookup if not specified
  • Refactored Tool Resolution: Extracted tool resolution logic into _resolve_tool() helper function

    • Centralizes the logic for finding CLI tools by provider name
    • Improves error messages when tools are not found
    • Reduces code duplication across cloud download functions
  • BCR Configuration: Added Bazel Central Registry metadata files for publishing

    • .bcr/metadata.template.json: Module metadata with homepage and maintainer info
    • .bcr/presubmit.yml: CI configuration for verifying builds on Ubuntu and macOS
    • .bcr/source.template.json: Source distribution configuration
  • Build Configuration: Updated .gitignore to track MODULE.bazel.lock

Implementation Details

The _resolve_tool() function provides a unified interface for tool resolution:

  • If tool_target is provided, it resolves the label to a path (triggering repository fetch)
  • Otherwise, it looks up the tool name in _PROVIDER_TOOL_NAMES mapping and searches $PATH
  • Provides clear error messages if the tool cannot be found

All cloud download functions now accept and pass through the tool_target parameter to enable this functionality.

claude added 5 commits March 31, 2026 15:38
Move all repository rule invocations from WORKSPACE to MODULE.bazel
using use_repo_rule (bzlmod-native). Remove --enable_workspace from
.bazelrc since Bazel 8 defaults to bzlmod.

Add optional tool_target attribute to all cloud rules (s3, gs, minio,
b2) so users can point to a Bazel-managed CLI binary (e.g.
@my_awscli//:aws) instead of requiring tools on $PATH. When unset,
the existing $PATH lookup via repo_ctx.which() is preserved.

Add .bcr/ templates (metadata, presubmit, source) for future Bazel
Central Registry submission.

Partially addresses PR #11.

https://claude.ai/code/session_01AxVsJ3PcLBCmcUXAaLKZQk
Replace the per-rule-only tool_target approach with a module extension
(cloud_archive.configure) that lets consumers register CLI tool labels
once in their MODULE.bazel. All cloud_archive rules then automatically
use the configured binaries.

Resolution order: per-rule tool_target > module extension config > $PATH.

Example consumer usage:

    cloud_archive = use_extension("@cloud_archive//:extensions.bzl", "cloud_archive")
    cloud_archive.configure(s3 = "@my_awscli//:aws")
    use_repo(cloud_archive, "cloud_archive_tools")

https://claude.ai/code/session_01AxVsJ3PcLBCmcUXAaLKZQk
Covers module extension setup, repository rule declaration,
BUILD file consumption, attribute reference, and tool resolution.

https://claude.ai/code/session_01AxVsJ3PcLBCmcUXAaLKZQk
Under bzlmod, repos registered via use_repo_rule get canonical names
like _main~_repo_rules~<name> in the runfiles tree. Add an _rlocation
helper that checks both the bare name and the bzlmod canonical name,
as well as the runfiles manifest when available.

https://claude.ai/code/session_01AxVsJ3PcLBCmcUXAaLKZQk
Replace the hand-rolled _rlocation helper with Bazel's official
runfiles.bash library, which reads the _repo_mapping file and
correctly translates apparent repo names to canonical names under
bzlmod. Add the @bazel_tools//tools/bash/runfiles dep to the test.

https://claude.ai/code/session_01AxVsJ3PcLBCmcUXAaLKZQk
@1e100 1e100 merged commit 5063b5c into master Apr 1, 2026
This was referenced Apr 1, 2026
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.

2 participants