tomato·bazeldocs v0 · latest
Docs/Reference/Modules/rules_github

rules_github

Bazel repository rules for GitHub-release-based content. Common substrate for rules_mdbook, rules_bun, rules_postgres, et al.

Latest0.1.2
Versions3
CategoryBazel rules
Compat level1
MaintainersMatt Marshall
Registryhttps://registry.tbzl.dev/modules/rules_github/
Sourcegithub.com/tomato-bazel/rules_github
MODULE.bazelstarlark
bazel_dep(name = "rules_github", version = "0.1.2")

View source & releases on GitHub ↗

Bazel repository rules for fetching content from GitHub releases — the common substrate underneath fastverk’s rules_mdbook, rules_bun, rules_postgres, and anything else that pulls a sha-pinned prebuilt binary or source tarball from a GitHub release.

Two repository rules:

  • github_binary_repository — fetch a per-platform binary release asset (releases/download/<tag>/<asset> URL shape; mdbook, bun, ripgrep, jq, …).
  • github_source_repository — fetch a source tarball from a tag (archive/refs/tags/<tag>.tar.gz URL shape; libpg_query and anything else that doesn’t ship prebuilt assets but you want to build from source under Bazel).

See docs/repositories.md for the full attribute reference.

Install

Add the registry to your .bazelrc:

common --registry=https://registry.fastverk.com/
common --registry=https://bcr.bazel.build/

In your MODULE.bazel:

bazel_dep(name = "rules_github", version = "0.1.0")

Quick start

Per-platform binary (mdbook-style)

load("@rules_github//github:repositories.bzl", "github_binary_repository")

def _bun_ext_impl(_ctx):
    github_binary_repository(
        name = "bun",
        repo = "oven-sh/bun",
        version = "1.3.14",
        tag_format = "bun-v{version}",
        asset_template = "bun-{platform}.zip",
        strip_prefix_template = "bun-{platform}",
        platform_aliases = {
            "darwin_aarch64": "darwin-aarch64",
            "darwin_x86_64":  "darwin-x64",
            "linux_aarch64":  "linux-aarch64",
            "linux_x86_64":   "linux-x64",
        },
        platform_shas = {
            "darwin_aarch64": "d8b96221828ad6f97ac7ac0ab7e95872341af763001e8803e8267652c2652620",
            "linux_x86_64":   "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f",
            # …
        },
        build_file_content = """
package(default_visibility = ["//visibility:public"])
exports_files(["bun"])
""",
    )

bun_ext = module_extension(implementation = _bun_ext_impl)

Canonical platform identifiers are darwin_aarch64, darwin_x86_64, linux_x86_64, linux_aarch64, windows_x86_64. platform_aliases maps these to whatever the upstream release naming uses (aarch64-apple-darwin for Rust-target convention, darwin-aarch64 for Bun, …).

Source tarball (libpg_query-style)

load("@rules_github//github:repositories.bzl", "github_source_repository")

github_source_repository(
    name = "libpg_query",
    repo = "pganalyze/libpg_query",
    version = "17-6.2.2",
    tag_format = "{version}",         # libpg_query tags don't have a `v` prefix
    sha256 = "e68962c18dbf5890821511be6c5c42261170bf8bfd51a82ea9176069f3d0df8b",
    build_file_content = """
load("@rules_cc//cc:defs.bzl", "cc_library")
# … cc_library wiring …
""",
)

strip_prefix_template defaults to <repo-basename>-<version>, matching GitHub’s auto-generated source tarball layout. Override only if upstream’s tag-to-tarball-prefix mapping is non-standard.

What’s deliberately NOT here

  • Toolchain rules. Each downstream rules_* (rules_mdbook, rules_bun, …) defines its own ToolchainInfo provider with project-specific fields. Wrapping the binary as a toolchain stays in the consumer’s BUILD overlay.
  • Generic-HTTP fetching. Non-GitHub URLs (e.g., ftp.postgresql.org/pub/source/postgresql-17.6.tar.bz2 for the full PG source) need a different URL template. A sibling http_archive_repository could be added later; today, use Bazel’s built-in http_archive directly.

Compatibility

  • Bazel: 7.4+, bzlmod required.
  • Platforms: detection covers darwin × {aarch64, x86_64}, linux × {x86_64, aarch64}, windows × x86_64. Other platforms surface as an explicit fail() — extend github/private/platforms.bzl if needed.

Contributing

Reference docs are stardoc-generated. After editing rule docstrings:

bazel run //docs:update

CI gates this via bazel test //docs/... + buildifier lint.

License

MIT.

Rules & providers#

Generated with Stardoc from the module's .bzl sources.

from docs/repositories.md

Two repository rules for GitHub-release-based content.

  • github_binary_repository — fetch a per-platform binary release asset (the releases/download/<tag>/<asset> URL shape used by most CLI projects: mdbook, bun, ripgrep, jq, …).

  • github_source_repository — fetch a source tarball from a tag (the archive/refs/tags/<tag>.tar.gz URL shape, used when a project doesn’t publish prebuilt release assets — e.g., libpg_query — or when you want to build the source yourself).

Both rules:

  • Construct the release tag from a template (v{version}, bun-v{version}, {version}, etc.).
  • Verify integrity via sha256.
  • Write the consumer-supplied BUILD overlay (inline or label).

Consumers that need a Bazel toolchain wrapping the downloaded binary declare it inside build_file_contentrules_github deliberately doesn’t ship its own toolchain rule because toolchain providers vary per-tool (each downstream rules_* repo has its own ToolToolchainInfo provider shape).

