Skip to content

Commit 9328ec9

Browse files
committed
Upgrade to bazel 7
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent bdc1c10 commit 9328ec9

File tree

9 files changed

+64
-33
lines changed

9 files changed

+64
-33
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Global bazelrc file, see https://docs.bazel.build/versions/master/guide.html#bazelrc.
22

3+
common --noenable_bzlmod --enable_workspace
4+
35
# Use strict action env to prevent leaks of env vars.
46
build --incompatible_strict_action_env
57

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.5.0
1+
7.7.1

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ load("@bazel_features//:deps.bzl", "bazel_features_deps")
2323

2424
bazel_features_deps()
2525

26+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
27+
28+
compatibility_proxy_repo()
29+
2630
# Order is important. Try to go from most basic/primitive to higher level packages.
2731
# - go_rules_dependencies
2832
# - protobuf_deps

bazel/cc_toolchains/sysroots/images.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def _sysroot_variant_image_factory(variant):
6565
return _image_from_sysroot_info(ctx, sysroot_toolchain.sysroot)
6666

6767
return rule(
68-
name = "sysroot_{variant}_image".format(variant = variant),
6968
implementation = _impl,
7069
attrs = dicts.add(_container.image.attrs, {
7170
"default_image": attr.label(mandatory = True, doc = "Default container_image to use if no sysroot toolchain is found"),

bazel/cc_toolchains/toolchain_features.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def pl_toolchain_pre_features(ctx):
6666
# pl_toolchain_post_features are added to the command line after all of the default features.
6767
def pl_toolchain_post_features(ctx):
6868
features = []
69-
features += _libstdcpp(ctx)
7069
if ctx.attr.compiler == "clang":
7170
features += _clang_features(ctx)
71+
else:
72+
features += _libstdcpp(ctx)
7273

7374
features += _external_dep(ctx)
7475

@@ -148,6 +149,10 @@ def _libcpp(ctx):
148149
return [
149150
feature(
150151
name = "libc++",
152+
# Enable by default for clang toolchains since they bundle libc++ and don't have libstdc++.
153+
# This is especially important for exec toolchains where --features=libc++ from bazelrc
154+
# may not be applied in Bazel 7+.
155+
enabled = True,
151156
flag_sets = [
152157
flag_set(
153158
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
2-
--- a/cc_toolchain_config.bzl 2023-01-06 15:34:50.000000000 -0800
3-
+++ b/cc_toolchain_config.bzl 2023-01-22 15:33:16.794758043 -0800
4-
@@ -27,6 +27,7 @@
1+
diff --git a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
2+
index 0b77afc..a046faf 100644
3+
--- a/cc_toolchain_config.bzl
4+
+++ b/cc_toolchain_config.bzl
5+
@@ -27,6 +27,7 @@ load(
56
"with_feature_set",
67
)
78
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
89
+load(":toolchain_features.bzl", "pl_toolchain_pre_features", "PL_EXTRA_CC_CONFIG_ATTRS", "pl_toolchain_post_features", "pl_action_configs")
9-
10+
1011
def layering_check_features(compiler):
1112
if compiler != "clang":
12-
@@ -147,7 +148,7 @@
13+
@@ -147,7 +148,7 @@ def _impl(ctx):
1314
tool_path(name = name, path = path)
1415
for name, path in ctx.attr.tool_paths.items()
1516
]
1617
- action_configs = []
1718
+ action_configs = pl_action_configs(ctx)
18-
19+
1920
llvm_cov_action = action_config(
2021
action_name = ACTION_NAMES.llvm_cov,
21-
@@ -168,6 +169,10 @@
22+
@@ -168,6 +169,10 @@ def _impl(ctx):
2223
name = "supports_start_end_lib",
2324
enabled = True,
2425
)
2526
+ default_opt_level_flags_feature = feature(
2627
+ name = "default_opt_level_flags",
2728
+ enabled = True,
2829
+ )
29-
30+
3031
default_compile_flags_feature = feature(
3132
name = "default_compile_flags",
32-
@@ -203,7 +208,7 @@
33+
@@ -203,7 +208,7 @@ def _impl(ctx):
3334
flags = ctx.attr.dbg_compile_flags,
3435
),
3536
] if ctx.attr.dbg_compile_flags else []),
@@ -38,7 +39,7 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
3839
),
3940
flag_set(
4041
actions = all_compile_actions,
41-
@@ -212,7 +217,7 @@
42+
@@ -212,7 +217,7 @@ def _impl(ctx):
4243
flags = ctx.attr.opt_compile_flags,
4344
),
4445
] if ctx.attr.opt_compile_flags else []),
@@ -47,7 +48,7 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
4748
),
4849
flag_set(
4950
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
50-
@@ -244,7 +249,7 @@
51+
@@ -244,7 +249,7 @@ def _impl(ctx):
5152
flags = ctx.attr.opt_link_flags,
5253
),
5354
] if ctx.attr.opt_link_flags else []),
@@ -56,44 +57,57 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
5657
),
5758
],
5859
)
59-
@@ -1255,6 +1260,7 @@
60+
@@ -1255,6 +1260,7 @@ def _impl(ctx):
6061
strip_debug_symbols_feature,
6162
coverage_feature,
6263
supports_pic_feature,
6364
+ default_opt_level_flags_feature,
6465
] + (
6566
[
6667
supports_start_end_lib_feature,
67-
@@ -1276,6 +1282,7 @@
68+
@@ -1276,6 +1282,7 @@ def _impl(ctx):
6869
else:
6970
features = [
7071
supports_pic_feature,
7172
+ default_opt_level_flags_feature,
7273
] + (
7374
[
7475
supports_start_end_lib_feature,
75-
@@ -1294,6 +1301,7 @@
76+
@@ -1294,6 +1301,17 @@ def _impl(ctx):
7677
unfiltered_compile_flags_feature,
7778
] + layering_check_features(ctx.attr.compiler)
78-
79+
7980
+ features = pl_toolchain_pre_features(ctx) + features + pl_toolchain_post_features(ctx)
81+
+
82+
+ sysroot_path = ctx.attr.builtin_sysroot
83+
+ # Only override with toolchain sysroot if this cc_toolchain is configured to use a sysroot
84+
+ # (i.e., builtin_sysroot is non-empty). This prevents exec toolchains from incorrectly
85+
+ # inheriting the target sysroot.
86+
+ if sysroot_path:
87+
+ sysroot_toolchain = ctx.toolchains["@px//bazel/cc_toolchains/sysroots/build:toolchain_type"]
88+
+ if sysroot_toolchain:
89+
+ sysroot_path = sysroot_toolchain.sysroot.path
90+
+
8091
return cc_common.create_cc_toolchain_config_info(
8192
ctx = ctx,
8293
features = features,
83-
@@ -1313,7 +1321,7 @@
84-
94+
@@ -1308,7 +1322,7 @@ def _impl(ctx):
95+
abi_version = ctx.attr.abi_version,
96+
abi_libc_version = ctx.attr.abi_libc_version,
97+
tool_paths = tool_paths,
98+
- builtin_sysroot = ctx.attr.builtin_sysroot,
99+
+ builtin_sysroot = sysroot_path,
100+
)
101+
85102
cc_toolchain_config = rule(
86-
implementation = _impl,
87-
- attrs = {
88-
+ attrs = dict({
89-
"cpu": attr.string(mandatory = True),
90-
"compiler": attr.string(mandatory = True),
91-
"toolchain_identifier": attr.string(mandatory = True),
92-
@@ -1336,6 +1344,6 @@
103+
@@ -1336,5 +1350,8 @@ cc_toolchain_config = rule(
93104
"coverage_link_flags": attr.string_list(),
94105
"supports_start_end_lib": attr.bool(),
95106
"builtin_sysroot": attr.string(),
96107
- },
97-
+ }, **PL_EXTRA_CC_CONFIG_ATTRS),
108+
+ } | PL_EXTRA_CC_CONFIG_ATTRS,
98109
provides = [CcToolchainConfigInfo],
110+
+ toolchains = [
111+
+ config_common.toolchain_type("@px//bazel/cc_toolchains/sysroots/build:toolchain_type", mandatory = False),
112+
+ ],
99113
)

bazel/pl_build_system.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def pl_common_linkopts():
9595
"-lunwind",
9696
],
9797
# The OSX system library transitively links common libraries (e.g., pthread).
98-
"@bazel_tools//tools/osx:darwin": [],
98+
"@bazel_tools//tools/osx:darwin_arm64": [],
99+
"@bazel_tools//tools/osx:darwin_x86_64": [],
99100
"//conditions:default": [
100101
"-pthread",
101102
"-lunwind",

bazel/repositories.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def _pl_cc_toolchain_deps():
247247
def _pl_deps():
248248
_bazel_repo("bazel_gazelle")
249249
_bazel_repo("io_bazel_rules_go", patches = ["//bazel/external:rules_go.patch"], patch_args = ["-p1"])
250+
_bazel_repo("rules_cc")
250251
_bazel_repo("rules_java")
251252
_bazel_repo("io_bazel_rules_scala")
252253
_bazel_repo("rules_scala")

bazel/repository_locations.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ REPOSITORY_LOCATIONS = dict(
2323
],
2424
),
2525
bazel_skylib = dict(
26-
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
26+
sha256 = "51b5105a760b353773f904d2bbc5e664d0987fbaf22265164de65d43e910d8ac",
2727
urls = [
28-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
29-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
28+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.1/bazel-skylib-1.8.1.tar.gz",
29+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.1/bazel-skylib-1.8.1.tar.gz",
3030
],
3131
),
3232
# Must be called boringssl to make sure the deps pick it up correctly.
@@ -415,6 +415,11 @@ REPOSITORY_LOCATIONS = dict(
415415
],
416416
manual_license_name = "oracle/openjdk",
417417
),
418+
rules_cc = dict(
419+
sha256 = "a2fdfde2ab9b2176bd6a33afca14458039023edb1dd2e73e6823810809df4027",
420+
strip_prefix = "rules_cc-0.2.14",
421+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.2.14/rules_cc-0.2.14.tar.gz"],
422+
),
418423
io_bazel_rules_closure = dict(
419424
sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9",
420425
strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149",

0 commit comments

Comments
 (0)