Skip to content

Commit e2a23ab

Browse files
committed
support extra flags
If you just want to add a single flag (that is per platform) and leave the rest of the default flags, you have to copy out all the existing flags and add it to what you have. Instead support just adding an extra flag that is appended to the default flags.
1 parent 69d3996 commit e2a23ab

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

toolchain/cc_toolchain_config.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,29 @@ def cc_toolchain_config(
364364
if compiler_configuration["unfiltered_compile_flags"] != None:
365365
unfiltered_compile_flags = _fmt_flags(compiler_configuration["unfiltered_compile_flags"], toolchain_path_prefix)
366366

367+
if compiler_configuration["extra_compile_flags"] != None:
368+
compile_flags.extend(_fmt_flags(compiler_configuration["extra_compile_flags"], toolchain_path_prefix))
369+
if compiler_configuration["extra_cxx_flags"] != None:
370+
cxx_flags.extend(_fmt_flags(compiler_configuration["extra_cxx_flags"], toolchain_path_prefix))
371+
if compiler_configuration["extra_link_flags"] != None:
372+
link_flags.extend(_fmt_flags(compiler_configuration["extra_link_flags"], toolchain_path_prefix))
373+
if compiler_configuration["extra_archive_flags"] != None:
374+
archive_flags.extend(_fmt_flags(compiler_configuration["extra_archive_flags"], toolchain_path_prefix))
375+
if compiler_configuration["extra_link_libs"] != None:
376+
link_libs.extend(_fmt_flags(compiler_configuration["extra_link_libs"], toolchain_path_prefix))
377+
if compiler_configuration["extra_opt_compile_flags"] != None:
378+
opt_compile_flags.extend(_fmt_flags(compiler_configuration["extra_opt_compile_flags"], toolchain_path_prefix))
379+
if compiler_configuration["extra_opt_link_flags"] != None:
380+
opt_link_flags.extend(_fmt_flags(compiler_configuration["extra_opt_link_flags"], toolchain_path_prefix))
381+
if compiler_configuration["extra_dbg_compile_flags"] != None:
382+
dbg_compile_flags.extend(_fmt_flags(compiler_configuration["extra_dbg_compile_flags"], toolchain_path_prefix))
383+
if compiler_configuration["extra_coverage_compile_flags"] != None:
384+
coverage_compile_flags.extend(_fmt_flags(compiler_configuration["extra_coverage_compile_flags"], toolchain_path_prefix))
385+
if compiler_configuration["extra_coverage_link_flags"] != None:
386+
coverage_link_flags.extend(_fmt_flags(compiler_configuration["extra_coverage_link_flags"], toolchain_path_prefix))
387+
if compiler_configuration["extra_unfiltered_compile_flags"] != None:
388+
unfiltered_compile_flags.extend(_fmt_flags(compiler_configuration["extra_unfiltered_compile_flags"], toolchain_path_prefix))
389+
367390
# Source: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/unix_cc_toolchain_config.bzl
368391
unix_cc_toolchain_config(
369392
name = name,

toolchain/internal/configure.bzl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ def llvm_config_impl(rctx):
174174
extra_compiler_files = rctx.attr.extra_compiler_files,
175175
extra_exec_compatible_with = rctx.attr.extra_exec_compatible_with,
176176
extra_target_compatible_with = rctx.attr.extra_target_compatible_with,
177+
extra_compile_flags_dict = rctx.attr.extra_compile_flags,
178+
extra_cxx_flags_dict = rctx.attr.extra_cxx_flags,
179+
extra_link_flags_dict = rctx.attr.extra_link_flags,
180+
extra_archive_flags_dict = rctx.attr.extra_archive_flags,
181+
extra_link_libs_dict = rctx.attr.extra_link_libs,
182+
extra_opt_compile_flags_dict = rctx.attr.extra_opt_compile_flags,
183+
extra_opt_link_flags_dict = rctx.attr.extra_opt_link_flags,
184+
extra_dbg_compile_flags_dict = rctx.attr.extra_dbg_compile_flags,
185+
extra_coverage_compile_flags_dict = rctx.attr.extra_coverage_compile_flags,
186+
extra_coverage_link_flags_dict = rctx.attr.extra_coverage_link_flags,
187+
extra_unfiltered_compile_flags_dict = rctx.attr.extra_unfiltered_compile_flags,
177188
)
178189
exec_dl_ext = "dylib" if os == "darwin" else "so"
179190
cc_toolchains_str, toolchain_labels_str = _cc_toolchains_str(
@@ -389,6 +400,17 @@ cc_toolchain_config(
389400
"coverage_compile_flags": {coverage_compile_flags},
390401
"coverage_link_flags": {coverage_link_flags},
391402
"unfiltered_compile_flags": {unfiltered_compile_flags},
403+
"extra_compile_flags": {extra_compile_flags},
404+
"extra_cxx_flags": {extra_cxx_flags},
405+
"extra_link_flags": {extra_link_flags},
406+
"extra_archive_flags": {extra_archive_flags},
407+
"extra_link_libs": {extra_link_libs},
408+
"extra_opt_compile_flags": {extra_opt_compile_flags},
409+
"extra_opt_link_flags": {extra_opt_link_flags},
410+
"extra_dbg_compile_flags": {extra_dbg_compile_flags},
411+
"extra_coverage_compile_flags": {extra_coverage_compile_flags},
412+
"extra_coverage_link_flags": {extra_coverage_link_flags},
413+
"extra_unfiltered_compile_flags": {extra_unfiltered_compile_flags},
392414
}},
393415
cxx_builtin_include_directories = {cxx_builtin_include_directories},
394416
major_llvm_version = {major_llvm_version},
@@ -562,6 +584,17 @@ cc_toolchain(
562584
coverage_compile_flags = _list_to_string(_dict_value(toolchain_info.coverage_compile_flags_dict, target_pair)),
563585
coverage_link_flags = _list_to_string(_dict_value(toolchain_info.coverage_link_flags_dict, target_pair)),
564586
unfiltered_compile_flags = _list_to_string(_dict_value(toolchain_info.unfiltered_compile_flags_dict, target_pair)),
587+
extra_compile_flags = _list_to_string(_dict_value(toolchain_info.extra_compile_flags_dict, target_pair)),
588+
extra_cxx_flags = _list_to_string(_dict_value(toolchain_info.extra_cxx_flags_dict, target_pair)),
589+
extra_link_flags = _list_to_string(_dict_value(toolchain_info.extra_link_flags_dict, target_pair)),
590+
extra_archive_flags = _list_to_string(_dict_value(toolchain_info.extra_archive_flags_dict, target_pair)),
591+
extra_link_libs = _list_to_string(_dict_value(toolchain_info.extra_link_libs_dict, target_pair)),
592+
extra_opt_compile_flags = _list_to_string(_dict_value(toolchain_info.extra_opt_compile_flags_dict, target_pair)),
593+
extra_opt_link_flags = _list_to_string(_dict_value(toolchain_info.extra_opt_link_flags_dict, target_pair)),
594+
extra_dbg_compile_flags = _list_to_string(_dict_value(toolchain_info.extra_dbg_compile_flags_dict, target_pair)),
595+
extra_coverage_compile_flags = _list_to_string(_dict_value(toolchain_info.extra_coverage_compile_flags_dict, target_pair)),
596+
extra_coverage_link_flags = _list_to_string(_dict_value(toolchain_info.extra_coverage_link_flags_dict, target_pair)),
597+
extra_unfiltered_compile_flags = _list_to_string(_dict_value(toolchain_info.extra_unfiltered_compile_flags_dict, target_pair)),
565598
extra_files_str = extra_files_str,
566599
cxx_builtin_include_directories = _list_to_string(filtered_cxx_builtin_include_directories),
567600
extra_compiler_files = ("\"%s\"," % str(toolchain_info.extra_compiler_files)) if toolchain_info.extra_compiler_files else "",

toolchain/internal/repo.bzl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,95 @@ _compiler_configuration_attrs = {
249249
"target OS and arch pair you want to override " +
250250
"({}); empty key overrides all.".format(_target_pairs)),
251251
),
252+
# Same as the above flags, but instead of overriding the defaults, it just adds extras
253+
"extra_compile_flags": attr.string_list_dict(
254+
mandatory = False,
255+
doc = ("Extra compile_flags, added after default values. " +
256+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
257+
"to the root LLVM distribution directory. Provide one list for each " +
258+
"target OS and arch pair you want to override " +
259+
"({}); empty key overrides all.".format(_target_pairs)),
260+
),
261+
"extra_cxx_flags": attr.string_list_dict(
262+
mandatory = False,
263+
doc = ("Extra cxx_flags, added after default values. " +
264+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
265+
"to the root LLVM distribution directory. Provide one list for each " +
266+
"target OS and arch pair you want to override " +
267+
"({}); empty key overrides all.".format(_target_pairs)),
268+
),
269+
"extra_link_flags": attr.string_list_dict(
270+
mandatory = False,
271+
doc = ("Extra link_flags, added after the default values. " +
272+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
273+
"to the root LLVM distribution directory. Provide one list for each " +
274+
"target OS and arch pair you want to override " +
275+
"({}); empty key overrides all.".format(_target_pairs)),
276+
),
277+
"extra_archive_flags": attr.string_list_dict(
278+
mandatory = False,
279+
doc = ("Extra archive_flags, added after the default values. " +
280+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
281+
"to the root LLVM distribution directory. Provide one list for each " +
282+
"target OS and arch pair you want to override " +
283+
"({}); empty key overrides all.".format(_target_pairs)),
284+
),
285+
"extra_link_libs": attr.string_list_dict(
286+
mandatory = False,
287+
doc = ("Extra for link_libs, added after the default values. " +
288+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
289+
"to the root LLVM distribution directory. Provide one list for each " +
290+
"target OS and arch pair you want to override " +
291+
"({}); empty key overrides all.".format(_target_pairs)),
292+
),
293+
"extra_opt_compile_flags": attr.string_list_dict(
294+
mandatory = False,
295+
doc = ("Extra opt_compile_flags, added after the default values. " +
296+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
297+
"to the root LLVM distribution directory. Provide one list for each " +
298+
"target OS and arch pair you want to override " +
299+
"({}); empty key overrides all.".format(_target_pairs)),
300+
),
301+
"extra_opt_link_flags": attr.string_list_dict(
302+
mandatory = False,
303+
doc = ("Extra opt_link_flags, added after the default values. " +
304+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
305+
"to the root LLVM distribution directory. Provide one list for each " +
306+
"target OS and arch pair you want to override " +
307+
"({}); empty key overrides all.".format(_target_pairs)),
308+
),
309+
"extra_dbg_compile_flags": attr.string_list_dict(
310+
mandatory = False,
311+
doc = ("Extra dbg_compile_flags, added after the default values. " +
312+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
313+
"to the root LLVM distribution directory. Provide one list for each " +
314+
"target OS and arch pair you want to override " +
315+
"({}); empty key overrides all.".format(_target_pairs)),
316+
),
317+
"extra_coverage_compile_flags": attr.string_list_dict(
318+
mandatory = False,
319+
doc = ("Extra coverage_compile_flags, added after the default values. " +
320+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
321+
"to the root LLVM distribution directory. Provide one list for each " +
322+
"target OS and arch pair you want to override " +
323+
"({}); empty key overrides all.".format(_target_pairs)),
324+
),
325+
"extra_coverage_link_flags": attr.string_list_dict(
326+
mandatory = False,
327+
doc = ("Extra coverage_link_flags, added after the default values. " +
328+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
329+
"to the root LLVM distribution directory. Provide one list for each " +
330+
"target OS and arch pair you want to override " +
331+
"({}); empty key overrides all.".format(_target_pairs)),
332+
),
333+
"extra_unfiltered_compile_flags": attr.string_list_dict(
334+
mandatory = False,
335+
doc = ("Extra unfiltered_compile_flags, added after the default values. " +
336+
"`{toolchain_path_prefix}` in the flags will be substituted by the path " +
337+
"to the root LLVM distribution directory. Provide one list for each " +
338+
"target OS and arch pair you want to override " +
339+
"({}); empty key overrides all.".format(_target_pairs)),
340+
),
252341
"target_settings": attr.string_list_dict(
253342
mandatory = False,
254343
doc = ("Override the toolchain's `target_settings` attribute."),

0 commit comments

Comments
 (0)