bazelbuild / rules_swift

Bazel rules to build Swift on Apple and Linux platforms
Apache License 2.0
313 stars 138 forks source link

New `swift_proto_library` rule ignores `srcs` #1330

Open rasberik opened 1 month ago

rasberik commented 1 month ago

Description

Despite intention of new swift_proto_library to behave like regular swift_library by inheriting its attributes, doesn't allow to add additional srcs.

Example

diff --git a/examples/xplatform/proto_files/BUILD b/examples/xplatform/proto_files/BUILD
index f43ebee..40336a9 100644
--- a/examples/xplatform/proto_files/BUILD
+++ b/examples/xplatform/proto_files/BUILD
@@ -4,6 +4,7 @@ load(
 )
 load("//proto:swift_proto_library.bzl", "swift_proto_library")
 load("//swift:swift_binary.bzl", "swift_binary")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")

 proto_library(
     name = "message_1_proto",
@@ -43,6 +44,7 @@ swift_proto_library(

 swift_proto_library(
     name = "messages_3_swift_proto",
+    srcs = [":MessagesExport"],
     module_name = "Messages_3",
     protos = [
         ":message_3_proto",
@@ -62,3 +64,11 @@ swift_binary(
         ":messages_3_swift_proto",
     ],
 )
+
+write_file(
+    name = "MessagesExport",
+    out = "MessagesExport.swift",
+    content = [
+        "@_exported import Messages_1_2"
+    ],
+)
rasberik commented 1 month ago

@AttilaTheFun @brentleyjones Apologies for direct tags, can I get any thoughts whether this behavior recognized as intended or an issue? Currently can be resolved by adding wrapper workarounds but would be much nicer to have ability to add additional srcs files.

AttilaTheFun commented 1 month ago

@rasberik Hmm this is an interesting question.

I never thought about the use case of injecting additional source files into the library but I don't think it would be too hard to support.

I think we'd just need to append the srcs attribute to the list of generated srcs passed to swift_common.compile

I'm not a maintainer of rules_swift so I can't approve the PR but @brentleyjones or @luispadron might be able to review it.