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

Add use_runfiles aspect_hint to include runfiles for specific cc_libr… #2479

Merged
merged 22 commits into from
Aug 7, 2024

Conversation

gkoreman
Copy link
Contributor

@gkoreman gkoreman commented Jun 26, 2024

Fixes #2477

Include all data from cc_libraries as runfiles or resources, depending on aspect_hints.
Provide aspect_hints for resource collection for all resource targets (eg, swift_library, cc_library, etc)

By default all data is now included from cc_libraries as runfiles and follows the expected runfiles folder structure, with files retaining their nested folders and being placed in /external/pkg_name/some/file.txt when included from a http_archive or local_repository.

The default behavior for other resource collecting targets like swift_library has not changed, and will continue to collect and process data as resources.

To allow modification of this default behavior, users may add aspect_hints to the target cc_library/swift_library/etc. There are three supported aspect_hints:
@build_bazel_rules_apple//apple:use_runfiles
@build_bazel_rules_apple//apple:use_resources
@build_bazel_rules_apple//apple:suppress_resources

Example

Here is an example of modifying the default behavior to bundle data.txt as a resource instead of a runfile.

cc_library(
    name = "libapp",
    srcs = ["main.cpp",],
    data = [":data.txt"],
    aspect_hints = ["@build_bazel_rules_apple//apple:use_runfiles"],
)

macos_application(
    name = "app_macos",
    deps = [":libapp"],
)

data.txt is bundled in Contents/Resources/data.txt

Note

Hints apply only to the target and do not affect transitive deps, however if a target includes runfiles then all runfiles are bundled (including transitive runfiles) regardless of the hints applied to transitive targets.

@brentleyjones
Copy link
Collaborator

brentleyjones commented Jun 26, 2024

I would like to flip the default, such that runfiles are collected by default for cc_library (but only it and the rules that currently don’t collect resources), and you need to use the aspect hint to make new rules collect resources instead. This will make it so the least number of people targets to use aspect hints. We will then need another aspect hint that tells the currently support resource collection rules to use runfiles instead. And we can have it be a build error when both are provided.

Three aspect hints are pre-defined and can be used on any target:
@build_bazel_rules_apple//apple:use_resources
@build_bazel_rules_apple//apple:use_runfiles
@build_bazel_rules_apple//apple:suppress_resources
Runfiles may be placed in the external/repo_name_x/ folder if they are pulled in from http_archive or local_repository. Runfiles from the main repo will be in a folder structure matching the main repo.
@gkoreman gkoreman marked this pull request as ready for review July 5, 2024 06:04
Copy link
Contributor

@luispadron luispadron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Left some comments I think we should address.

You'll also need to re-run buildifier as we updated the version and it adds more lints/formatting fixes

apple/internal/aspects/resource_aspect.bzl Outdated Show resolved Hide resolved
apple/internal/aspects/resource_aspect.bzl Show resolved Hide resolved
apple/internal/aspects/resource_aspect_hint.bzl Outdated Show resolved Hide resolved
apple/internal/aspects/resource_aspect_hint.bzl Outdated Show resolved Hide resolved
apple/internal/aspects/resource_aspect_hint.bzl Outdated Show resolved Hide resolved
@gkoreman gkoreman requested a review from luispadron July 25, 2024 18:36
@luispadron
Copy link
Contributor

@brentleyjones Would you have some time to review this as well? Thank you!

apple/internal/aspects/resource_aspect.bzl Outdated Show resolved Hide resolved
apple/internal/aspects/resource_aspect.bzl Outdated Show resolved Hide resolved
apple/internal/aspects/resource_aspect_hint.bzl Outdated Show resolved Hide resolved
@gkoreman
Copy link
Contributor Author

gkoreman commented Aug 6, 2024 via email

@brentleyjones brentleyjones merged commit 91be02a into bazelbuild:master Aug 7, 2024
9 checks passed
@gkoreman gkoreman deleted the use_runfiles branch August 8, 2024 00:15
sewerynplazuk pushed a commit to sewerynplazuk/rules_apple that referenced this pull request Sep 20, 2024
bazelbuild#2479)

Fixes bazelbuild#2477

Include all data from cc_libraries as runfiles or resources, depending
on aspect_hints.
Provide aspect_hints for resource collection for all resource targets
(eg, swift_library, cc_library, etc)

By default all data is now included from cc_libraries as runfiles and
follows the expected runfiles folder structure, with files retaining
their nested folders and being placed in
/external/pkg_name/some/file.txt when included from a http_archive or
local_repository.

The default behavior for other resource collecting targets like
swift_library has not changed, and will continue to collect and process
data as resources.

To allow modification of this default behavior, users may add
aspect_hints to the target cc_library/swift_library/etc. There are three
supported aspect_hints:
@build_bazel_rules_apple//apple:use_runfiles
@build_bazel_rules_apple//apple:use_resources
@build_bazel_rules_apple//apple:suppress_resources

##### Example
Here is an example of modifying the default behavior to bundle data.txt
as a resource instead of a runfile.
```
cc_library(
    name = "libapp",
    srcs = ["main.cpp",],
    data = [":data.txt"],
    aspect_hints = ["@build_bazel_rules_apple//apple:use_runfiles"],
)

macos_application(
    name = "app_macos",
    deps = [":libapp"],
)
```
data.txt is bundled in Contents/Resources/data.txt

#### Note
Hints apply only to the target and do not affect transitive deps,
however if a target includes runfiles then all runfiles are bundled
(including transitive runfiles) regardless of the hints applied to
transitive targets.

---------

Co-authored-by: Luis Padron <[email protected]>
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.

Runfiles not bundled with macos_application
3 participants