Skip to content

Commit 17e78a3

Browse files
authored
refactor: examples folder standalone (#25)
1 parent 50468cd commit 17e78a3

File tree

26 files changed

+183
-149
lines changed

26 files changed

+183
-149
lines changed

.bazelignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
e2e/
1+
e2e/
2+
examples/

.bazelrc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@
22
# Take care to document any settings that you expect users to apply.
33
# Settings that apply only to CI are in .github/workflows/ci.bazelrc
44

5-
# The main ingredient: allow us to register toolchains other than com_google_protobuf targets
6-
common --incompatible_enable_proto_toolchain_resolution
7-
common --@aspect_rules_py//py:interpreter_version=3.9.18
8-
9-
# See https://github.com/bazelbuild/rules_python/issues/1069#issuecomment-1942053014
10-
common --action_env=RULES_PYTHON_ENABLE_PYSTAR=0
11-
12-
# Don’t want to push a rules author to update their deps if not needed.
13-
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
14-
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
15-
common --check_direct_dependencies=off
16-
17-
# Force rules_go to disable CGO even though we have a (fake) C++ toolchain registered.
18-
common --host_platform=//:no_cgo_host_platform
19-
205
# Load any settings specific to the current user.
216
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
227
# This needs to be last statement in this

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ jobs:
2020
test:
2121
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
2222
with:
23-
folders: '[".", "e2e/smoke"]'
23+
folders: '[".", "e2e/smoke", "examples"]'
2424
exclude: |
2525
[
2626
{"bazelversion": "6.4.0"},
2727
{"folder": ".", "bzlmodEnabled": false},
28+
{"folder": "examples", "bzlmodEnabled": false},
2829
{"folder": ".", "os": "windows-latest"}
2930
]

.github/workflows/release_prep.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
1616
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
1717

1818
cat << EOF
19-
## Using Bzlmod with Bazel 6
19+
## Using Bzlmod with Bazel 6 or later
2020
21-
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
21+
1. (Bazel 6 only) Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
2222
2. Add to your \`MODULE.bazel\` file:
2323
2424
\`\`\`starlark
@@ -33,6 +33,9 @@ protoc.toolchain(
3333
# Pin to any version of protoc
3434
version = "v26.0",
3535
)
36+
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")
37+
38+
register_toolchains("@toolchains_protoc_hub//:all")
3639
\`\`\`
3740
3841
## Using WORKSPACE

BUILD.bazel

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
22

3-
platform(
4-
name = "no_cgo_host_platform",
5-
constraint_values = HOST_CONSTRAINTS + [
6-
"@rules_go//go/toolchain:cgo_off",
7-
],
3+
# Placeholder until there are docs tests
4+
build_test(
5+
name = "tautology",
6+
targets = ["//:BUILD.bazel"],
87
)

MODULE.bazel

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,13 @@ bazel_dep(name = "bazel_skylib", version = "1.4.1")
1111
bazel_dep(name = "rules_proto", version = "6.0.0")
1212
bazel_dep(name = "platforms", version = "0.0.10")
1313

14-
protoc = use_extension("//protoc:extensions.bzl", "protoc")
14+
bazel_dep(name = "aspect_bazel_lib", version = "2.8.1", dev_dependency = True)
15+
bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)
16+
17+
protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
1518
protoc.toolchain(
16-
google_protobuf = "com_google_protobuf",
1719
version = "v27.3",
1820
)
19-
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")
21+
use_repo(protoc, "toolchains_protoc_hub")
2022

2123
register_toolchains("@toolchains_protoc_hub//:all")
22-
23-
# Assert no CC compilation occurs
24-
register_toolchains(
25-
"//tools/toolchains:all",
26-
dev_dependency = True,
27-
)
28-
29-
bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
30-
bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)
31-
bazel_dep(name = "aspect_rules_py", version = "0.7.1", dev_dependency = True)
32-
bazel_dep(name = "rules_java", version = "7.4.0", dev_dependency = True)
33-
bazel_dep(name = "rules_python", version = "0.32.2", dev_dependency = True)
34-
bazel_dep(name = "rules_go", version = "0.48.0", dev_dependency = True)
35-
bazel_dep(name = "rules_uv", version = "0.10.0", dev_dependency = True)
36-
37-
register_toolchains(
38-
"//examples/lang_toolchains:all",
39-
dev_dependency = True,
40-
)
41-
42-
# Shows how a typical Python user fetches all the dependencies of their app, including the protobuf runtime
43-
dev_pip = use_extension(
44-
"@rules_python//python/extensions:pip.bzl",
45-
"pip",
46-
dev_dependency = True,
47-
)
48-
dev_pip.parse(
49-
hub_name = "pypi",
50-
python_version = "3.11",
51-
requirements_lock = "//examples/lang_toolchains:requirements.txt",
52-
)
53-
use_repo(dev_pip, "pypi")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Using Protocol Buffers with Bazel has always been difficult.
99
- Nearly every Bazel user has waited for `protoc` to compile from sources many, MANY times.
1010
This universally slows down builds, especially due to issues like https://github.com/bazelbuild/bazel/issues/7095 where it is observed to be easily cache-busted.
1111
- The protobuf Bazel module is quite complex and maintenance and support from the protobuf team has been inconsistent.
12-
By using pre-built artifacts, Bazel users can follow the same well-tested as users of other build systems.
12+
By using pre-built artifacts, Bazel users can follow the same well-tested codepaths as users of other build systems.
1313
- Relying on the protobuf runtime for each language from the `@com_google_protobuf` repo forces you to use
1414
the same version of the runtime for all languages in a monorepo, and matching protoc.
1515
This makes it difficult to migrate to a monorepo, allowing some applications to move from their separate repo without

WORKSPACE.bazel

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
11
# Marker that this is the root of a Bazel workspace.
2-
3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
4-
5-
# Note: this is simpler than using rules_jvm_external with a maven installation,
6-
# but users would probably get this JAR file that way.
7-
http_jar(
8-
name = "protobuf-java",
9-
sha256 = "0532ad1024d62361561acaedb974d7d16889e7670b36e23e9321dd6b9d334ef9",
10-
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.27.0-RC3/protobuf-java-4.27.0-RC3.jar"],
11-
)

examples/.bazelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The main ingredient: allow us to register toolchains other than com_google_protobuf targets
2+
common --incompatible_enable_proto_toolchain_resolution
3+
common --@aspect_rules_py//py:interpreter_version=3.9.18
4+
5+
# See https://github.com/bazelbuild/rules_python/issues/1069#issuecomment-1942053014
6+
common --action_env=RULES_PYTHON_ENABLE_PYSTAR=0
7+
8+
# Force rules_go to disable CGO even though we have a (fake) C++ toolchain registered.
9+
common --host_platform=//tools:no_cgo_host_platform

examples/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.3.0

0 commit comments

Comments
 (0)