generated from bazel-contrib/rules-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
537 additions
and
520 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"homepage": "https://github.com/myorg/rules_mylang", | ||
"homepage": "https://github.com/alexeagle/rules_protoc", | ||
"maintainers": [], | ||
"repository": ["github:myorg/rules_mylang"], | ||
"repository": ["github:alexeagle/rules_protoc"], | ||
"versions": [], | ||
"yanked_versions": {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Mirror Releases | ||
on: | ||
# Trigger manually in the UI | ||
workflow_dispatch: | ||
# Trigger daily at 06:10 UTC | ||
schedule: | ||
- cron: "10 6 * * *" | ||
|
||
jobs: | ||
mirror: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: | | ||
./protoc/private/mirror_protoc_releases.sh | ||
npx @bazel/buildifier protoc/private/versions.bzl | ||
- uses: peter-evans/create-pull-request@v5 | ||
with: | ||
commit-message: "chore: mirror protoc release" |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ bazel-* | |
.bazelrc.user | ||
.idea/ | ||
.ijwb/ | ||
# Ignore until it is more stable | ||
MODULE.bazel.lock |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +0,0 @@ | ||
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") | ||
|
||
gazelle_binary( | ||
name = "gazelle_bin", | ||
languages = ["@bazel_skylib_gazelle_plugin//bzl"], | ||
) | ||
|
||
gazelle( | ||
name = "gazelle", | ||
gazelle = "gazelle_bin", | ||
) | ||
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
"Bazel dependencies" | ||
|
||
module( | ||
name = "com_myorg_rules_mylang", | ||
name = "toolchains_protoc", | ||
version = "0.0.0", | ||
compatibility_level = 1, | ||
) | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.4.1") | ||
bazel_dep(name = "platforms", version = "0.0.5") | ||
bazel_dep(name = "rules_proto", version = "6.0.0-rc2") | ||
bazel_dep(name = "platforms", version = "0.0.8") | ||
|
||
bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True, repo_name = "bazel_gazelle") | ||
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True) | ||
bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True) | ||
bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True) | ||
|
||
mylang = use_extension("//mylang:extensions.bzl", "mylang") | ||
mylang.toolchain(mylang_version = "1.14.2") | ||
use_repo(mylang, "mylang_toolchains") | ||
protoc = use_extension("//protoc:extensions.bzl", "protoc") | ||
protoc.toolchain(version = "v25.3") | ||
use_repo(protoc, "toolchains_protoc_hub") | ||
|
||
register_toolchains("@mylang_toolchains//:all") | ||
register_toolchains("@toolchains_protoc_hub//:all") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,28 @@ | ||
# Template for Bazel rules | ||
# Bazel toolchain for pre-built protoc | ||
|
||
Copy this template to create a Bazel ruleset. | ||
protoc has always been distributed as pre-built binaries on https://github.com/protocolbuffers/protobuf/releases | ||
|
||
Features: | ||
Bazel 7 introduced `--incompatible_enable_proto_toolchain_resolution` to allow us fetch that binary rather than re-build it! | ||
|
||
- follows the official style guide at https://docs.bazel.build/versions/main/skylark/deploying.html | ||
- allows for both WORKSPACE.bazel and bzlmod (MODULE.bazel) usage | ||
- includes Bazel formatting as a pre-commit hook (using [buildifier]) | ||
- includes stardoc API documentation generator | ||
- includes typical toolchain setup | ||
- CI configured with GitHub Actions | ||
- release using GitHub Actions just by pushing a tag | ||
- the release artifact doesn't need to be built by Bazel, but can still exclude files and stamp the version | ||
See https://github.com/bazelbuild/examples/blob/never_compile_protoc_again/proto/README.md | ||
|
||
See https://docs.bazel.build/versions/main/skylark/deploying.html#readme | ||
## Why a separate Bazel module? | ||
|
||
[buildifier]: https://github.com/bazelbuild/buildtools/tree/master/buildifier#readme | ||
This belongs in rules_proto, see | ||
|
||
Ready to get started? Copy this repo, then | ||
- https://github.com/bazelbuild/rules_proto/pull/205 | ||
- https://github.com/bazelbuild/rules_proto/pull/206 | ||
|
||
1. search for "com_myorg_rules_mylang" and replace with the name you'll use for your workspace | ||
1. search for "myorg" and replace with GitHub org | ||
1. search for "mylang", "Mylang", "MYLANG" and replace with the language/tool your rules are for | ||
1. rename directory "mylang" similarly | ||
1. run `pre-commit install` to get lints (see CONTRIBUTING.md) | ||
1. if you don't need to fetch platform-dependent tools, then remove anything toolchain-related. | ||
1. (optional) install the [Renovate app](https://github.com/apps/renovate) to get auto-PRs to keep the dependencies up-to-date. | ||
1. delete this section of the README (everything up to the SNIP). | ||
|
||
---- SNIP ---- | ||
|
||
# Bazel rules for mylang | ||
Getting reviews from Googlers is hard so let's not wait for them. | ||
|
||
## Installation | ||
|
||
From the release you wish to use: | ||
<https://github.com/myorg/rules_mylang/releases> | ||
copy the WORKSPACE snippet into your `WORKSPACE` file. | ||
|
||
To use a commit rather than a release, you can point at any SHA of the repo. | ||
Make sure your `.bazelrc` contains | ||
|
||
For example to use commit `abc123`: | ||
``` | ||
# Introduced in Bazel 7. | ||
common --incompatible_enable_proto_toolchain_resolution | ||
``` | ||
|
||
1. Replace `url = "https://github.com/myorg/rules_mylang/releases/download/v0.1.0/rules_mylang-v0.1.0.tar.gz"` with a GitHub-provided source archive like `url = "https://github.com/myorg/rules_mylang/archive/abc123.tar.gz"` | ||
1. Replace `strip_prefix = "rules_mylang-0.1.0"` with `strip_prefix = "rules_mylang-abc123"` | ||
1. Update the `sha256`. The easiest way to do this is to comment out the line, then Bazel will | ||
print a message with the correct value. Note that GitHub source archives don't have a strong | ||
guarantee on the sha256 stability, see | ||
<https://github.blog/2023-02-21-update-on-the-future-stability-of-source-code-archives-and-hashes/> | ||
Follow instructions from the release you wish to use: | ||
<https://github.com/alexeagle/rules_protoc/releases> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# The main ingredient: allow us to register toolchains other than com_google_protobuf targets | ||
common --incompatible_enable_proto_toolchain_resolution |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
"""Provides a simple way to test your rules as an external workspace. | ||
Add a basic smoke-test target below. | ||
""" | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
# load("@com_myorg_rules_mylang//mylang:defs.bzl", "...") | ||
|
||
# Replace with a usage of your rule/macro | ||
filegroup(name = "empty") | ||
|
||
build_test( | ||
name = "smoke_test", | ||
targets = [ | ||
# targets you add above | ||
":empty", | ||
], | ||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
bazel_dep(name = "com_myorg_rules_mylang", version = "0.0.0", dev_dependency = True) | ||
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) | ||
bazel_dep(name = "toolchains_protoc", version = "0.0.0") | ||
bazel_dep(name = "rules_proto", version = "6.0.0-rc2") | ||
|
||
local_path_override( | ||
module_name = "com_myorg_rules_mylang", | ||
module_name = "toolchains_protoc", | ||
path = "../..", | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
# smoke test | ||
# No compiling protoc! | ||
|
||
This e2e exercises the repo from an end-users perpective. | ||
It catches mistakes in our install instructions, or usages that fail when called from an "external" repository to rules_mylang. | ||
It is also used by the presubmit check for the Bazel Central Registry. | ||
``` | ||
time bazel --output_base=$(mktemp -d) build :all | ||
Starting local Bazel server and connecting to it... | ||
INFO: Analyzed target //:foo_proto (38 packages loaded, 164 targets configured). | ||
INFO: Found 1 target... | ||
Target //:foo_proto up-to-date: | ||
bazel-bin/foo_proto-descriptor-set.proto.bin | ||
INFO: Elapsed time: 1.761s, Critical Path: 0.02s | ||
INFO: 2 processes: 1 internal, 1 linux-sandbox. | ||
INFO: Build completed successfully, 2 total actions | ||
real 0m2.148s | ||
user 0m0.033s | ||
sys 0m0.005s | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
# Override http_archive for local testing | ||
local_repository( | ||
name = "com_myorg_rules_mylang", | ||
name = "toolchains_protoc", | ||
path = "../..", | ||
) | ||
|
||
#---SNIP--- Below here is re-used in the workspace snippet published on releases | ||
|
||
###################### | ||
# rules_mylang setup # | ||
# rules_protoc setup # | ||
###################### | ||
# Fetches the rules_mylang dependencies. | ||
# Fetches the rules_protoc dependencies. | ||
# If you want to have a different version of some dependency, | ||
# you should fetch it *before* calling this. | ||
# Alternatively, you can skip calling this function, so long as you've | ||
# already fetched all the dependencies. | ||
load("@com_myorg_rules_mylang//mylang:repositories.bzl", "rules_mylang_dependencies") | ||
load("@toolchains_protoc//protoc:repositories.bzl", "rules_protoc_dependencies") | ||
|
||
rules_mylang_dependencies() | ||
rules_protoc_dependencies() | ||
|
||
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") | ||
|
||
rules_proto_dependencies() | ||
|
||
load("@bazel_features//:deps.bzl", "bazel_features_deps") | ||
|
||
bazel_features_deps() | ||
|
||
load("@toolchains_protoc//protoc:toolchain.bzl", "protoc_toolchains") | ||
|
||
protoc_toolchains( | ||
name = "protoc_toolchains", | ||
version = "v25.3", | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
message Foo { | ||
string msg = 1; | ||
} |
Oops, something went wrong.