github_binary_repository

load("@rules_github//github:repositories.bzl", "github_binary_repository")

github_binary_repository(name, allow_unverified, asset_template, build_file, build_file_content,
                         platform, platform_aliases, platform_shas, repo, strip_prefix_template,
                         tag_format, version)

Fetch a per-platform binary release asset from a GitHub release.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this repository.Namerequired
allow_unverifiedIf True, missing sha256 for the host platform downgrades to a warning + unverified download. Useful for bumping to a new version before computing pins.BooleanoptionalFalse
asset_templateAsset filename pattern. {version} + {platform} substituted. The platform substitution uses the alias from platform_aliases for the detected host.Stringrequired
build_fileBUILD.bazel content as a label. Alternative to build_file_content.LabeloptionalNone
build_file_contentInline BUILD.bazel content for the generated repo. Either this OR build_file must be set.Stringoptional""
platformOverride host-platform detection. Empty = auto-detect.Stringoptional""
platform_aliasesCanonical-platform → project-specific-platform mapping. Canonical keys: darwin_aarch64, darwin_x86_64, linux_x86_64, linux_aarch64, windows_x86_64. Project values follow whatever the upstream release uses (aarch64-apple-darwin, darwin-aarch64, etc.). Missing key = canonical name used verbatim.Dictionary: String -> Stringoptional{}
platform_shasCanonical-platform → sha256 hex. Lookup keys match platform_aliases. Missing entry for the host platform fails the build unless allow_unverified = True.Dictionary: String -> Stringoptional{}
repoGitHub repo as owner/name (e.g. oven-sh/bun).Stringrequired
strip_prefix_templateOptional strip-prefix pattern with {version} + {platform} substitution. Defaults to empty (binary at archive root).Stringoptional""
tag_formatRelease tag pattern. {version} is substituted. Examples: v{version} (default; mdbook, most tools), bun-v{version} (bun), {version} (libpg_query: 17-6.2.2 IS the tag).Stringoptional"v{version}"
versionUpstream version string (no leading v, no tag prefix).Stringrequired

github_source_repository

load("@rules_github//github:repositories.bzl", "github_source_repository")

github_source_repository(name, allow_unverified, build_file, build_file_content, repo, sha256,
                         strip_prefix_template, tag_format, version)

Fetch a source tarball from a GitHub release tag.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this repository.Namerequired
allow_unverifiedSkip sha256 requirement; downgrade missing sha to warning.BooleanoptionalFalse
build_fileBUILD.bazel content as a label.LabeloptionalNone
build_file_contentInline BUILD.bazel content. Either this OR build_file must be set.Stringoptional""
repoGitHub repo as owner/name.Stringrequired
sha256sha256 of the auto-generated source tarball. Required unless allow_unverified = True.Stringoptional""
strip_prefix_templateOverride strip-prefix pattern. Default: <repo-basename>-{version} (matches GitHub’s auto-tarball convention).Stringoptional""
tag_formatRelease tag pattern. Same semantics as github_binary_repository.Stringoptional"v{version}"
versionUpstream version string.Stringrequired

Conformance#

No gate findings. 8 contested atoms. See how gating works or the full report.

Contested atoms

Third-party modules where this module resolves a different version than others do. Not a violation of anything this module did — it is the actionable form of a registry-level convergence finding, and the sentence a maintainer can act on.

AtomResolved hereElsewhere
apple_support 1.24.2 2.2.0 ×1
bazel_skylib 1.8.2 1.9.0 ×2
nlohmann_json 3.6.1 3.12.0.bcr.1 ×1
protobuf 33.4 34.0.bcr.1 ×2
rules_jvm_external 6.7 6.8 ×4
rules_python 1.7.0 2.0.1 ×1
rules_swift 3.1.2 3.6.1 ×1
upb 0.0.0-20220923-a547704 0.0.0-20230516-61a97ef ×1

Dependencies#

rules_github in the registry graph — what it depends on (left) and what depends on it (right).

Depends on

platforms0.0.10bazel_skylib1.7.1stardoc0.7.2devrules_shell0.4.1dev

Used by (5 in the registry)

Versions#

3 published versions, newest first. Each resolves to an immutable, integrity-checked archive.

VersionIntegrity (sha256)Source archive
0.1.2 latest D4ETRrFeQ6p4xAHm… tag archive ↗
0.1.1 snzsRW6ro/YUbcAS… tag archive ↗
0.1.0 U0zYSoQclbXfAXrA… tag archive ↗

Changelog#

All notable changes to rules_github. The format is loosely Keep a Changelog — version headers mirror the published bazel-registry entries.

0.1.2 — commit-pinned sources + bzlmod extension

  • github_source_repository gains a commit attr: fetch archive/<sha>.tar.gz for repos without release tags (e.g. research repos like HowieHwong/MetaTool). version and commit are mutually exclusive; exactly one is required. strip_prefix_template now also substitutes {commit}.
  • New //github:extensions.bzl module extension (github) with github.source / github.binary tag classes, so the repository rules are usable directly from MODULE.bazel under bzlmod without a hand-rolled consumer extension.

0.1.1 — public bzl_library targets

  • Mark bzl_library targets as public so downstream stardoc builds in consumer repos (rules_bun, rules_postgres, …) can depend on them.

0.1.0 — initial release

  • First cut of shared Bazel repository rules for fetching content from GitHub releases: github_binary_repository (per-platform release asset URLs) and github_source_repository (tag tarball URLs). Acts as the common substrate beneath fastverk’s other rules_* modules.

← All modules