From 419a6f07756cec7c54d344bc98432171edd4419b Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Wed, 28 Aug 2024 14:50:14 +0100 Subject: [PATCH 1/5] Enable access level on imports in remaining modules --- Package@swift-6.swift | 6 ++++-- Protos/generate.sh | 8 ++++---- .../InteroperabilityTests/InteroperabilityTestCase.swift | 2 +- .../InteroperabilityTests/InteroperabilityTestCases.swift | 5 ++--- Sources/InteroperabilityTests/TestService.swift | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Package@swift-6.swift b/Package@swift-6.swift index 6b41375d6..7b5b81394 100644 --- a/Package@swift-6.swift +++ b/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") ] ) } diff --git a/Protos/generate.sh b/Protos/generate.sh index 6346105b2..58eebb5f0 100755 --- a/Protos/generate.sh +++ b/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,7 +228,7 @@ 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_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" done } @@ -260,7 +260,7 @@ 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_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true" generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "_V2=true" } diff --git a/Sources/InteroperabilityTests/InteroperabilityTestCase.swift b/Sources/InteroperabilityTests/InteroperabilityTestCase.swift index 74fdcd35b..1c60f1401 100644 --- a/Sources/InteroperabilityTests/InteroperabilityTestCase.swift +++ b/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 { diff --git a/Sources/InteroperabilityTests/InteroperabilityTestCases.swift b/Sources/InteroperabilityTests/InteroperabilityTestCases.swift index d43e58590..be1c22e04 100644 --- a/Sources/InteroperabilityTests/InteroperabilityTestCases.swift +++ b/Sources/InteroperabilityTests/InteroperabilityTestCases.swift @@ -14,9 +14,8 @@ * limitations under the License. */ -import GRPCCore - -import struct Foundation.Data +internal import GRPCCore +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 diff --git a/Sources/InteroperabilityTests/TestService.swift b/Sources/InteroperabilityTests/TestService.swift index 669cf5c41..02c27c1f3 100644 --- a/Sources/InteroperabilityTests/TestService.swift +++ b/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 { From d99ca92dbcf8f961311c85f8c61ead21410cf7e7 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Tue, 3 Sep 2024 16:16:51 +0100 Subject: [PATCH 2/5] Regenerate protos --- Sources/InteroperabilityTests/Generated/empty.pb.swift | 2 +- Sources/InteroperabilityTests/Generated/messages.pb.swift | 4 ++-- Sources/Services/Health/Generated/health.pb.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/InteroperabilityTests/Generated/empty.pb.swift b/Sources/InteroperabilityTests/Generated/empty.pb.swift index 840c3367f..7e246bf7b 100644 --- a/Sources/InteroperabilityTests/Generated/empty.pb.swift +++ b/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 diff --git a/Sources/InteroperabilityTests/Generated/messages.pb.swift b/Sources/InteroperabilityTests/Generated/messages.pb.swift index fa2318afd..cd0a3dd15 100644 --- a/Sources/InteroperabilityTests/Generated/messages.pb.swift +++ b/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 diff --git a/Sources/Services/Health/Generated/health.pb.swift b/Sources/Services/Health/Generated/health.pb.swift index 35bec2020..ea2cde5c6 100644 --- a/Sources/Services/Health/Generated/health.pb.swift +++ b/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 From dd2df758ce59d38690ee8dd68150fae3944a63bf Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Tue, 3 Sep 2024 16:19:36 +0100 Subject: [PATCH 3/5] Formatting --- Sources/InteroperabilityTests/InteroperabilityTestCases.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/InteroperabilityTests/InteroperabilityTestCases.swift b/Sources/InteroperabilityTests/InteroperabilityTestCases.swift index be1c22e04..b1be0be50 100644 --- a/Sources/InteroperabilityTests/InteroperabilityTestCases.swift +++ b/Sources/InteroperabilityTests/InteroperabilityTestCases.swift @@ -15,6 +15,7 @@ */ internal import GRPCCore + private import struct Foundation.Data /// This test verifies that implementations support zero-size messages. Ideally, client From ef7e527a720c31b3caeae44d9306d34b810a1519 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Thu, 5 Sep 2024 13:55:41 +0100 Subject: [PATCH 4/5] PR fixes --- Sources/protoc-gen-grpc-swift/Options.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/protoc-gen-grpc-swift/Options.swift b/Sources/protoc-gen-grpc-swift/Options.swift index 278864dcf..b8b539431 100644 --- a/Sources/protoc-gen-grpc-swift/Options.swift +++ b/Sources/protoc-gen-grpc-swift/Options.swift @@ -77,7 +77,11 @@ struct GeneratorOptions { #if compiler(>=6.0) private(set) var v2 = false #endif + #if swift(>=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) From 4a51a892bdcd2495d237a327ff12cd94e9d3ed47 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Fri, 6 Sep 2024 09:48:58 +0100 Subject: [PATCH 5/5] PR Fix --- Protos/generate.sh | 4 ++-- Sources/protoc-gen-grpc-swift/Options.swift | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Protos/generate.sh b/Protos/generate.sh index 58eebb5f0..5eb6aa313 100755 --- a/Protos/generate.sh +++ b/Protos/generate.sh @@ -229,7 +229,7 @@ function generate_service_messages_interop_tests { for proto in "${protos[@]}"; do 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" + generate_grpc "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "Server=true" "_V2=true" "FileNaming=DropPath" "UseAccessLevelOnImports=true" done } @@ -261,7 +261,7 @@ function generate_health_service { local output="$root/Sources/Services/Health/Generated" generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true" - generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "_V2=true" + generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "_V2=true" "UseAccessLevelOnImports=true" } #------------------------------------------------------------------------------ diff --git a/Sources/protoc-gen-grpc-swift/Options.swift b/Sources/protoc-gen-grpc-swift/Options.swift index b8b539431..7c7077eff 100644 --- a/Sources/protoc-gen-grpc-swift/Options.swift +++ b/Sources/protoc-gen-grpc-swift/Options.swift @@ -74,10 +74,12 @@ 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 swift(>=6.0) + + #if compiler(>=6.0) private(set) var useAccessLevelOnImports = true #else private(set) var useAccessLevelOnImports = false