Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2b622fc

Browse files
committedFeb 25, 2025·
Bazel build: use Clang and bump rules_foreign and protobuf versions.
This is is preparation for migrating to Bzlmod ( #5066), which requires up-to-date versions of all dependencies. Signed-off-by: Steffen Smolka <smolkaj@google.com>
1 parent d647430 commit 2b622fc

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed
 

‎.bazelrc

+7-1
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

+23-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ 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+
# If you're not already using bazel_skylib, bazel_features or rules_python,
18+
# you'll need to add these calls as well.
19+
20+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
21+
22+
bazel_skylib_workspace()
23+
24+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
25+
26+
bazel_features_deps()
27+
28+
load("@rules_python//python:repositories.bzl", "py_repositories")
29+
30+
py_repositories()
31+
932
# -- Dependencies of dependencies. ---------------------------------------------
1033

1134
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
@@ -38,12 +61,6 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
3861

3962
grpc_extra_deps()
4063

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-
4764
# -- Load Buildifier (for formatting) ------------------------------------------
4865

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

6481
buildifier_prebuilt_deps()
6582

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

7285
buildifier_prebuilt_register_toolchains()

‎bazel/BUILD.z3.bazel

+7-7
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

+7-1
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/p4c_deps.bzl

+7-6
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)
Please sign in to comment.