Skip to content

Commit d4365f1

Browse files
authored
Bazel build: use Clang and bump rules_foreign and protobuf versions. (#5148)
Signed-off-by: Steffen Smolka <smolkaj@google.com>
1 parent d647430 commit d4365f1

File tree

6 files changed

+70
-25
lines changed

6 files changed

+70
-25
lines changed

.bazelrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ common --enable_workspace
33
# Enable once #5066 is resolved.
44
common --noenable_bzlmod
55

6-
build --action_env=BAZEL_CXXOPTS="-std=c++17"
6+
# Use C++17.
7+
build --cxxopt=-std=c++17
8+
build --host_cxxopt=-std=c++17
9+
10+
# Force the use of Clang for all builds.
11+
build --action_env=CC=clang
12+
build --action_env=CXX=clang++

WORKSPACE.bazel

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ load("//:bazel/p4c_deps.bzl", "p4c_deps")
66

77
p4c_deps()
88

9+
# -- Load Rules Foreign CC -----------------------------------------------------
10+
11+
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
12+
13+
# This sets up some common toolchains for building targets. For more details, please see
14+
# https://bazel-contrib.github.io/rules_foreign_cc/0.14.0/flatten.html#rules_foreign_cc_dependencies
15+
rules_foreign_cc_dependencies()
16+
17+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
18+
19+
bazel_skylib_workspace()
20+
21+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
22+
23+
bazel_features_deps()
24+
25+
load("@rules_python//python:repositories.bzl", "py_repositories")
26+
27+
py_repositories()
28+
929
# -- Dependencies of dependencies. ---------------------------------------------
1030

1131
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
@@ -38,12 +58,6 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
3858

3959
grpc_extra_deps()
4060

41-
# -- Load Rules Foreign CC -----------------------------------------------------
42-
43-
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
44-
45-
rules_foreign_cc_dependencies()
46-
4761
# -- Load Buildifier (for formatting) ------------------------------------------
4862

4963
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
@@ -63,10 +77,6 @@ load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
6377

6478
buildifier_prebuilt_deps()
6579

66-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
67-
68-
bazel_skylib_workspace()
69-
7080
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")
7181

7282
buildifier_prebuilt_register_toolchains()

bazel/BUILD.z3.bazel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ filegroup(
77

88
configure_make(
99
name = "api",
10+
args = [
11+
"--directory build",
12+
"-j8",
13+
],
14+
configure_in_place = True,
1015
# Bazel redacts certain cc macros such as __DATA__ and __TIMESTAMP__
1116
# since they will cause the compiled code to have timestamps or other
1217
# similar information in it, causing the compilation to be
@@ -25,19 +30,14 @@ configure_make(
2530
# 0, which is a valid c++ expression.
2631
# This is a minor improvement on top of:
2732
# https://github.com/bazelbuild/rules_foreign_cc/issues/239
28-
configure_env_vars = {
33+
env = {
2934
"CFLAGS": "-Dredacted=0",
3035
"CXXFLAGS": "-Dredacted=0",
3136
"PYTHON": "python3",
3237
},
33-
configure_in_place = True,
3438
lib_source = ":all",
35-
make_commands = [
36-
"cd build",
37-
"make -j8", # Use -j8, hardcoded but otherwise it will be too slow.
38-
"make install",
39-
],
4039
out_binaries = ["z3"],
4140
out_shared_libs = ["libz3.so"],
41+
targets = ["install"],
4242
visibility = ["//visibility:public"],
4343
)

bazel/example/.bazelrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ common --enable_workspace
33
# Enable once #5066 is resolved.
44
common --noenable_bzlmod
55

6-
build --action_env=BAZEL_CXXOPTS="-std=c++17"
6+
# Use C++17.
7+
build --cxxopt=-std=c++17
8+
build --host_cxxopt=-std=c++17
9+
10+
# Force the use of Clang for all builds.
11+
build --action_env=CC=clang
12+
build --action_env=CXX=clang++

bazel/example/WORKSPACE.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
workspace(name = "example_p4_project")
22

3+
# -- Direct dependencies. ------------------------------------------------------
4+
35
# May replace this with `git_repository` or `http_archive` in your own project.
46
local_repository(
57
name = "com_github_p4lang_p4c",
@@ -16,6 +18,26 @@ load("@com_github_p4lang_p4c//:bazel/p4c_deps.bzl", "p4c_deps")
1618

1719
p4c_deps()
1820

21+
# -- Load Rules Foreign CC -----------------------------------------------------
22+
23+
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
24+
25+
# This sets up some common toolchains for building targets. For more details, please see
26+
# https://bazel-contrib.github.io/rules_foreign_cc/0.14.0/flatten.html#rules_foreign_cc_dependencies
27+
rules_foreign_cc_dependencies()
28+
29+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
30+
31+
bazel_skylib_workspace()
32+
33+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
34+
35+
bazel_features_deps()
36+
37+
load("@rules_python//python:repositories.bzl", "py_repositories")
38+
39+
py_repositories()
40+
1941
# -- Dependencies of dependencies. ---------------------------------------------
2042

2143
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")

bazel/p4c_deps.bzl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,17 @@ filegroup(
7979
if not native.existing_rule("com_google_protobuf"):
8080
http_archive(
8181
name = "com_google_protobuf",
82-
url = "https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protobuf-25.3.tar.gz",
83-
strip_prefix = "protobuf-25.3",
84-
sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e",
82+
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.3/protobuf-29.3.tar.gz",
83+
strip_prefix = "protobuf-29.3",
84+
integrity = "sha256-AIoRzFb5uWZ5tMKF/QX0bTF9aFvjq1JLKjEL4PutmH4=",
85+
# sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e",
8586
)
8687
if not native.existing_rule("rules_foreign_cc"):
8788
http_archive(
8889
name = "rules_foreign_cc",
89-
sha256 = "d54742ffbdc6924f222d2179f0e10e911c5c659c4ae74158e9fe827aad862ac6",
90-
strip_prefix = "rules_foreign_cc-0.2.0",
91-
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz",
90+
sha256 = "e0f0ebb1a2223c99a904a565e62aa285bf1d1a8aeda22d10ea2127591624866c",
91+
strip_prefix = "rules_foreign_cc-0.14.0",
92+
url = "https://github.com/bazel-contrib/rules_foreign_cc/releases/download/0.14.0/rules_foreign_cc-0.14.0.tar.gz",
9293
)
9394
if not native.existing_rule("com_github_z3prover_z3"):
9495
http_archive(

0 commit comments

Comments
 (0)