Browse Source

Enable `InternalImportsByDefault` in remaining modules (#2042)

This PR enables `InternalImportsByDefault` on `GRPCHealth` and
`InteroperabilityTests`.
It also regenerates the protos with the latest version of swift-protobuf
(v1.28.1), and increases its min version to 1.28.1 to make sure that we
don't get build failures when using earlier generators.
Gus Cairo 1 year ago
parent
commit
1b060a3210

+ 4 - 2
Package@swift-6.swift

@@ -550,7 +550,8 @@ extension Target {
       ],
       swiftSettings: [
         .swiftLanguageMode(.v6),
-        .enableUpcomingFeature("ExistentialAny")
+        .enableUpcomingFeature("ExistentialAny"),
+        .enableUpcomingFeature("InternalImportsByDefault")
       ]
     )
   }
@@ -950,7 +951,8 @@ extension Target {
       path: "Sources/Services/Health",
       swiftSettings: [
         .swiftLanguageMode(.v6),
-        .enableUpcomingFeature("ExistentialAny")
+        .enableUpcomingFeature("ExistentialAny"),
+        .enableUpcomingFeature("InternalImportsByDefault")
       ]
     )
   }

+ 6 - 6
Protos/generate.sh

@@ -29,7 +29,7 @@ bin_path=$(swift build -c release --show-bin-path)
 protoc_gen_swift="$bin_path/protoc-gen-swift"
 protoc_generate_grpc_swift="$bin_path/protoc-gen-grpc-swift"
 
-# Genreates gRPC by invoking protoc with the gRPC Swift plugin.
+# Generates gRPC by invoking protoc with the gRPC Swift plugin.
 # Parameters:
 # - $1: .proto file
 # - $2: proto path
@@ -46,7 +46,7 @@ function generate_grpc {
   invoke_protoc "${args[@]}" "$proto"
 }
 
-# Genreates messages by invoking protoc with the Swift plugin.
+# Generates messages by invoking protoc with the Swift plugin.
 # Parameters:
 # - $1: .proto file
 # - $2: proto path
@@ -228,8 +228,8 @@ function generate_service_messages_interop_tests {
   local output="$root/Sources/InteroperabilityTests/Generated"
 
   for proto in "${protos[@]}"; do
-    generate_message "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "FileNaming=DropPath"
-    generate_grpc "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "Server=true" "_V2=true" "FileNaming=DropPath"
+    generate_message "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "FileNaming=DropPath" "UseAccessLevelOnImports=true"
+    generate_grpc "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "Server=true" "_V2=true" "FileNaming=DropPath" "UseAccessLevelOnImports=true"
   done
 }
 
@@ -260,8 +260,8 @@ function generate_health_service {
   local proto="$here/upstream/grpc/health/v1/health.proto"
   local output="$root/Sources/Services/Health/Generated"
 
-  generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package"
-  generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "_V2=true"
+  generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true"
+  generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "_V2=true" "UseAccessLevelOnImports=true"
 }
 
 #------------------------------------------------------------------------------

+ 1 - 1
Sources/InteroperabilityTests/Generated/empty.pb.swift

@@ -22,7 +22,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import SwiftProtobuf
+public import SwiftProtobuf
 
 // If the compiler emits an error on this type, it is because this file
 // was generated by a version of the `protoc` Swift plug-in that is

+ 2 - 2
Sources/InteroperabilityTests/Generated/messages.pb.swift

@@ -24,8 +24,8 @@
 
 // Message definitions to be used by integration test service definitions.
 
-import Foundation
-import SwiftProtobuf
+public import Foundation
+public import SwiftProtobuf
 
 // If the compiler emits an error on this type, it is because this file
 // was generated by a version of the `protoc` Swift plug-in that is

+ 1 - 1
Sources/InteroperabilityTests/InteroperabilityTestCase.swift

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import GRPCCore
+public import GRPCCore
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 public protocol InteroperabilityTest {

+ 2 - 2
Sources/InteroperabilityTests/InteroperabilityTestCases.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
-import struct Foundation.Data
+private import struct Foundation.Data
 
 /// This test verifies that implementations support zero-size messages. Ideally, client
 /// implementations would verify that the request and response were zero bytes serialized, but

+ 2 - 2
Sources/InteroperabilityTests/TestService.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import Foundation
-import GRPCCore
+private import Foundation
+public import GRPCCore
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 public struct TestService: Grpc_Testing_TestService.ServiceProtocol {

+ 1 - 1
Sources/Services/Health/Generated/health.pb.swift

@@ -25,7 +25,7 @@
 // The canonical version of this proto can be found at
 // https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto
 
-import SwiftProtobuf
+package import SwiftProtobuf
 
 // If the compiler emits an error on this type, it is because this file
 // was generated by a version of the `protoc` Swift plug-in that is

+ 6 - 0
Sources/protoc-gen-grpc-swift/Options.swift

@@ -74,10 +74,16 @@ struct GeneratorOptions {
   private(set) var gRPCModuleName = "GRPC"
   private(set) var swiftProtobufModuleName = "SwiftProtobuf"
   private(set) var generateReflectionData = false
+
   #if compiler(>=6.0)
   private(set) var v2 = false
   #endif
+
+  #if compiler(>=6.0)
   private(set) var useAccessLevelOnImports = true
+  #else
+  private(set) var useAccessLevelOnImports = false
+  #endif
 
   init(parameter: any CodeGeneratorParameter) throws {
     try self.init(pairs: parameter.parsedPairs)