-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add apple/swift v1.28.2 plugin (#1536)
Needed to fix up the patch, as the upstream adopted `swift-format`: https://github.com/apple/swift-protobuf/releases/tag/1.28.2. Fixes #1529.
- Loading branch information
1 parent
813b0a8
commit b1776ea
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,19 @@ | ||
# syntax=docker/dockerfile:1.10 | ||
FROM swift:5.10.1-bookworm AS build | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y libstdc++-12-dev | ||
COPY --link extramoduleimports.patch /app/extramoduleimports.patch | ||
WORKDIR /app | ||
RUN git clone --depth 1 --branch 1.28.2 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-debian12:latest@sha256:3310655aac0d85eb9d579792387af1ff3eb7a1667823478be58020ab0e0d97a8 AS base | ||
|
||
FROM scratch | ||
COPY --link --from=base / / | ||
COPY --link --from=build /app/swift-protobuf/.build/release/protoc-gen-swift . | ||
USER nobody | ||
ENTRYPOINT [ "/protoc-gen-swift" ] |
This file contains 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,21 @@ | ||
version: v1 | ||
name: buf.build/apple/swift | ||
plugin_version: v1.28.2 | ||
source_url: https://github.com/apple/swift-protobuf | ||
integration_guide_url: https://github.com/apple/swift-protobuf#getting-started | ||
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.28.2 | ||
opts: | ||
- Visibility=Public | ||
- FileNaming=PathToUnderscores | ||
spdx_license_id: Apache-2.0 | ||
license_url: https://github.com/apple/swift-protobuf/blob/1.28.2/LICENSE.txt |
This file contains 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,63 @@ | ||
diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift | ||
index f0cddb24..e5864211 100644 | ||
--- a/Sources/protoc-gen-swift/FileGenerator.swift | ||
+++ b/Sources/protoc-gen-swift/FileGenerator.swift | ||
@@ -149,6 +149,14 @@ class FileGenerator { | ||
return | ||
} | ||
|
||
+ let neededCustomImports = generatorOptions.extraModuleImports | ||
+ if !neededCustomImports.isEmpty { | ||
+ p.print() | ||
+ for i in neededCustomImports { | ||
+ p.print("import \(i)\n") | ||
+ } | ||
+ } | ||
+ | ||
p.print() | ||
generateVersionCheck(printer: &p) | ||
|
||
diff --git a/Sources/protoc-gen-swift/GeneratorOptions.swift b/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
index 3224e138..8bfc1ce5 100644 | ||
--- a/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
+++ b/Sources/protoc-gen-swift/GeneratorOptions.swift | ||
@@ -64,6 +64,7 @@ class GeneratorOptions { | ||
} | ||
} | ||
|
||
+ let extraModuleImports: [String] | ||
let outputNaming: OutputNaming | ||
let protoToModuleMappings: ProtoFileToModuleMappings | ||
let visibility: Visibility | ||
@@ -74,6 +75,7 @@ class GeneratorOptions { | ||
let visibilitySourceSnippet: String | ||
|
||
init(parameter: any CodeGeneratorParameter) throws { | ||
+ var externalModuleImports: [String] = [] | ||
var outputNaming: OutputNaming = .fullPath | ||
var moduleMapPath: String? | ||
var visibility: Visibility = .internal | ||
@@ -146,6 +148,15 @@ class GeneratorOptions { | ||
value: pair.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) | ||
} | ||
@@ -179,6 +190,7 @@ class GeneratorOptions { | ||
visibilitySourceSnippet = "package " | ||
} | ||
|
||
+ self.extraModuleImports = externalModuleImports | ||
self.experimentalStripNonfunctionalCodegen = experimentalStripNonfunctionalCodegen | ||
|
||
switch (implementationOnlyImports, useAccessLevelOnImports) { |
This file contains 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:2V79rqozuiAEUtD1M8yNEC0x99wWa/swFpqQzak3InA= |
1 change: 1 addition & 0 deletions
1
tests/testdata/buf.build/apple/swift/v1.28.2/petapis/plugin.sum
This file contains 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:uoHRiWUJ7qWsF25fxHZTCCk/O+1mLNB1KbObPI6K/pw= |