-
Notifications
You must be signed in to change notification settings - Fork 16
Add swift v1.22.0 with updated patch #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * | ||
| !Dockerfile | ||
| !extramoduleimports.patch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # syntax=docker/dockerfile:1.4 | ||
| FROM swift:5.8.1-focal AS build | ||
|
|
||
| COPY extramoduleimports.patch /app/extramoduleimports.patch | ||
| WORKDIR /app | ||
| RUN git clone --depth 1 --branch 1.22.0 https://github.com/apple/swift-protobuf --recursive | ||
| WORKDIR /app/swift-protobuf | ||
| RUN git apply /app/extramoduleimports.patch | ||
| RUN swift build -c release --static-swift-stdlib -Xlinker -s | ||
|
|
||
| FROM gcr.io/distroless/cc-debian11 | ||
| COPY --from=build --link /app/swift-protobuf/.build/release/protoc-gen-swift . | ||
| USER nobody | ||
| ENTRYPOINT [ "/protoc-gen-swift" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| version: v1 | ||
| name: buf.build/apple/swift | ||
| plugin_version: v1.22.0 | ||
| source_url: https://github.com/apple/swift-protobuf | ||
| description: Base types for Swift. Generates message and enum types. | ||
| output_languages: | ||
| - swift | ||
| registry: | ||
| swift: | ||
| deps: | ||
| - source: https://github.com/apple/swift-protobuf.git | ||
| package: swift-protobuf | ||
| swift_versions: [ ".v5" ] | ||
| products: [ SwiftProtobuf ] | ||
| version: 1.22.0 | ||
| opts: | ||
| - Visibility=Public | ||
| - FileNaming=PathToUnderscores | ||
| spdx_license_id: Apache-2.0 | ||
| license_url: https://github.com/apple/swift-protobuf/blob/1.22.0/LICENSE.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift | ||
| index 90fd06a6..93460574 100644 | ||
| --- a/Sources/protoc-gen-swift/FileGenerator.swift | ||
| +++ b/Sources/protoc-gen-swift/FileGenerator.swift | ||
| @@ -121,6 +121,13 @@ class FileGenerator { | ||
| p.print("\(visibilityAnnotation)import \(i)\n") | ||
| } | ||
| } | ||
| + let neededCustomImports = generatorOptions.extraModuleImports | ||
| + if !neededCustomImports.isEmpty { | ||
| + p.print() | ||
| + for i in neededCustomImports { | ||
| + p.print("import \(i)\n") | ||
| + } | ||
| + } | ||
|
|
||
| p.print("\n") | ||
| generateVersionCheck(printer: &p) | ||
| diff --git a/Sources/protoc-gen-swift/GeneratorOptions.swift b/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
| index 69ecdb86..e0f2e26e 100644 | ||
| --- a/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
| +++ b/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
| @@ -50,6 +50,7 @@ class GeneratorOptions { | ||
| let protoToModuleMappings: ProtoFileToModuleMappings | ||
| let visibility: Visibility | ||
| let implementationOnlyImports: Bool | ||
| + let extraModuleImports: [String] | ||
|
|
||
| /// A string snippet to insert for the visibility | ||
| let visibilitySourceSnippet: String | ||
| @@ -60,6 +61,7 @@ class GeneratorOptions { | ||
| var visibility: Visibility = .internal | ||
| var swiftProtobufModuleName: String? = nil | ||
| var implementationOnlyImports: Bool = false | ||
| + var externalModuleImports: [String] = [] | ||
|
|
||
| for pair in parseParameter(string:parameter) { | ||
| switch pair.key { | ||
| @@ -94,6 +96,12 @@ class GeneratorOptions { | ||
| if let value = Bool(pair.value) { | ||
| implementationOnlyImports = value | ||
| } | ||
| + case "ExtraModuleImports": | ||
| + if !pair.value.isEmpty { | ||
| + externalModuleImports.append(pair.value) | ||
| + } else { | ||
| + throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value) | ||
| + } | ||
| default: | ||
| throw GenerationError.unknownParameter(name: pair.key) | ||
| } | ||
| @@ -122,5 +130,6 @@ class GeneratorOptions { | ||
| } | ||
|
|
||
| self.implementationOnlyImports = implementationOnlyImports | ||
| + self.extraModuleImports = externalModuleImports | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| h1:ffGsj903OkejaJHBJ9J0lmZkRiA58mar/OznBW1O9Wo= |
1 change: 1 addition & 0 deletions
1
tests/testdata/buf.build/apple/swift/v1.22.0/petapis/plugin.sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| h1:0b5iqMifZQ1mLRYdO83BFuNf3JagkBeYg5O++DTSFhE= |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the patch to apply cleanly on this version - there were some changes upstream in apple/swift-protobuf@6b33e90 that caused the previous patch not to apply.
@pgmitche / @stefanvanburen / @rebello95 - I'm not sure if we want to do anything here with the new visibilityAnnotation logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks essentially identical, so happy to approve on that basis.
If I'm understanding the annotation correctly, then it sounds like symbols in the packages generated with that annotation would not be importable, so wouldn't be compatible with remote packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need to do anything for that new option, we don't have a use case for implementation-only imports with remote packages. Also updating Connect-Swift: connectrpc/connect-swift#136