rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

Support `per_file_copt`

Open mering opened this issue 1 year ago • 6 comments

Options passed as --per_file_copt are currently not honored by rules_foreign_cc.

This is blocking us from enabling -Werror for our own code but ignoring warnings on external code where we have no control over. We want to do this with the following .bazelrc:

build --per_file_copt=external/.*@-Wno-everything --host_per_file_copt=external/.*@-Wno-everything
build --copt=-Werror --host_copt=-Werror

See https://github.com/bazelbuild/bazel/issues/24528 for further details.

mering avatar Nov 29 '24 10:11 mering

I'm not sure how you'd implement this as you'd need support from the configure script or the cmake script to apply flags to specific files which I don't think there is a general solution for. What we support though is features and so you could add a feature to your toolchain that sets the desired flags and then set the features for your rules_foreign_cc targets?

jsharpe avatar Nov 29 '24 10:11 jsharpe

@jsharpe thanks for your quick reply.

I do not have control over all rules_foreign_cc targets as some come in via transitive dependencies. I also get some errors for internal tools like make and pkgconfig.

Could there be a way to explicitly set additional copt for all rules_foreign_cc targets?

mering avatar Nov 29 '24 11:11 mering

Another approach could be to match the regex (here external/.*) against the BUILD file or the cmake() rule itself and if matching then appending the per_file_copt to the copts for the whole the target.

mering avatar Nov 29 '24 12:11 mering

Another approach could be to match the regex (here external/.*) against the BUILD file or the cmake() rule itself and if matching then appending the per_file_copt to the copts for the whole the target.

I don't think starlark has visibility of the per_file_copt except indirectly via the cc_common API?

jsharpe avatar Nov 29 '24 12:11 jsharpe

I don't think starlark has visibility of the per_file_copt except indirectly via the cc_common API?

@meteorcloudy @fmeum could you answer this?

mering avatar Nov 29 '24 12:11 mering

bump on this, any new ideas on how to accomplish this other than patching every single third-party CMakeLists.txt?

lalten avatar Apr 07 '25 10:04 lalten