Skip to content

Commit 0bdeae2

Browse files
meringtrybka
andauthored
Add fastbuild_compile_flags (#536)
This includes updating and using bazelbuild/rules_cc@ff06b70 and bazelbuild/rules_cc@eed7e63 which is also [used by `bazel_tools`](https://github.com/bazelbuild/bazel/blob/4f46e8265313078b8afbf9d6b832711b2d75cfc2/tools/cpp/unix_cc_toolchain_config.bzl#L17). Usage example: ```starlark # MODULE.bazel llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") llvm.toolchain( compile_flags = { "fastbuild_compile_flags": [ "-O1", ], }, llvm_version = "20.1.2", ) ``` --------- Co-authored-by: Tom Rybka <[email protected]>
1 parent 7cfc09d commit 0bdeae2

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

.github/workflows/release_notes_template.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")
4343

4444
bazel_toolchain_dependencies()
4545

46+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
47+
48+
bazel_features_deps()
49+
50+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
51+
52+
compatibility_proxy_repo()
53+
4654
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
4755

4856
llvm_toolchain(

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module(
2020
)
2121

2222
bazel_dep(name = "bazel_skylib", version = "1.5.0")
23-
bazel_dep(name = "rules_cc", version = "0.0.17")
23+
bazel_dep(name = "rules_cc", version = "0.2.2")
2424
bazel_dep(name = "platforms", version = "0.0.8")
2525

2626
# TODO: Remove when protobuf is released with a version of rules_python that supports 8.x

tests/WORKSPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,12 @@ rules_foreign_cc_dependencies()
325325

326326
load("@bazel_features//:deps.bzl", "bazel_features_deps")
327327

328-
# Dep of `rules_foreign_cc`.
329328
bazel_features_deps()
330329

330+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
331+
332+
compatibility_proxy_repo()
333+
331334
_ALL_CONTENT = """\
332335
filegroup(
333336
name = "all_srcs",

toolchain/cc_toolchain_config.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# buildifier: disable=bzl-visibility
1516
load(
16-
"@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl",
17+
"@rules_cc//cc/private/toolchain:unix_cc_toolchain_config.bzl",
1718
unix_cc_toolchain_config = "cc_toolchain_config",
1819
)
1920
load(
@@ -178,6 +179,8 @@ def cc_toolchain_config(
178179

179180
dbg_compile_flags = ["-g", "-fstandalone-debug"]
180181

182+
fastbuild_compile_flags = []
183+
181184
opt_compile_flags = [
182185
"-g0",
183186
"-O2",
@@ -399,6 +402,8 @@ def cc_toolchain_config(
399402
opt_link_flags = _fmt_flags(compiler_configuration["opt_link_flags"], toolchain_path_prefix)
400403
if compiler_configuration["dbg_compile_flags"] != None:
401404
dbg_compile_flags = _fmt_flags(compiler_configuration["dbg_compile_flags"], toolchain_path_prefix)
405+
if compiler_configuration["fastbuild_compile_flags"] != None:
406+
fastbuild_compile_flags = _fmt_flags(compiler_configuration["fastbuild_compile_flags"], toolchain_path_prefix)
402407
if compiler_configuration["coverage_compile_flags"] != None:
403408
coverage_compile_flags = _fmt_flags(compiler_configuration["coverage_compile_flags"], toolchain_path_prefix)
404409
if compiler_configuration["coverage_link_flags"] != None:
@@ -420,6 +425,7 @@ def cc_toolchain_config(
420425
cxx_builtin_include_directories = cxx_builtin_include_directories,
421426
tool_paths = tool_paths,
422427
compile_flags = compile_flags,
428+
fastbuild_compile_flags = fastbuild_compile_flags,
423429
dbg_compile_flags = dbg_compile_flags,
424430
opt_compile_flags = opt_compile_flags,
425431
conly_flags = conly_flags,

toolchain/deps.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def bazel_toolchain_dependencies():
1919
if not native.existing_rule("rules_cc"):
2020
http_archive(
2121
name = "rules_cc",
22-
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"],
23-
sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1",
24-
strip_prefix = "rules_cc-0.0.17",
22+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.2.2/rules_cc-0.2.2.tar.gz"],
23+
sha256 = "e50f24506011841e2ac83d9733a0c7e058eb3a10a6e3e10baa9c7942ff5f4767",
24+
strip_prefix = "rules_cc-0.2.2",
2525
)
2626

2727
# Load bazel_skylib if the user has not defined them.
@@ -36,3 +36,12 @@ def bazel_toolchain_dependencies():
3636
)
3737

3838
# Skip bazel_skylib_workspace because we are not using lib/unittest.bzl
39+
40+
# Load bazel_features if the user has not defined them.
41+
if not native.existing_rule("bazel_features"):
42+
http_archive(
43+
name = "bazel_features",
44+
sha256 = "ba1282c1aa1d1fffdcf994ab32131d7c7551a9bc960fbf05f42d55a1b930cbfb",
45+
strip_prefix = "bazel_features-1.15.0",
46+
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.15.0/bazel_features-v1.15.0.tar.gz",
47+
)

toolchain/internal/configure.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def llvm_config_impl(rctx):
165165
link_flags_dict = rctx.attr.link_flags,
166166
archive_flags_dict = rctx.attr.archive_flags,
167167
link_libs_dict = rctx.attr.link_libs,
168+
fastbuild_compile_flags_dict = rctx.attr.fastbuild_compile_flags,
168169
opt_compile_flags_dict = rctx.attr.opt_compile_flags,
169170
opt_link_flags_dict = rctx.attr.opt_link_flags,
170171
dbg_compile_flags_dict = rctx.attr.dbg_compile_flags,
@@ -396,6 +397,7 @@ cc_toolchain_config(
396397
"link_flags": {link_flags},
397398
"archive_flags": {archive_flags},
398399
"link_libs": {link_libs},
400+
"fastbuild_compile_flags": {fastbuild_compile_flags},
399401
"opt_compile_flags": {opt_compile_flags},
400402
"opt_link_flags": {opt_link_flags},
401403
"dbg_compile_flags": {dbg_compile_flags},
@@ -570,6 +572,7 @@ cc_toolchain(
570572
link_flags = _list_to_string(_dict_value(toolchain_info.link_flags_dict, target_pair)),
571573
archive_flags = _list_to_string(_dict_value(toolchain_info.archive_flags_dict, target_pair)),
572574
link_libs = _list_to_string(_dict_value(toolchain_info.link_libs_dict, target_pair)),
575+
fastbuild_compile_flags = _list_to_string(_dict_value(toolchain_info.fastbuild_compile_flags_dict, target_pair)),
573576
opt_compile_flags = _list_to_string(_dict_value(toolchain_info.opt_compile_flags_dict, target_pair)),
574577
opt_link_flags = _list_to_string(_dict_value(toolchain_info.opt_link_flags_dict, target_pair)),
575578
dbg_compile_flags = _list_to_string(_dict_value(toolchain_info.dbg_compile_flags_dict, target_pair)),

toolchain/internal/repo.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ _compiler_configuration_attrs = {
209209
"target OS and arch pair you want to override " +
210210
"({}); empty key overrides all.".format(_target_pairs)),
211211
),
212+
"fastbuild_compile_flags": attr.string_list_dict(
213+
mandatory = False,
214+
doc = ("Override for fastbuild_compile_flags, replacing the default values. " +
215+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
216+
"to the root LLVM distribution directory. Provide one list for each " +
217+
"target OS and arch pair you want to override " +
218+
"({}); empty key overrides all.".format(_target_pairs)),
219+
),
212220
"opt_compile_flags": attr.string_list_dict(
213221
mandatory = False,
214222
doc = ("Override for opt_compile_flags, replacing the default values. " +

0 commit comments

Comments
 (0)