-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Apply repo mapping to cc_shared_library
's exports_filter
#21622
Conversation
|
||
"""Implementation of cc_shared_library's macro wrapper""" | ||
|
||
def cc_shared_library(**kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being a macro would require migrating the attribute doc
s to a function comment.
@comius What do you think of allowing native.package_relative_label
in initializer
s instead, perhaps by providing a suitably trimmed down BazelStarlarkContext
to the thread running the initializer
? I understand why you don't want native.existing_rules
to be run in one, but label conversion will be a frequent ask with Bzlmod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializers already lift strings of regular labels. Maybe the solution is to make exports_filter
a label?
Should the lifting really be package relative? That's only the property of output labels. Otherwise labels are lifted call-site relative. Not much difference at the moment. But if you had a string label in an initializer, that would need to work relative to the initializer, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializers already lift strings of regular labels. Maybe the solution is to make
exports_filter
a label?
Could you elaborate on that? My understanding is that making exports_filter
a label_list
would result in dependency edges on all entries of the list, which would result in errors since the __pkg__
pseudo targets don't exist.
Should the lifting really be package relative? That's only the property of output labels. Otherwise labels are lifted call-site relative. Not much difference at the moment. But if you had a string label in an initializer, that would need to work relative to the initializer, right?
I'm aware of three different "lifting" mechanisms in macros:
- Strings passed to
attr.label
s are resolved relative to the BUILD file call site. - The
Label
constructor resolves relative to its own.bzl
call site. native.package_relative_label
resolves relative to the BUILD file call site.
I wouldn't expect initializers to behave differently here. But at the moment native.package_relative_label
isn't available in initializers, so I don't know how to turn user-supplied strings into labels without creating a dependency edge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t want to expose such functions to initializers, because they open space for crafting weird conversions and bugs with that.
A new type like attr.nodep_label_list would be the right thing to do. We have it natively.
But I’m also wondering, what’s going on in cc_shared_library, to make a usecase like this. In all the rules we touched, label comparison was a bad idea and we removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oquenchil can explain that better than me. Having an attribute control the transitive closure of a top-level transitive target does seem like a reasonable if rare use case to me.
Given that this is essentially a bug fix for a regression caused by --enable_bzlmod
, what do you think of using a macro for now until something like attr.nodep_label_list
becomes available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it's better to expose package_relative_label
to initializers and use them.
Without initializers also the docs on bazel.build would break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this in #21740. I also allowed the other non-target related functions as they seemed equally safe and useful to allow in initializers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now using an initializer, PTAL.
Original context is https://bazelbuild.slack.com/archives/CGA9QFQ8H/p1709829043052719 |
Switching to draft as I will update it after #21740 has been merged. |
This is required for `exports_filter` to match any external repositories with Bzlmod enabled. `native.package_relative_label` is used to convert the user-specified filter strings, which are always valid labels, to canonical label literals that are then passed to the actual `cc_shared_library` rule.
bad9800
to
4be413d
Compare
@bazel-io fork 7.2.0 |
Work towards bazelbuild#21622 RELNOTES: `native.package_relative_label` can now be used in rule initializers. Closes bazelbuild#21740. PiperOrigin-RevId: 631546734 Change-Id: Id6eb237f0f79195b678bb954deaef071e1c45ab1
This is required for `exports_filter` to match any external repositories with Bzlmod enabled. `native.package_relative_label` is used to convert the user-specified filter strings, which are always valid labels, to canonical label literals that are then passed to the actual `cc_shared_library` rule. Fixes #21872 Closes #21622. PiperOrigin-RevId: 632624776 Change-Id: I2f80563d8c434b2726f4facb0551b316b2cd2e1c
…22328) This is required for `exports_filter` to match any external repositories with Bzlmod enabled. `native.package_relative_label` is used to convert the user-specified filter strings, which are always valid labels, to canonical label literals that are then passed to the actual `cc_shared_library` rule. Fixes #21872 Closes #21622. PiperOrigin-RevId: 632624776 Change-Id: I2f80563d8c434b2726f4facb0551b316b2cd2e1c Co-authored-by: Fabian Meumertzheim <[email protected]>
Work towards bazelbuild#21622 RELNOTES: `native.package_relative_label` can now be used in rule initializers. Closes bazelbuild#21740. PiperOrigin-RevId: 631546734 Change-Id: Id6eb237f0f79195b678bb954deaef071e1c45ab1
This is required for `exports_filter` to match any external repositories with Bzlmod enabled. `native.package_relative_label` is used to convert the user-specified filter strings, which are always valid labels, to canonical label literals that are then passed to the actual `cc_shared_library` rule. Fixes bazelbuild#21872 Closes bazelbuild#21622. PiperOrigin-RevId: 632624776 Change-Id: I2f80563d8c434b2726f4facb0551b316b2cd2e1c
This is required for
exports_filter
to match any external repositories with Bzlmod enabled.native.package_relative_label
is used to convert the user-specified filter strings, which are always valid labels, to canonical label literals that are then passed to the actualcc_shared_library
rule.Fixes #21872