Is there a toolchain config alternative to --per_file_copt?

117 views
Skip to first unread message

Phil Schrader

unread,
Nov 30, 2022, 8:36:33 PM11/30/22
to bazel-discuss
In trying to enable thinLTO, I discovered that folks are liberally using --copt and --per_file_copt in the .bazelrc file. No good for various reasons (e.g. transitions), but it's the reason for posting here. Those options seem to apply to thinLTO actions.

For example, this is a presumably helpful line in our .bazelrc file:
build --per_file_copt=third_party/.*,external/.*@-Wpacked-bitfield-compat

This results in warnings like this:
INFO: From LTO Backend Compile bazel-out/k8-fastbuild-clang15/bin/foo.lto/external/libbar/_objs/libbar/baz.pic.o:
warning: unknown warning option '-Wpacked-bitfield-compat' [-Wunknown-warning-option]

Is there a way to emulate this in the toolchain config? I was hoping I could write something like this:
foo = feature(
    flag_sets = [
        flag_set(
            actions = ...,
            flag_groups = [
                flag_group(
                    flags = ["-Wpacked-bitfield-compat"],
                    expand_if_equal = variable_with_value(
                        name = "source_file.path.parts[0]",
                        name = "external",
                    ),
                ),
            ],
        ),
    ],
)

Basically accessing the source_file variable like a mix of a Starlark File and a Python Path object.

Are there other approaches to achieve the same thing?

Thanks,
Phil

Ted Pudlik

unread,
Oct 30, 2023, 6:06:32 PM10/30/23
to bazel-discuss
I was hoping for the same thing. I filed an FR: https://github.com/bazelbuild/rules_cc/issues/209
Reply all
Reply to author
Forward
0 new messages