-
Notifications
You must be signed in to change notification settings - Fork 303
Add use_runfiles aspect_hint to include runfiles for specific cc_libr… #2479
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9e224bb
Add use_runfiles aspect_hint to include runfiles for specific cc_libr…
gkoreman df334c1
Change the resource aspect hint to be more general
gkoreman 7c80246
Add missing load for AppleResourceHintInfo
gkoreman d835f0c
Add tests for runfiles and resources style data included from a cc_li…
gkoreman b8ea428
Add bzl_library for resource_aspect_hint
gkoreman 3cd3c76
Add the bzl_library for resource_aspect_hint and run //doc:update
gkoreman efa38a5
Use correct paths for resources.
gkoreman 6188803
Merge branch 'master' into use_runfiles
gkoreman acce355
Test suppress_resources and improve test naming
gkoreman db24d5e
Fix buildifier sorting
gkoreman 4f186bb
Merge branch 'master' into use_runfiles
luispadron 1b6db64
Remove unneeded @unsorted-dict-items
gkoreman eaf5275
Update error formatting
gkoreman 5c7dd8a
Extract default_action check into variables
gkoreman 2476de4
Add comment to explain why dylibs are excluded
gkoreman dc3e59a
Add comment to explain possible values for AppleResourceHintInfo acti…
gkoreman 26c42c5
Fix buildifier warning
gkoreman d451086
Convert to use struct constants instead of strings.
gkoreman 8662a61
Convert if check to positive assertion
gkoreman 8e30c51
Alphabetize the struct definitions
gkoreman 6713608
Add simple example of runfiles layout
gkoreman 1905929
Merge branch 'master' into use_runfiles
gkoreman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Implementation of the `apple_resource_hint` rule.""" | ||
|
||
_resource_actions = ["RESOURCES", "RUNFILES", "SUPPRESS"] | ||
gkoreman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
AppleResourceHintInfo = provider( | ||
doc = """Provider that propagates desire to automatically bundle runfiles, resources, or suppress both.""", | ||
gkoreman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# @unsorted-dict-items | ||
gkoreman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fields = { | ||
"action": "Which resource action to run.", | ||
}, | ||
) | ||
|
||
def _apple_resource_hint_impl(ctx): | ||
if ctx.attr.action not in _resource_actions: | ||
fail(str(ctx.label) + " apple resource hint allowed to take values {" + | ||
", ".join(_resource_actions) + "} but was set to unallowed value " + | ||
gkoreman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx.attr.action) | ||
return AppleResourceHintInfo( | ||
action = ctx.attr.action, | ||
) | ||
|
||
apple_resource_hint = rule( | ||
attrs = { | ||
"action": attr.string( | ||
mandatory = True, | ||
doc = """ | ||
Hints the resource collector to take a specific action. | ||
Available actions are | ||
`RESOURCES` collect all labels referenced in the data attribute, process them based on | ||
file extension, flatten the folder heirarchy and include them in Contents/Resources | ||
`RUNFILES` collect all runfiles without processing and include them in Contents/Resources. | ||
`SUPPRESS` stop any collection of resources on this target. Transitive runfiles may still be | ||
collected based on ancestor resource rules. | ||
""", | ||
), | ||
}, | ||
doc = """\ | ||
Defines an aspect hint that generates an appropriate AppleResourceHintInfo based on the | ||
runfiles for this target. | ||
|
||
> [!NOTE] | ||
> Bazel 6 users must set the `--experimental_enable_aspect_hints` flag to utilize | ||
> this rule. In addition, downstream consumers of rules that utilize this rule | ||
> must also set the flag. The flag is enabled by default in Bazel 7. | ||
|
||
Some rules like `cc_library` may have data associated with them in the data attribute | ||
that is needed at runtime. If the library was linked in a `cc_binary` then those data | ||
files would be made available to the application as `runfiles`. To control this | ||
functionality with a `macos_application` you may use this aspect hint. | ||
|
||
|
||
#### Collect resources of a cc_library | ||
|
||
By default a cc_library will add its runfiles to the Contents/Resources folder of a | ||
`macos_application`. To alter this behavior and have it collect resources instead | ||
you can add this pre-built aspect hint. This will cause resources to be collected | ||
and processed like objc_library. | ||
|
||
```build | ||
# //my/project/BUILD | ||
cc_library( | ||
name = "somelib", | ||
data = ["mydata.txt"], | ||
aspect_hints = ["@build_bazel_rules_apple//apple:use_resources"], | ||
) | ||
``` | ||
|
||
#### Collect runfiles of a objc_library | ||
gkoreman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Similar to above, you can modify the default resource collection behavior of | ||
an objc_library by adding an aspect hint to `use_runfiles` instead of resources. | ||
|
||
```build | ||
# //my/project/BUILD | ||
objc_library( | ||
name = "somelib", | ||
data = ["mydata.txt"], | ||
aspect_hints = ["@build_bazel_rules_apple//apple:use_runfiles"], | ||
) | ||
``` | ||
|
||
#### Suppress resource collection | ||
|
||
In some situations you may wish to suppress resource or runfile collection of | ||
a target. You can add the `suppress_resources` aspect hint to accomplish this. | ||
Note that runfile collection is transitive, so if an ancestor of this target | ||
collects runfiles then this targets runfiles will be included regardless of | ||
any aspect hint applied. | ||
|
||
```build | ||
# //my/project/BUILD | ||
objc_library( | ||
name = "somelib", | ||
data = ["mydata.txt"], | ||
aspect_hints = ["@build_bazel_rules_apple//apple:suppress_resources"], | ||
) | ||
``` | ||
""", | ||
implementation = _apple_resource_hint_impl, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.