Skip to content

Commit 16720ef

Browse files
committed
Add support for Bzlmod (fixes #515).
Specifically, this allows P4Runtime users to use Bzlmod. I am not yet enabling Blzmod for P4Runtime itself. I plan to do so in a follow up PR. Signed-off-by: Steffen Smolka <[email protected]>
1 parent 1b44d49 commit 16720ef

12 files changed

+826
-1
lines changed

bazel/example/using-bzlmod/.bazelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Use Bzlmod instead of WORKSPACE.
2+
common --enable_bzlmod
3+
common --noenable_workspace
4+
5+
# C++14 required for recent gRPC versions
6+
build --cxxopt='-std=c++14'
File renamed without changes.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
bazel_dep(
2+
name = "p4runtime",
3+
repo_name = "com_github_p4lang_p4runtime",
4+
)
5+
6+
# In your own project, you will likely want to use `http_archive` instead
7+
# of `local_repository` to load p4runtime.
8+
local_path_override(
9+
module_name = "p4runtime",
10+
path = "../../../proto",
11+
)
12+
13+
# git_override(
14+
# module_name = "p4runtime",
15+
# strip_prefix = "p4runtime-1.4.1/proto",
16+
# urls = ["https://github.com/p4lang/p4runtime/archive/v1.4.1.tar.gz"],
17+
# # sha256 = "<insert hash value here>",
18+
# )
19+
20+
bazel_dep(
21+
name = "protobuf",
22+
version = "29.1",
23+
repo_name = "com_google_protobuf",
24+
)

bazel/example/using-bzlmod/MODULE.bazel.lock

+727
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cc_binary(
2+
name = "hello_p4runtime",
3+
srcs = ["hello_p4runtime.cc"],
4+
deps = [
5+
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
6+
"@com_google_protobuf//:protobuf",
7+
]
8+
)

bazel/example/WORKSPACE.bazel bazel/example/using-workspace/WORKSPACE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
55
# of `local_repository` to load p4runtime.
66
local_repository(
77
name = "com_github_p4lang_p4runtime",
8-
path = "../../proto",
8+
path = "../../../proto",
99
)
1010
# http_archive(
1111
# name = "com_github_p4lang_p4runtime",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
#include "google/protobuf/text_format.h"
4+
#include "p4/config/v1/p4info.pb.h"
5+
6+
using ::google::protobuf::TextFormat;
7+
using ::p4::config::v1::P4Info;
8+
9+
int main() {
10+
P4Info p4info;
11+
TextFormat::ParseFromString(R"PROTO(
12+
tables {
13+
preamble {
14+
id: 10
15+
name: "Hello, P4Runtime!"
16+
}
17+
}
18+
)PROTO", &p4info);
19+
p4info.mutable_tables()->at(0).mutable_preamble()->set_id(42);
20+
std::cout << p4info.DebugString();
21+
}

proto/MODULE.bazel

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module(
2+
name = "p4runtime",
3+
repo_name = "com_github_p4lang_p4runtime",
4+
)
5+
6+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
7+
bazel_dep(
8+
name = "googleapis",
9+
version = "0.0.0-20240819-fe8ba054a",
10+
repo_name = "com_google_googleapis",
11+
)
12+
13+
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
14+
switched_rules.use_languages(
15+
cc = True,
16+
go = True,
17+
grpc = True,
18+
python = True,
19+
)
20+
use_repo(switched_rules, "com_google_googleapis_imports")
21+
22+
bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
23+
bazel_dep(
24+
name = "protobuf",
25+
version = "29.1",
26+
repo_name = "com_google_protobuf",
27+
)
28+
bazel_dep(name = "rules_license", version = "1.0.0")
29+
bazel_dep(name = "rules_proto", version = "7.0.2")
30+
bazel_dep(
31+
name = "rules_go",
32+
version = "0.50.1",
33+
repo_name = "io_bazel_rules_go",
34+
)

proto/WORKSPACE.bzlmod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://bazel.build/external/migration#workspace.bzlmod
2+
#
3+
# This file is intentionally empty. When bzlmod is enabled and this
4+
# file exists, the contents of WORKSPACE.bazel is ignored. This prevents
5+
# bzlmod builds from unintentionally depending on the WORKSPACE.bazel file.

0 commit comments

Comments
 (0)