Skip to content

Commit

Permalink
Add support for Bzlmod, Bazel 7/8, Ubuntu 24.04 (fixes #515, fixes #516
Browse files Browse the repository at this point in the history
…, fixes #514).

Signed-off-by: Steffen Smolka <[email protected]>
  • Loading branch information
smolkaj committed Dec 18, 2024
1 parent a41e728 commit 8bbc4c3
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 21 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/ci-build-proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: "build protobufs"

on:
push:
branches:
branches:
- main
- '*-dev'
pull_request:
branches:
branches:
- main
- '*-dev'
schedule:
Expand All @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Mount bazel cache
uses: actions/cache@v2
with:
Expand All @@ -33,14 +33,11 @@ jobs:
restore-keys: |
bazel-${{ runner.os }}-build-
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.15.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: Build proto/
run: cd proto && bazel build //... && bazel test //...

- name: Build bazel/example/
run: cd bazel/example/ && bazel build //...
- name: Build bazel/example/using-workspace/
run: cd bazel/example/using-workspace && bazel build //...

- name: Build bazel/example/using-bzlmod/
run: cd bazel/example/using-bzlmod && bazel build //...
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Emacs
*~
docs/v1/build/
bazel-*
.DS_Store
build
dist
*.egg-info
.eggs

# rust
# Rust
target/

# Bazel
bazel-*
*.lock
4 changes: 0 additions & 4 deletions bazel/example/.bazelrc

This file was deleted.

1 change: 0 additions & 1 deletion bazel/example/.bazelversion

This file was deleted.

6 changes: 6 additions & 0 deletions bazel/example/using-bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`.
common --enable_bzlmod
common --noenable_workspace

# C++14 required for recent gRPC versions
build --cxxopt='-std=c++14'
File renamed without changes.
24 changes: 24 additions & 0 deletions bazel/example/using-bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
bazel_dep(
name = "p4runtime",
repo_name = "com_github_p4lang_p4runtime",
)

# In your own project, you will likely want to use `http_archive` instead
# of `local_repository` to load p4runtime.
local_path_override(
module_name = "p4runtime",
path = "../../../proto",
)

# git_override(
# module_name = "p4runtime",
# strip_prefix = "p4runtime-1.4.1/proto",
# urls = ["https://github.com/p4lang/p4runtime/archive/v1.4.1.tar.gz"],
# # sha256 = "<insert hash value here>",
# )

bazel_dep(
name = "protobuf",
version = "29.1",
repo_name = "com_google_protobuf",
)
File renamed without changes.
6 changes: 6 additions & 0 deletions bazel/example/using-workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use `WORKSPACE.bazel` instead of bzlmod (`MODULE.bazel`).
common --enable_workspace
common --noenable_bzlmod

# C++14 required for recent gRPC versions
build --cxxopt='-std=c++14'
1 change: 1 addition & 0 deletions bazel/example/using-workspace/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4.1
8 changes: 8 additions & 0 deletions bazel/example/using-workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_binary(
name = "hello_p4runtime",
srcs = ["hello_p4runtime.cc"],
deps = [
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_google_protobuf//:protobuf",
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# of `local_repository` to load p4runtime.
local_repository(
name = "com_github_p4lang_p4runtime",
path = "../../proto",
path = "../../../proto",
)
# http_archive(
# name = "com_github_p4lang_p4runtime",
Expand Down
21 changes: 21 additions & 0 deletions bazel/example/using-workspace/hello_p4runtime.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>

#include "google/protobuf/text_format.h"
#include "p4/config/v1/p4info.pb.h"

using ::google::protobuf::TextFormat;
using ::p4::config::v1::P4Info;

int main() {
P4Info p4info;
TextFormat::ParseFromString(R"PROTO(
tables {
preamble {
id: 10
name: "Hello, P4Runtime!"
}
}
)PROTO", &p4info);
p4info.mutable_tables()->at(0).mutable_preamble()->set_id(42);
std::cout << p4info.DebugString();
}
4 changes: 3 additions & 1 deletion proto/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# bazelrc file
# Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`.
common --enable_bzlmod
common --noenable_workspace

# C++14 required for recent gRPC versions
build --cxxopt='-std=c++14'
1 change: 0 additions & 1 deletion proto/.bazelversion

This file was deleted.

38 changes: 38 additions & 0 deletions proto/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module(
name = "p4runtime",
bazel_compatibility = [">=7.4.1"],
repo_name = "com_github_p4lang_p4runtime",
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(
name = "googleapis",
version = "0.0.0-20240819-fe8ba054a",
repo_name = "com_google_googleapis",
)
bazel_dep(
name = "grpc",
version = "1.68.0",
repo_name = "com_github_grpc_grpc",
)
bazel_dep(
name = "protobuf",
version = "29.1",
repo_name = "com_google_protobuf",
)
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(
name = "rules_go",
version = "0.50.1",
repo_name = "io_bazel_rules_go",
)

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(
cc = True,
go = True,
grpc = True,
python = True,
)
use_repo(switched_rules, "com_google_googleapis_imports")
5 changes: 5 additions & 0 deletions proto/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://bazel.build/external/migration#workspace.bzlmod
#
# This file is intentionally empty. When bzlmod is enabled and this
# file exists, the contents of WORKSPACE.bazel is ignored. This prevents
# bzlmod builds from unintentionally depending on the WORKSPACE.bazel file.

0 comments on commit 8bbc4c3

Please sign in to comment.