From 00c92ec78464b477bc9bb499ff4a4a1f2aa672b6 Mon Sep 17 00:00:00 2001 From: Steve Ayers Date: Wed, 27 Nov 2024 11:29:58 -0500 Subject: [PATCH] Add cmake support to protocolbuffers/cpp plugins to v25 (#1577) Also squash layers --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: app-token-plugins[bot] <116026991+app-token-plugins[bot]@users.noreply.github.com> Co-authored-by: mfridman <6278244+mfridman@users.noreply.github.com> Co-authored-by: Saquib Mian Co-authored-by: Philip K. Warren Co-authored-by: Michael Fridman Co-authored-by: Philip K. Warren --- .../protocolbuffers/cpp/v25.0/.dockerignore | 1 + plugins/protocolbuffers/cpp/v25.0/Dockerfile | 15 +++++++++----- .../protocolbuffers/cpp/v25.0/buf.plugin.yaml | 2 ++ .../cpp/v25.0/disable_cpp_editions.patch | 20 +++++++++++++++++++ .../protocolbuffers/cpp/v25.1/.dockerignore | 1 + plugins/protocolbuffers/cpp/v25.1/Dockerfile | 15 +++++++++----- .../protocolbuffers/cpp/v25.1/buf.plugin.yaml | 2 ++ .../cpp/v25.1/disable_cpp_editions.patch | 20 +++++++++++++++++++ .../protocolbuffers/cpp/v25.2/.dockerignore | 1 + plugins/protocolbuffers/cpp/v25.2/Dockerfile | 15 +++++++++----- .../protocolbuffers/cpp/v25.2/buf.plugin.yaml | 2 ++ .../cpp/v25.2/disable_cpp_editions.patch | 20 +++++++++++++++++++ plugins/protocolbuffers/cpp/v25.3/Dockerfile | 6 +++--- .../protocolbuffers/cpp/v25.3/buf.plugin.yaml | 2 ++ plugins/protocolbuffers/cpp/v26.0/Dockerfile | 11 ++++++---- .../protocolbuffers/cpp/v26.0/buf.plugin.yaml | 2 ++ 16 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 plugins/protocolbuffers/cpp/v25.0/disable_cpp_editions.patch create mode 100644 plugins/protocolbuffers/cpp/v25.1/disable_cpp_editions.patch create mode 100644 plugins/protocolbuffers/cpp/v25.2/disable_cpp_editions.patch diff --git a/plugins/protocolbuffers/cpp/v25.0/.dockerignore b/plugins/protocolbuffers/cpp/v25.0/.dockerignore index c80455688..ab1677e27 100644 --- a/plugins/protocolbuffers/cpp/v25.0/.dockerignore +++ b/plugins/protocolbuffers/cpp/v25.0/.dockerignore @@ -1,4 +1,5 @@ * !BUILD !cpp.cc +!disable_cpp_editions.patch !Dockerfile diff --git a/plugins/protocolbuffers/cpp/v25.0/Dockerfile b/plugins/protocolbuffers/cpp/v25.0/Dockerfile index 2adce92c9..9707154c4 100644 --- a/plugins/protocolbuffers/cpp/v25.0/Dockerfile +++ b/plugins/protocolbuffers/cpp/v25.0/Dockerfile @@ -1,5 +1,5 @@ -# syntax=docker/dockerfile:1.5 -FROM debian:bullseye-20231030 AS build +# syntax=docker/dockerfile:1.10 +FROM debian:bookworm-20241111 AS build ARG TARGETARCH @@ -16,9 +16,14 @@ RUN curl -fsSL -o protoc.tar.gz https://github.com/protocolbuffers/protobuf/rele && rm protoc.tar.gz RUN bazel build '//:protoc_lib' COPY --link BUILD cpp.cc plugins/ -RUN bazel build '//plugins:protoc-gen-cpp.stripped' +COPY --link disable_cpp_editions.patch . +RUN git apply < disable_cpp_editions.patch \ + && bazel build '//plugins:protoc-gen-cpp.stripped' -FROM gcr.io/distroless/cc-debian11 -COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . +FROM gcr.io/distroless/cc-debian12:latest@sha256:2fb69596e692931f909c4c69ab09e50608959eaf8898c44fa64db741a23588b0 AS base + +FROM scratch +COPY --link --from=base / / +COPY --link --from=build --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . USER nobody ENTRYPOINT ["/protoc-gen-cpp"] diff --git a/plugins/protocolbuffers/cpp/v25.0/buf.plugin.yaml b/plugins/protocolbuffers/cpp/v25.0/buf.plugin.yaml index 218f9c718..6cff71ed1 100644 --- a/plugins/protocolbuffers/cpp/v25.0/buf.plugin.yaml +++ b/plugins/protocolbuffers/cpp/v25.0/buf.plugin.yaml @@ -7,3 +7,5 @@ output_languages: - cpp spdx_license_id: BSD-3-Clause license_url: https://github.com/protocolbuffers/protobuf/blob/v25.0/LICENSE +registry: + cmake: {} diff --git a/plugins/protocolbuffers/cpp/v25.0/disable_cpp_editions.patch b/plugins/protocolbuffers/cpp/v25.0/disable_cpp_editions.patch new file mode 100644 index 000000000..c4a57ab64 --- /dev/null +++ b/plugins/protocolbuffers/cpp/v25.0/disable_cpp_editions.patch @@ -0,0 +1,20 @@ +diff --git a/src/google/protobuf/compiler/cpp/generator.h b/src/google/protobuf/compiler/cpp/generator.h +index 64f334d5b..fd6e08e84 100644 +--- a/src/google/protobuf/compiler/cpp/generator.h ++++ b/src/google/protobuf/compiler/cpp/generator.h +@@ -70,14 +70,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator { + std::string* error) const override; + + uint64_t GetSupportedFeatures() const override { +- return FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS; +- } +- +- Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } +- Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } +- +- std::vector GetFeatureExtensions() const override { +- return {GetExtensionReflection(pb::cpp)}; ++ return FEATURE_PROTO3_OPTIONAL; + } + + private: diff --git a/plugins/protocolbuffers/cpp/v25.1/.dockerignore b/plugins/protocolbuffers/cpp/v25.1/.dockerignore index c80455688..ab1677e27 100644 --- a/plugins/protocolbuffers/cpp/v25.1/.dockerignore +++ b/plugins/protocolbuffers/cpp/v25.1/.dockerignore @@ -1,4 +1,5 @@ * !BUILD !cpp.cc +!disable_cpp_editions.patch !Dockerfile diff --git a/plugins/protocolbuffers/cpp/v25.1/Dockerfile b/plugins/protocolbuffers/cpp/v25.1/Dockerfile index 3bb6c7991..21525a31f 100644 --- a/plugins/protocolbuffers/cpp/v25.1/Dockerfile +++ b/plugins/protocolbuffers/cpp/v25.1/Dockerfile @@ -1,5 +1,5 @@ -# syntax=docker/dockerfile:1.5 -FROM debian:bullseye-20231030 AS build +# syntax=docker/dockerfile:1.10 +FROM debian:bookworm-20241111 AS build ARG TARGETARCH @@ -16,9 +16,14 @@ RUN curl -fsSL -o protoc.tar.gz https://github.com/protocolbuffers/protobuf/rele && rm protoc.tar.gz RUN bazel build '//:protoc_lib' COPY --link BUILD cpp.cc plugins/ -RUN bazel build '//plugins:protoc-gen-cpp.stripped' +COPY --link disable_cpp_editions.patch . +RUN git apply < disable_cpp_editions.patch \ + && bazel build '//plugins:protoc-gen-cpp.stripped' -FROM gcr.io/distroless/cc-debian11 -COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . +FROM gcr.io/distroless/cc-debian12:latest@sha256:2fb69596e692931f909c4c69ab09e50608959eaf8898c44fa64db741a23588b0 AS base + +FROM scratch +COPY --link --from=base / / +COPY --link --from=build --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . USER nobody ENTRYPOINT ["/protoc-gen-cpp"] diff --git a/plugins/protocolbuffers/cpp/v25.1/buf.plugin.yaml b/plugins/protocolbuffers/cpp/v25.1/buf.plugin.yaml index 8d56264a0..32396a4a2 100644 --- a/plugins/protocolbuffers/cpp/v25.1/buf.plugin.yaml +++ b/plugins/protocolbuffers/cpp/v25.1/buf.plugin.yaml @@ -7,3 +7,5 @@ output_languages: - cpp spdx_license_id: BSD-3-Clause license_url: https://github.com/protocolbuffers/protobuf/blob/v25.1/LICENSE +registry: + cmake: {} diff --git a/plugins/protocolbuffers/cpp/v25.1/disable_cpp_editions.patch b/plugins/protocolbuffers/cpp/v25.1/disable_cpp_editions.patch new file mode 100644 index 000000000..c4a57ab64 --- /dev/null +++ b/plugins/protocolbuffers/cpp/v25.1/disable_cpp_editions.patch @@ -0,0 +1,20 @@ +diff --git a/src/google/protobuf/compiler/cpp/generator.h b/src/google/protobuf/compiler/cpp/generator.h +index 64f334d5b..fd6e08e84 100644 +--- a/src/google/protobuf/compiler/cpp/generator.h ++++ b/src/google/protobuf/compiler/cpp/generator.h +@@ -70,14 +70,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator { + std::string* error) const override; + + uint64_t GetSupportedFeatures() const override { +- return FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS; +- } +- +- Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } +- Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } +- +- std::vector GetFeatureExtensions() const override { +- return {GetExtensionReflection(pb::cpp)}; ++ return FEATURE_PROTO3_OPTIONAL; + } + + private: diff --git a/plugins/protocolbuffers/cpp/v25.2/.dockerignore b/plugins/protocolbuffers/cpp/v25.2/.dockerignore index c80455688..ab1677e27 100644 --- a/plugins/protocolbuffers/cpp/v25.2/.dockerignore +++ b/plugins/protocolbuffers/cpp/v25.2/.dockerignore @@ -1,4 +1,5 @@ * !BUILD !cpp.cc +!disable_cpp_editions.patch !Dockerfile diff --git a/plugins/protocolbuffers/cpp/v25.2/Dockerfile b/plugins/protocolbuffers/cpp/v25.2/Dockerfile index 44d0d37ea..e27383aa1 100644 --- a/plugins/protocolbuffers/cpp/v25.2/Dockerfile +++ b/plugins/protocolbuffers/cpp/v25.2/Dockerfile @@ -1,5 +1,5 @@ -# syntax=docker/dockerfile:1.5 -FROM debian:bookworm-20231218 AS build +# syntax=docker/dockerfile:1.10 +FROM debian:bookworm-20241111 AS build ARG TARGETARCH @@ -16,9 +16,14 @@ RUN curl -fsSL -o protoc.tar.gz https://github.com/protocolbuffers/protobuf/rele && rm protoc.tar.gz RUN bazel build '//:protoc_lib' COPY --link BUILD cpp.cc plugins/ -RUN bazel build '//plugins:protoc-gen-cpp.stripped' +COPY --link disable_cpp_editions.patch . +RUN git apply < disable_cpp_editions.patch \ + && bazel build '//plugins:protoc-gen-cpp.stripped' -FROM gcr.io/distroless/cc-debian12:latest@sha256:6714977f9f02632c31377650c15d89a7efaebf43bab0f37c712c30fc01edb973 -COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . +FROM gcr.io/distroless/cc-debian12:latest@sha256:2fb69596e692931f909c4c69ab09e50608959eaf8898c44fa64db741a23588b0 AS base + +FROM scratch +COPY --link --from=base / / +COPY --link --from=build --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . USER nobody ENTRYPOINT ["/protoc-gen-cpp"] diff --git a/plugins/protocolbuffers/cpp/v25.2/buf.plugin.yaml b/plugins/protocolbuffers/cpp/v25.2/buf.plugin.yaml index 55befc9cb..19031f1a1 100644 --- a/plugins/protocolbuffers/cpp/v25.2/buf.plugin.yaml +++ b/plugins/protocolbuffers/cpp/v25.2/buf.plugin.yaml @@ -7,3 +7,5 @@ output_languages: - cpp spdx_license_id: BSD-3-Clause license_url: https://github.com/protocolbuffers/protobuf/blob/v25.2/LICENSE +registry: + cmake: {} diff --git a/plugins/protocolbuffers/cpp/v25.2/disable_cpp_editions.patch b/plugins/protocolbuffers/cpp/v25.2/disable_cpp_editions.patch new file mode 100644 index 000000000..c4a57ab64 --- /dev/null +++ b/plugins/protocolbuffers/cpp/v25.2/disable_cpp_editions.patch @@ -0,0 +1,20 @@ +diff --git a/src/google/protobuf/compiler/cpp/generator.h b/src/google/protobuf/compiler/cpp/generator.h +index 64f334d5b..fd6e08e84 100644 +--- a/src/google/protobuf/compiler/cpp/generator.h ++++ b/src/google/protobuf/compiler/cpp/generator.h +@@ -70,14 +70,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator { + std::string* error) const override; + + uint64_t GetSupportedFeatures() const override { +- return FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS; +- } +- +- Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } +- Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } +- +- std::vector GetFeatureExtensions() const override { +- return {GetExtensionReflection(pb::cpp)}; ++ return FEATURE_PROTO3_OPTIONAL; + } + + private: diff --git a/plugins/protocolbuffers/cpp/v25.3/Dockerfile b/plugins/protocolbuffers/cpp/v25.3/Dockerfile index 5cbb19ef7..8b6a5fb0d 100644 --- a/plugins/protocolbuffers/cpp/v25.3/Dockerfile +++ b/plugins/protocolbuffers/cpp/v25.3/Dockerfile @@ -1,5 +1,5 @@ -# syntax=docker/dockerfile:1.7 -FROM debian:bookworm-20240211 AS build +# syntax=docker/dockerfile:1.10 +FROM debian:bookworm-20241111 AS build ARG TARGETARCH @@ -20,7 +20,7 @@ COPY --link disable_cpp_editions.patch . RUN git apply < disable_cpp_editions.patch \ && bazel build '//plugins:protoc-gen-cpp.stripped' -FROM gcr.io/distroless/cc-debian12:latest@sha256:e1065a1d58800a7294f74e67c32ec4146d09d6cbe471c1fa7ed456b2d2bf06e0 AS base +FROM gcr.io/distroless/cc-debian12:latest@sha256:2fb69596e692931f909c4c69ab09e50608959eaf8898c44fa64db741a23588b0 AS base FROM scratch COPY --link --from=base / / diff --git a/plugins/protocolbuffers/cpp/v25.3/buf.plugin.yaml b/plugins/protocolbuffers/cpp/v25.3/buf.plugin.yaml index 14a05d57a..0ff9d01e2 100644 --- a/plugins/protocolbuffers/cpp/v25.3/buf.plugin.yaml +++ b/plugins/protocolbuffers/cpp/v25.3/buf.plugin.yaml @@ -7,3 +7,5 @@ output_languages: - cpp spdx_license_id: BSD-3-Clause license_url: https://github.com/protocolbuffers/protobuf/blob/v25.3/LICENSE +registry: + cmake: {} diff --git a/plugins/protocolbuffers/cpp/v26.0/Dockerfile b/plugins/protocolbuffers/cpp/v26.0/Dockerfile index c17fd80f5..6a43b71cb 100644 --- a/plugins/protocolbuffers/cpp/v26.0/Dockerfile +++ b/plugins/protocolbuffers/cpp/v26.0/Dockerfile @@ -1,5 +1,5 @@ -# syntax=docker/dockerfile:1.5 -FROM debian:bookworm-20240311 AS build +# syntax=docker/dockerfile:1.10 +FROM debian:bookworm-20241111 AS build ARG TARGETARCH @@ -18,7 +18,10 @@ RUN bazel build '//:protoc_lib' COPY --link BUILD cpp.cc plugins/ RUN bazel build '//plugins:protoc-gen-cpp.stripped' -FROM gcr.io/distroless/cc-debian12:latest@sha256:e6ae66a5a343d7112167f9117c4e630cfffcd80db44e44302759ec13ddd2d22b -COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . +FROM gcr.io/distroless/cc-debian12:latest@sha256:2fb69596e692931f909c4c69ab09e50608959eaf8898c44fa64db741a23588b0 AS base + +FROM scratch +COPY --link --from=base / / +COPY --link --from=build --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp . USER nobody ENTRYPOINT ["/protoc-gen-cpp"] diff --git a/plugins/protocolbuffers/cpp/v26.0/buf.plugin.yaml b/plugins/protocolbuffers/cpp/v26.0/buf.plugin.yaml index b6a1cc1c2..0aff6b454 100644 --- a/plugins/protocolbuffers/cpp/v26.0/buf.plugin.yaml +++ b/plugins/protocolbuffers/cpp/v26.0/buf.plugin.yaml @@ -7,3 +7,5 @@ output_languages: - cpp spdx_license_id: BSD-3-Clause license_url: https://github.com/protocolbuffers/protobuf/blob/v26.0/LICENSE +registry: + cmake: {}