Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel: Migrate to bazel 7; use bzlmod for dependencies #284

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The examples/ dir has example bazel workspaces that show how to import
# remote-apis, and should not be treated as part of this workspace.
examples
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.1
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ jobs:

- name: Install bazelisk
run: |
curl -LO https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64
curl -LO https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64
mkdir -p "${HOME}/bin"
mv bazelisk-linux-amd64 "${HOME}/bin/bazel"
chmod +x "${HOME}/bin/bazel"

# TODO: Should this step assert that generated code == checked-in code?
- name: Check bindings generation
run: |
set -e
PATH=${HOME}/bin:$PATH ./hooks/pre-commit

- name: Check sample project build
run: |
set -e
cd examples/sample_project
bazel build //...
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
*~
# Ignore Vim swap files.
.*.sw*
# Ignore bazel directories
/bazel-bin
/bazel-genfiles
/bazel-out
/bazel-remote-apis
/bazel-testlogs
# Ignore bazel directories, including those in nested workspaces (such as the
# examples).
**/bazel-*
Copy link
Author

Choose a reason for hiding this comment

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

Can we assume a sufficiently up-to-date git client version?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's a reasonable assumption. If we find that this breaks someone, it's easy to revert back to the explicit list of directories.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, how's this different from just "bazel-*"?

Copy link
Author

Choose a reason for hiding this comment

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

(just double-checked to confirm) This ignores bazel-generated symlinks in repo subdirs, not just the toplevel, which is significant because there now exist example workspaces where one can cd to and run builds.

Clarified the comment above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I get that **/bazel-* would indeed ignore that. But why can't we just use bazel-*? So without a leading slash, without a leading anything.


10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/bazelbuild/remote-apis

# gazelle:resolve proto google/api/annotations.proto @googleapis//google/api:annotations_proto
# gazelle:resolve proto go google/api/annotations.proto @org_golang_google_genproto//googleapis/api/annotations

gazelle(
name = "gazelle",
)
64 changes: 64 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""remote-apis dependencies"""

module(
name = "bazel_remote_apis",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name = "bazel_remote_apis",
name = "remoteapis",

bazel itself uses this name, not sure which should be preferred

repo_name = "com_github_bazelbuild_remote_apis",
)

# deps
bazel_dep(name = "gazelle", version = "0.35.0")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_go", version = "0.44.2")
bazel_dep(name = "rules_java", version = "7.3.2")
bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
bazel_dep(name = "rules_proto_grpc_cpp", version = "5.0.0-alpha2")
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")

# dev deps
bazel_dep(name = "toolchains_llvm", version = "0.10.3", dev_dependency = True)

# Top-level projects will need a C++ toolchain to build protoc, grpc, etc., but
# we shouldn't dictate their toolchain, so the toolchain is marked as a dev
# dependency.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)
llvm.toolchain(
# This is a version of LLVM that builds absl and upb successfully with their
# default compile options.
#
# TODO: Update this to the latest version of LLVM possible
llvm_version = "13.0.0",
)
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all", dev_dependency = True)

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"org_golang_google_genproto",
"org_golang_google_genproto_googleapis_api",
"org_golang_google_genproto_googleapis_rpc",
"org_golang_google_grpc",
"org_golang_google_protobuf",
)

# googleapis workaround for lack of bzlmod support
# From: https://github.com/bazelbuild/rules_go/issues/3685#issuecomment-1711854475
#
# TODO: Drop this once googleapis has official bzlmod support
bazel_dep(name = "com_google_googleapis", version = "64926d52febbf298cb82a8f472ade4a3969ba922")
archive_override(
module_name = "com_google_googleapis",
integrity = "sha256-nRqTDnZ8k8glOYuPhpLso/41O5qq3t+88fyiKCyF34g=",
patch_strip = 1,
patches = [
"patches/googleapis_add_bzlmod_support.patch",
],
strip_prefix = "googleapis-64926d52febbf298cb82a8f472ade4a3969ba922",
urls = [
"https://github.com/googleapis/googleapis/archive/64926d52febbf298cb82a8f472ade4a3969ba922.zip",
],
)
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages()
use_repo(switched_rules, "com_google_googleapis_imports")
Loading