rules_swift icon indicating copy to clipboard operation
rules_swift copied to clipboard

`private_deps` may lost `data` fields which could cause an unexpected resource lost

Open xiemotongye opened this issue 1 year ago • 3 comments

Please take a look at this example: https://github.com/xiemotongye/private_deps_data_issue

When we use deps in swift_library.

swift_library(
    name = "Sources",
    srcs = [
        "AppDelegate.swift",
    ],
    module_name = "Sources",
    #private_deps = [
    #    "//srcs/A:a_lib",
    #    "//srcs/B:b_lib",
    #]
    deps = [
        "//srcs/A:a_lib",
        "//srcs/B:b_lib",
    ]
)

Run this command in terminal to build an ipa.

bazel build //:private_deps_demo

Unarchive bazel-bin/private_deps_demo.ipa, we will see bazel-swift.png & bazel-objc.png in Payload.

But when we use private_deps in swift_library.

swift_library(
    name = "Sources",
    srcs = [
        "AppDelegate.swift",
    ],
    module_name = "Sources",
    private_deps = [
        "//srcs/A:a_lib",
        "//srcs/B:b_lib",
    ]
    #deps = [
    #    "//srcs/A:a_lib",
    #    "//srcs/B:b_lib",
    #]
)

We run the same command in terminal to build another ipa.

bazel build //:private_deps_demo

Let's unarchive bazel-bin/private_deps_demo.ipa again.

This time, there is no bazel-swift.png & bazel-objc.png in Payload.

I don't think this is an expected output. This behavior may cause some unexpected resource lost, and it's hard to discover which resources are missing.

xiemotongye avatar Jul 14 '23 10:07 xiemotongye

We probably just have to adjust (some of?) these locations to also include private_deps:

  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/xcframework_rules.bzl#L541
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/xcframework_rules.bzl#L1011
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L62
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L261
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L295 (this one for sure)

Can you make a PR with the required fix(es), including some tests, and then we can review it?

brentleyjones avatar Jul 14 '23 14:07 brentleyjones

Bazel 6.3 will support implementation_deps in objc_library(https://github.com/bazelbuild/bazel/issues/18298) it seems that we need to support this attribute as well

xinzhengzhang avatar Jul 15 '23 16:07 xinzhengzhang

We probably just have to adjust (some of?) these locations to also include private_deps:

  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/xcframework_rules.bzl#L541
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/xcframework_rules.bzl#L1011
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L62
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L261
  • https://github.com/bazelbuild/rules_apple/blob/c678d8d0cbf3767007e303196680ee14a31b78da/apple/internal/aspects/resource_aspect.bzl#L295 (this one for sure)

Can you make a PR with the required fix(es), including some tests, and then we can review it?

OK. I will have a try this week.

xiemotongye avatar Jul 17 '23 06:07 xiemotongye