Skip to content

Commit fa0280a

Browse files
Update apple/swift (#2079)
1 parent 13b47dc commit fa0280a

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!Dockerfile
3+
!extramoduleimports.patch
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1.19
2+
FROM swift:6.2.0-bookworm AS build
3+
4+
RUN apt-get update \
5+
&& apt-get install -y libstdc++-12-dev unzip
6+
COPY --link extramoduleimports.patch /app/extramoduleimports.patch
7+
WORKDIR /app
8+
RUN git clone --depth 1 --branch 1.33.1 https://github.com/apple/swift-protobuf --recursive
9+
WORKDIR /app/swift-protobuf
10+
RUN git apply /app/extramoduleimports.patch
11+
RUN swift build -c release --static-swift-stdlib -Xlinker -s
12+
13+
FROM gcr.io/distroless/cc-debian12:latest@sha256:0000f9dc0290f8eaf0ecceafbc35e803649087ea7879570fbc78372df7ac649b AS base
14+
15+
FROM scratch
16+
COPY --link --from=base / /
17+
COPY --link --from=build /app/swift-protobuf/.build/release/protoc-gen-swift .
18+
USER nobody
19+
ENTRYPOINT [ "/protoc-gen-swift" ]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: v1
2+
name: buf.build/apple/swift
3+
plugin_version: v1.33.1
4+
source_url: https://github.com/apple/swift-protobuf
5+
integration_guide_url: https://github.com/apple/swift-protobuf#getting-started
6+
description: Base types for Swift. Generates message and enum types.
7+
output_languages:
8+
- swift
9+
registry:
10+
swift:
11+
deps:
12+
- source: https://github.com/apple/swift-protobuf.git
13+
package: swift-protobuf
14+
swift_versions: [ ".v5", ".v6" ]
15+
products: [ SwiftProtobuf ]
16+
version: 1.33.1
17+
opts:
18+
- Visibility=Public
19+
- FileNaming=PathToUnderscores
20+
spdx_license_id: Apache-2.0
21+
license_url: https://github.com/apple/swift-protobuf/blob/1.33.1/LICENSE.txt
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift
2+
index f0cddb24..e5864211 100644
3+
--- a/Sources/protoc-gen-swift/FileGenerator.swift
4+
+++ b/Sources/protoc-gen-swift/FileGenerator.swift
5+
@@ -149,6 +149,14 @@ class FileGenerator {
6+
return
7+
}
8+
9+
+ let neededCustomImports = generatorOptions.extraModuleImports
10+
+ if !neededCustomImports.isEmpty {
11+
+ p.print()
12+
+ for i in neededCustomImports {
13+
+ p.print("import \(i)\n")
14+
+ }
15+
+ }
16+
+
17+
p.print()
18+
generateVersionCheck(printer: &p)
19+
20+
diff --git a/Sources/protoc-gen-swift/GeneratorOptions.swift b/Sources/protoc-gen-swift/GeneratorOptions.swift
21+
index 3224e138..8bfc1ce5 100644
22+
--- a/Sources/protoc-gen-swift/GeneratorOptions.swift
23+
+++ b/Sources/protoc-gen-swift/GeneratorOptions.swift
24+
@@ -64,6 +64,7 @@ class GeneratorOptions {
25+
}
26+
}
27+
28+
+ let extraModuleImports: [String]
29+
let outputNaming: OutputNaming
30+
let protoToModuleMappings: ProtoFileToModuleMappings
31+
let visibility: Visibility
32+
@@ -74,6 +75,7 @@ class GeneratorOptions {
33+
let visibilitySourceSnippet: String
34+
35+
init(parameter: any CodeGeneratorParameter) throws {
36+
+ var externalModuleImports: [String] = []
37+
var outputNaming: OutputNaming = .fullPath
38+
var moduleMapPath: String?
39+
var visibility: Visibility = .internal
40+
@@ -146,6 +148,15 @@ class GeneratorOptions {
41+
value: pair.value
42+
)
43+
}
44+
+ case "ExtraModuleImports":
45+
+ if !pair.value.isEmpty {
46+
+ externalModuleImports.append(pair.value)
47+
+ } else {
48+
+ throw GenerationError.invalidParameterValue(
49+
+ name: pair.key,
50+
+ value: pair.value
51+
+ )
52+
+ }
53+
default:
54+
throw GenerationError.unknownParameter(name: pair.key)
55+
}
56+
@@ -179,6 +190,7 @@ class GeneratorOptions {
57+
visibilitySourceSnippet = "package "
58+
}
59+
60+
+ self.extraModuleImports = externalModuleImports
61+
self.experimentalStripNonfunctionalCodegen = experimentalStripNonfunctionalCodegen
62+
63+
switch (implementationOnlyImports, useAccessLevelOnImports) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
h1:ep7eRBaCZYegnNuYt01ISHnPmoQQfYD3cOiayRryTIU=
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
h1:R/ayfFL1UMZiBYEWqgTodlpaLgWs2i9TWcj0x/Y+98A=

0 commit comments

Comments
 (0)