Skip to content

bazel: Remove custom framework rule#797

Closed
keith wants to merge 4 commits intomasterfrom
ks/bazel-remove-custom-framework-rule
Closed

bazel: Remove custom framework rule#797
keith wants to merge 4 commits intomasterfrom
ks/bazel-remove-custom-framework-rule

Conversation

@keith
Copy link
Member

@keith keith commented Apr 20, 2020

With this change we can remove our custom swift_static_framework rule
and replace it with the rules_apple ios_static_framework rule. There are
a few behavioral differences here that required other changes.

  1. ios_static_framework uses -enable-library-evolution, which means we
    get a swiftinterface file instead of a swiftmodule. This opts us
    in to having to guarantee some level of binary compatibility (once we
    hit 1.0 at least) but has the benefit of not requiring consumers to
    be on the exact same Xcode version as what we build with
  2. To Support Initial setup #1 we had to remove the bridging header use, this was
    previously required because if we imported the Objective-C dependency
    directly it also had to be shipped to consumers. Now we use
    @_implementationOnly imports with this, and consume it with
    private_deps so it's not exposed to consumers at all. This is a
    new-ish private feature in the Swift compiler to support this type of
    use case.
  3. To propagate the correct header with the framework so that it can be
    imported by Objective-C (which isn't automatically done by
    rules_swift / rules_apple
    Add generated_header to SwiftInfo? bazelbuild/rules_swift#291) we need to
    access it from the swift_library target, which I wrote a tiny rule to
    do.

Signed-off-by: Keith Smiley keithbsmiley@gmail.com

dep = ctx.attr.deps[0]
return [
DefaultInfo(
files = dep[CcInfo].compilation_context.headers,
Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK since this is a direct dep there cannot be more than 1 in this list, but I could filter by ones ending with -Swift.h if that wasn't the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I saw in the past we only had one here IIRC, so this is prob fine

@keith
Copy link
Member Author

keith commented Apr 20, 2020

Depends on #796

rebello95
rebello95 previously approved these changes Apr 20, 2020
Copy link
Contributor

@rebello95 rebello95 left a comment

Choose a reason for hiding this comment

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

So much better!

dep = ctx.attr.deps[0]
return [
DefaultInfo(
files = dep[CcInfo].compilation_context.headers,
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I saw in the past we only had one here IIRC, so this is prob fine


swift_header_collector(
name = "collector",
deps = ["lib"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change make it possible for us to split out the above code into different libraries and still collect them into one framework here?

Copy link
Member Author

Choose a reason for hiding this comment

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

not particularly right here, but overall it depends on how you want to split things up. if you have public API in multiple modules I don't think that will end up working in a single framework, but if you have other internal modules like the EnvoyEngine objc is acting as here now, you could include that in private_deps and have as many as you want. But I think no matter what you'll have to be able to @_implementationOnly import them

kastiglione
kastiglione previously approved these changes Apr 20, 2020
keith added 3 commits April 20, 2020 14:30
With this change we can remove our custom swift_static_framework rule
and replace it with the rules_apple ios_static_framework rule. There are
a few behavioral differences here that required other changes.

1. ios_static_framework uses `-enable-library-evolution`, which means we
   get a `swiftinterface` file instead of a `swiftmodule`. This opts us
   in to having to guarantee some level of binary compatibility (once we
   hit 1.0 at least) but has the benefit of not requiring consumers to
   be on the exact same Xcode version as what we build with
2. To Support #1 we had to remove the bridging header use, this was
   previously required because if we imported the Objective-C dependency
   directly it also had to be shipped to consumers. Now we use
   `@_implementationOnly` imports with this, and consume it with
   `private_deps` so it's not exposed to consumers at all. This is a
   new-ish private feature in the Swift compiler to support this type of
   use case.
3. To propagate the correct header with the framework so that it can be
   imported by Objective-C (which isn't automatically done by
   rules_swift / rules_apple
   bazelbuild/rules_swift#291) we need to
   access it from the swift_library target, which I wrote a tiny rule to
   do.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@keith keith force-pushed the ks/bazel-remove-custom-framework-rule branch from ba42f26 to ce6b7b8 Compare April 20, 2020 21:31
@keith
Copy link
Member Author

keith commented Apr 20, 2020

Might actually depend on bazelbuild/rules_apple#753

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@keith
Copy link
Member Author

keith commented Apr 22, 2020

Potential fix for the duplicate symbol issue I'm seeing currently bazelbuild/rules_swift#420

1 similar comment
@keith
Copy link
Member Author

keith commented Apr 22, 2020

Potential fix for the duplicate symbol issue I'm seeing currently bazelbuild/rules_swift#420

@keith
Copy link
Member Author

keith commented Apr 24, 2020

Filed an issue for the blocker here bazelbuild/bazel#11223

@keith keith changed the title [bazel] Remove custom framework rule bazel: Remove custom framework rule Apr 27, 2020
keith added a commit that referenced this pull request Apr 27, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
keith added a commit that referenced this pull request Apr 27, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@stale
Copy link

stale bot commented May 5, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale label May 5, 2020
keith added a commit that referenced this pull request May 7, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@stale
Copy link

stale bot commented May 12, 2020

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this May 12, 2020
keith added a commit that referenced this pull request May 12, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
keith added a commit that referenced this pull request May 18, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
keith added a commit that referenced this pull request May 28, 2020
This is an in between to #797
which starts building the archive with swiftinterface files, but does
it with our existing swift_static_framework rule because of issues
linked on that PR.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
@junr03 junr03 deleted the ks/bazel-remove-custom-framework-rule branch July 8, 2020 21:25
@junr03 junr03 restored the ks/bazel-remove-custom-framework-rule branch July 15, 2021 23:42
@junr03 junr03 mentioned this pull request Jul 21, 2021
@junr03 junr03 deleted the ks/bazel-remove-custom-framework-rule branch December 23, 2021 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants