Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rule-based toolchains: Can't enable sentinel features #233

Closed
armandomontanez opened this issue Aug 14, 2024 · 2 comments
Closed

rule-based toolchains: Can't enable sentinel features #233

armandomontanez opened this issue Aug 14, 2024 · 2 comments

Comments

@armandomontanez
Copy link
Collaborator

In Pigweed, we have a feature like this:

# This is a sentinel feature defined by rules_rust. It is by definition
# unsupported: rules_rust will disable this feature when linking Rust code.
cc_feature(
    name = "rules_rust_unsupported_feature",
    feature_name = "rules_rust_unsupported_feature",
)

This is a feature that should default to enabled when added to the toolchain, and then dynamically be disabled by Rust rules to signal toolchain flags that should be flipped for Rust interop. When the enabled attribute was removed from cc_feature, the only way to enable a feature by default became via implies (which is what is used by cc_toolchain's enabled_features attribute), which produces the following error:

$ bazel build --override_module=rules_cc=~/development/projects/bazel/rules_cc/ //pw_status/...
ERROR: /Users/amontanez/development/projects/pigweed/pigweed/pw_toolchain/rust/BUILD.bazel:22:34: in rust_toolchain rule //pw_toolchain/rust:host_rust_toolchain_macos_x86_64_stable_rust_toolchain:
Traceback (most recent call last):
	File "/private/var/tmp/_bazel_amontanez/e724b21efc8bc19866072fbc72ee5907/external/rules_rust~/rust/toolchain.bzl", line 640, column 72, in _rust_toolchain_impl
		libstd_and_allocator_ccinfo = _make_libstd_and_allocator_ccinfo(ctx, rust_std, ctx.attr.allocator_library, "std"),
	File "/private/var/tmp/_bazel_amontanez/e724b21efc8bc19866072fbc72ee5907/external/rules_rust~/rust/toolchain.bzl", line 155, column 60, in _make_libstd_and_allocator_ccinfo
		cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
	File "/private/var/tmp/_bazel_amontanez/e724b21efc8bc19866072fbc72ee5907/external/rules_rust~/rust/private/utils.bzl", line 55, column 57, in find_cc_toolchain
		feature_configuration = cc_common.configure_features(
	File "/virtual_builtins_bzl/common/cc/cc_common.bzl", line 179, column 49, in _configure_features
Error in configure_features: The C++ toolchain '//pw_toolchain/host_clang:host_toolchain' unconditionally implies feature 'rules_rust_unsupported_feature', which is unsupported by this rule. This is most likely a misconfiguration in the C++ toolchain.
@armandomontanez
Copy link
Collaborator Author

Either:

  • We need to revert 84fceed to support this use case
  • We need to change how things are expressed to allow some part of toolchain rules to express the intended default state of a feature.

I'm not sure I fully understand cc_toolchain.enabled_features. Since it unconditionally enables a feature with no escape hatch, wouldn't the right pattern be to express the flags in that feature directly in cc_toolchain.args?

@matts1
Copy link
Contributor

matts1 commented Aug 15, 2024

Adding something to cc_toolchain.enabled_features was intended to be functionally equivalent to cc_feature(..., enabled = True).

I used implies instead of changing cc_feature.enabled, because that was easier to implement, and I thought it was equivalent because I didn't consider this particular use case.

FWIW, this should be a relatively simple fix - it should just be a change to legacy_converter.bzl.

copybara-service bot pushed a commit that referenced this issue Jan 7, 2025
Imported changes from Github:

  - e278ee35e5ab56757bcd5ca3f10cab4822da1f1e Prepare release 0.7.2 (#258) by Alexandre Rostovtsev <arostovtsev@google.com>
  - bee95475e35903ac166766bc3df146d2acf4cbdb Remove apple_basic_test - we should not be accessing appl... by Alexandre Rostovtsev <arostovtsev@google.com>
  - aefab4cf8d6f46f1de97ae9e57fed9ba0648c3f1 fix: add missing proto_library load to support Bazel 8 (#... by Richard Levasseur <richardlev@gmail.com>
  - 91e429d9e2e959893c1ce2f81c35806b3a2daf8c Replace AppleDynamicFramework in test/testdata/apple_basi... by Philip Zembrod <pzembrod@gmail.com>
  - 46fd77a446f00faddedd0467ce993b462fba3c8a Delete usages/tests of the builtin bazel java symbols (#2... by hvadehra <hvadehra@gmail.com>
  - 2ac0981b7c35ff46cf66cc92467c37411c7bfacc Update proto and prepare release 0.7.1 (#239) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 03eb7ce460e3aa54fee1f4fac8fa6bfc3d7294f2 Fix CI since --enable_workspace is now disabled by defaul... by Alexandre Rostovtsev <arostovtsev@google.com>
  - 2100c63ca234836bd600800587076860a6973918 Merge user-defined tags with default tags in stardoc macr... by yashathwani <145871056+yashathwani@users.noreply.github.com>
  - db47c15e8d342c5e5b95d81554d7f901ba062c2e Revert most of #237 and #238 (#243) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 0ac26cd45b01011ffc172bd2054f07e9df1efbf2 Skip Bazel 7.2 tests in downstream pipeline (#244) by Alexandre Rostovtsev <arostovtsev@google.com>
  - da374a508b5a5f82e1e00f94889f04f9f86ca1fe Fix internal linter warnings (#235) by Alexandre Rostovtsev <arostovtsev@google.com>
  - c026daeee09fb072a02be87dfc87ea60d157e770 Improve incompatible flag testing (#238) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 7f0601624ceb55c84690ba9fc86a097a4c7cf6b8 Make Stardoc work with --incompatible_enable_proto_toolch... by lberki <lberki@users.noreply.github.com>
  - 00cc953512de26265c2c9b86947b5b13f338d707 Prepare release 0.7.0 (#233) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 1be7db63c28825a147670fe68d223633e37c8141 Do not emit rules_pkg dep in distro tarball's MODULE.baze... by Alexandre Rostovtsev <arostovtsev@google.com>
  - 92a4819c07f0985aba3746a5d89b81b6a4adf194 Respect --stamp and --nostamp flags for stamping (#234) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 018dee5bd296d81fa3f1eff3a08512d190ff7181 Include `load` in summaries (#216) by Fabian Meumertzheim <fabian@meumertzhe.im>
  - aba1a01295094e9df40fc94e355f54e7e98dcd33 Update test regeneration script to support multiple Bazel... by Alexandre Rostovtsev <arostovtsev@google.com>
  - f39ed53f56f2de895b2f1891fa166b2b3b0e3fe7 Render *args / * / **kwargs properly in function summary ... by Alexandre Rostovtsev <arostovtsev@google.com>
  - f40819fd48193987f8cd22d724fbbab2a7aaf322 Refactor param rendering in summary line (#230) by Alexandre Rostovtsev <arostovtsev@google.com>
  - 4644386b36253da4436bb961ed1f5fbcc8c15101 proto_format_test requires Bazel 7.1, and may break with ... by Alexandre Rostovtsev <arostovtsev@google.com>
  - 666b7ba7124b9af9c531c6c5f2013f69b27ea144 Render documentation for provider `init` callbacks (#224) by Alexandre Rostovtsev <arostovtsev@google.com>

... and update copybara configs and tests.

BEGIN_PUBLIC
Regenerate Starlark docs using Stardoc 0.7.2.
END_PUBLIC

PiperOrigin-RevId: 713040596
Change-Id: Id84f0010b5c873041c30880d7b47ac6e5eaa5c74
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

No branches or pull requests

2 participants