Skip to content

Commit 763f08e

Browse files
Update protoc and apple/swift plugins (#2022)
1 parent dabc205 commit 763f08e

70 files changed

Lines changed: 714 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
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.18
2+
FROM swift:6.1.3-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.31.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:620d8b11ae800f0dbd7995f89ddc5344ad603269ea98770588b1b07a4a0a6872 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.31.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.31.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.31.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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!BUILD
3+
!cpp.cc
4+
!Dockerfile
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cc_binary(
2+
name = "protoc-gen-cpp",
3+
srcs = ["cpp.cc"],
4+
deps = [
5+
"//:protoc_lib",
6+
],
7+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# syntax=docker/dockerfile:1.18
2+
FROM debian:bookworm-20250908 AS build
3+
4+
ARG TARGETARCH
5+
ARG BAZEL_OPTS="--host_jvm_args=-Djava.net.preferIPv4Stack=true"
6+
7+
RUN apt-get update \
8+
&& apt-get install -y curl git cmake build-essential autoconf clang libc++-dev libtool pkg-config unzip zip
9+
RUN curl -fsSL -o /usr/local/bin/bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-${TARGETARCH} \
10+
&& chmod +x /usr/local/bin/bazelisk \
11+
&& mkdir /build \
12+
&& chown nobody:nogroup /build \
13+
&& usermod --home /build nobody
14+
15+
USER nobody
16+
WORKDIR /build
17+
RUN curl -fsSL -o protoc.tar.gz https://github.com/protocolbuffers/protobuf/releases/download/v32.1/protobuf-32.1.tar.gz \
18+
&& tar --strip-components=1 -zxf protoc.tar.gz \
19+
&& rm protoc.tar.gz
20+
RUN bazelisk ${BAZEL_OPTS} build '//:protoc_lib'
21+
COPY --link BUILD cpp.cc plugins/
22+
RUN bazelisk ${BAZEL_OPTS} build '//plugins:protoc-gen-cpp.stripped'
23+
24+
FROM gcr.io/distroless/cc-debian12:latest@sha256:620d8b11ae800f0dbd7995f89ddc5344ad603269ea98770588b1b07a4a0a6872 AS base
25+
26+
FROM scratch
27+
COPY --from=base --link / /
28+
COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp .
29+
USER nobody
30+
ENTRYPOINT ["/protoc-gen-cpp"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v1
2+
name: buf.build/protocolbuffers/cpp
3+
plugin_version: v32.1
4+
source_url: https://github.com/protocolbuffers/protobuf
5+
description: Base types for C++. Generates message and enum types.
6+
output_languages:
7+
- cpp
8+
spdx_license_id: BSD-3-Clause
9+
license_url: https://github.com/protocolbuffers/protobuf/blob/v32.1/LICENSE
10+
registry:
11+
cmake: {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <google/protobuf/compiler/cpp/generator.h>
2+
#include <google/protobuf/compiler/plugin.h>
3+
4+
int main(int argc, char *argv[]) {
5+
google::protobuf::compiler::cpp::CppGenerator generator;
6+
return google::protobuf::compiler::PluginMain(argc, argv, &generator);
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!BUILD
3+
!csharp.cc
4+
!Dockerfile
5+
!build.csproj

0 commit comments

Comments
 (0)