diff --git a/plugins/apple/swift/v1.28.1/.dockerignore b/plugins/apple/swift/v1.28.1/.dockerignore new file mode 100644 index 00000000..ff0a69ef --- /dev/null +++ b/plugins/apple/swift/v1.28.1/.dockerignore @@ -0,0 +1,3 @@ +* +!Dockerfile +!extramoduleimports.patch diff --git a/plugins/apple/swift/v1.28.1/Dockerfile b/plugins/apple/swift/v1.28.1/Dockerfile new file mode 100644 index 00000000..8326395b --- /dev/null +++ b/plugins/apple/swift/v1.28.1/Dockerfile @@ -0,0 +1,19 @@ +# syntax=docker/dockerfile:1.9 +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.1 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:3b75fdd33932d16e53a461277becf57c4f815c6cee5f6bc8f52457c095e004c8 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" ] diff --git a/plugins/apple/swift/v1.28.1/buf.plugin.yaml b/plugins/apple/swift/v1.28.1/buf.plugin.yaml new file mode 100644 index 00000000..023807ed --- /dev/null +++ b/plugins/apple/swift/v1.28.1/buf.plugin.yaml @@ -0,0 +1,21 @@ +version: v1 +name: buf.build/apple/swift +plugin_version: v1.28.1 +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.1 + opts: + - Visibility=Public + - FileNaming=PathToUnderscores +spdx_license_id: Apache-2.0 +license_url: https://github.com/apple/swift-protobuf/blob/1.28.1/LICENSE.txt diff --git a/plugins/apple/swift/v1.28.1/extramoduleimports.patch b/plugins/apple/swift/v1.28.1/extramoduleimports.patch new file mode 100644 index 00000000..a921365f --- /dev/null +++ b/plugins/apple/swift/v1.28.1/extramoduleimports.patch @@ -0,0 +1,60 @@ +diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift +index 6238fd10..e5d957da 100644 +--- a/Sources/protoc-gen-swift/FileGenerator.swift ++++ b/Sources/protoc-gen-swift/FileGenerator.swift +@@ -133,6 +133,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 bf9d9cdb..653ea0f1 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 +@@ -138,6 +140,12 @@ class GeneratorOptions { + throw GenerationError.invalidParameterValue(name: pair.key, + 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) + } +@@ -167,6 +175,7 @@ class GeneratorOptions { + visibilitySourceSnippet = "package " + } + ++ self.extraModuleImports = externalModuleImports + self.experimentalStripNonfunctionalCodegen = experimentalStripNonfunctionalCodegen + + switch (implementationOnlyImports, useAccessLevelOnImports) { diff --git a/tests/testdata/buf.build/apple/swift/v1.28.1/eliza/plugin.sum b/tests/testdata/buf.build/apple/swift/v1.28.1/eliza/plugin.sum new file mode 100644 index 00000000..c0074b95 --- /dev/null +++ b/tests/testdata/buf.build/apple/swift/v1.28.1/eliza/plugin.sum @@ -0,0 +1 @@ +h1:2V79rqozuiAEUtD1M8yNEC0x99wWa/swFpqQzak3InA= diff --git a/tests/testdata/buf.build/apple/swift/v1.28.1/petapis/plugin.sum b/tests/testdata/buf.build/apple/swift/v1.28.1/petapis/plugin.sum new file mode 100644 index 00000000..2608eeb7 --- /dev/null +++ b/tests/testdata/buf.build/apple/swift/v1.28.1/petapis/plugin.sum @@ -0,0 +1 @@ +h1:uoHRiWUJ7qWsF25fxHZTCCk/O+1mLNB1KbObPI6K/pw=