Skip to content

Conversation

reutermj
Copy link
Contributor

@reutermj reutermj commented Sep 9, 2025

Any target produced by a symbolic macro must start with the name of the macro. cc_toolchain produces two sets of targets prefixed with _ instead of the name. This change drops the _ prefix from the targets produced by cc_toolchain to enable its use in symbolic macros.

example error:

ERROR: /home/mark/.cache/bazel/_bazel_mark/5979f8eda1b07b2dab85fbe51f06c597/external/toolchains_cc++cxx_toolchains+toolchains_cc_default_toolchain/BUILD:3:18: in cc_toolchain_config rule @@toolchains_cc++cxx_toolchains+toolchains_cc_default_toolchain//:_toolchains_cc_default_toolchain_cc_toolchain_config: Target @@toolchains_cc++cxx_toolchains+toolchains_cc_default_toolchain//:_toolchains_cc_default_toolchain_cc_toolchain_config declared in symbolic macro 'toolchains_cc_default_toolchain' violates macro naming rules and cannot be built. Name must be the same as the macro's name, or the macro's name followed by '_' (recommended), '-', or '.', and a non-empty string.

fix verified with working toolchain: https://github.com/reutermj/toolchains_cc/tree/backup-gcc

Any target produced by a symbolic macro must start with the name of the macro.
cc_toolchain produces two sets of targets prefixed with `_` instead of the name.
This change drops the `_` prefix from the targets produced by cc_toolchain to enable its use in symbolic macros.
@reutermj reutermj changed the title Fix target naming to follow symbolic macro namming requirements Fix target naming to follow symbolic macro naming requirements Sep 9, 2025
@armandomontanez
Copy link
Collaborator

armandomontanez commented Sep 15, 2025

This target is intended to be private so we don't have other folks rely on the intermediate target, so it's named with a _{name} prefix which is part of the bzl style guide. Is there a flag to turn this check off until either the check or style guide are improved?

@reutermj
Copy link
Contributor Author

reutermj commented Sep 15, 2025

There's nothing blocking me on my end. I can (and currently do) just use a legacy macro in the meantime which doesn't have the naming check. Yeah the style guide and the symbolic macro requirements aren't in agreement:

Have their names prefixed by <name> or _<name>. For example, using name = '%s_bar' % (name).

https://bazel.build/rules/bzl-style#macros

The names of any targets or submacros created by a symbolic macro must either match the macro's name parameter or must be prefixed by name followed by _ (preferred), . or -.

https://bazel.build/extending/macros#naming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants