bazel: incompatible_disable_nocopts: Disallow 'nocopts' attribute from cc_* rules

Flag: --incompatible_disable_nocopts Available since: 0.28 Will be flipped: 1.0

The nocopts attribute in cc_* rules is used to specify a pattern for filtering out flags from C++ compilation command line. We are deprecating it because:

  • it prevents migration of C++ rules to Starlark: we don’t have regex in Starlark currently
  • we don’t need to do it - we can disable features to have the same effect

Migration

If you use the nocopts attributes to filter out a flag please comment on this issue, with the offending flag/pattern that you’re filtering out.

As we have no way of knowing which flags users filter out, we will rely on them reaching out to us in case the flipping of the --incompatible_disable_nocopts flag breaks their project. We will keep on support for filtering out the flags through --noincompatible_disable_nocopts for 1-2 extra Bazel releases, until we are able to provide the support for disabling the reported flags through features.

If a user is filtering out a flag provided by bazel’s own C++ toolchain configuration, we will wrap the flag into a feature, so the user can disable the feature instead of filter out the flag. E.g a

cc_library(
    name = "lib",
    srcs = ["lib.cc", "lib.h"],
    nocopts = "flagA",
)

would be migrated to

cc_library(
    name = "lib",
    srcs = ["lib.cc", "lib.h"],
    features = ["-flag_a_feature"],
)

with flag_a_feature being defined in bazel’s own C++ toolchain configuration.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Do you use your own toolchain configuration? If so, you’ll need to create a feature that will pass the -Wno-declaration-after-statement to the command line, and use features = ["-declaration_after_statement"] in the targets that you’d like to not apply the flag to.

That looks like it worked. That’s a much better solution than nocopts. Thanks!