Skip to content

Conversation

@AttilaTheFun
Copy link
Contributor

@AttilaTheFun AttilaTheFun commented Feb 23, 2024

I recently merged #1140 which introduced a new, highly-customizable swift_proto_library implementation.

However, because this dropped support for the proto aspect, consumers of the deprecated rules who relied on this behavior and don't want to use a tool like gazelle to generate their build files will have a hard time migrating to the new rules.

This PR introduces a new swift_proto_library_group rule which uses an aspect and functions very similarly to the deprecated rule to facilitate their migration. Because of the limitations of aspects, though, they will be unable to benefit from some of the customization options afforded to the new swift_proto_library rule including custom module names. This was true of the deprecated rules and it will be true of the aspect-based rule as well.

To avoid repeated / diverging logic, I extracted most of the logic necessary to generate the swift source files and compile them + aggregate the providers into the swift_proto_utils.bzl file and shared this between the swift_proto_library and swift_proto_library_group rules.

I've also added a working GRPC example which shows how to combine swift_proto_library and swift_proto_library_group targets. As with the old rule, swift_proto_library_group does not support GRPC generation directly. However, you can create a swift_proto_library target to generate your service protos which depends on a swift_proto_library_group which generates everything else. This is how the deprecated rules behaved with a swift_grpc_library depending on a (deprecated) swift_proto_library target.

@AttilaTheFun AttilaTheFun changed the title WIP Add swift_proto_library_group rule Feb 26, 2024
@AttilaTheFun AttilaTheFun marked this pull request as ready for review March 2, 2024 23:40
@AttilaTheFun AttilaTheFun force-pushed the lshire-swift-proto-library-group branch from 3a790c7 to 7de082a Compare March 31, 2024 19:35
@AttilaTheFun AttilaTheFun force-pushed the lshire-swift-proto-library-group branch from c44496b to 74cf25d Compare April 2, 2024 20:53
@brentleyjones brentleyjones merged commit ea2d4bd into bazelbuild:master Apr 5, 2024
@rasberik
Copy link

rasberik commented Aug 16, 2024

@AttilaTheFun @brentleyjones In case I am missing something, is there way to apply additional_compiler_info to this rule?

New proto rules dont seem to respect swift.generate_path_to_underscores_from_proto_files on proto_library, and there is no option like

additional_compiler_info = {
        "FileNaming": "PathToUnderscores",
    },

as with new swift_proto_library.

I was migrating from old proto and due to large scale, tried to use swift_proto_library_group but cannot resolve duplication issues.

@AttilaTheFun
Copy link
Contributor Author

@rasberik the swift_proto_library_group doesn't support that attribute yet, but you can customize the swift_proto_compiler through the compiler attribute here:
https://github.com/bazelbuild/rules_swift/blob/master/proto/swift_proto_library_group.bzl#L141

On your custom swift_proto_compiler target you can customize the options, so you can accomplish this that way.

You're welcome to create a feature request or PR to add the additional_compiler_info attribute to swift_proto_library_group and plumb it into the aspect through the transition similar to the compiler attribute. I think this would be fairly simple?

cc @brentleyjones

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.

4 participants