Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmake support to protocolbuffers/cpp plugins to v25 #1577

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/protocolbuffers/cpp/v25.0/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!BUILD
!cpp.cc
!disable_cpp_editions.patch
!Dockerfile
4 changes: 3 additions & 1 deletion plugins/protocolbuffers/cpp/v25.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ 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 .
Expand Down
2 changes: 2 additions & 0 deletions plugins/protocolbuffers/cpp/v25.0/buf.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
20 changes: 20 additions & 0 deletions plugins/protocolbuffers/cpp/v25.0/disable_cpp_editions.patch
Original file line number Diff line number Diff line change
@@ -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<const FieldDescriptor*> GetFeatureExtensions() const override {
- return {GetExtensionReflection(pb::cpp)};
+ return FEATURE_PROTO3_OPTIONAL;
}

private:
1 change: 1 addition & 0 deletions plugins/protocolbuffers/cpp/v25.1/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!BUILD
!cpp.cc
!disable_cpp_editions.patch
!Dockerfile
4 changes: 3 additions & 1 deletion plugins/protocolbuffers/cpp/v25.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ 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'
Copy link
Member

@pkwarren pkwarren Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're updating this plugin lets merge the latest changes from 25.3 or 28.3 into here (including changing base images to bookworm/debian12, updating base images to latest, and reducing image layers).


FROM gcr.io/distroless/cc-debian11
COPY --from=build --link --chmod=0755 /build/bazel-bin/plugins/protoc-gen-cpp .
Expand Down
2 changes: 2 additions & 0 deletions plugins/protocolbuffers/cpp/v25.1/buf.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
20 changes: 20 additions & 0 deletions plugins/protocolbuffers/cpp/v25.1/disable_cpp_editions.patch
Original file line number Diff line number Diff line change
@@ -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<const FieldDescriptor*> GetFeatureExtensions() const override {
- return {GetExtensionReflection(pb::cpp)};
+ return FEATURE_PROTO3_OPTIONAL;
}

private:
1 change: 1 addition & 0 deletions plugins/protocolbuffers/cpp/v25.2/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!BUILD
!cpp.cc
!disable_cpp_editions.patch
!Dockerfile
11 changes: 8 additions & 3 deletions plugins/protocolbuffers/cpp/v25.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:6714977f9f02632c31377650c15d89a7efaebf43bab0f37c712c30fc01edb973 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"]
2 changes: 2 additions & 0 deletions plugins/protocolbuffers/cpp/v25.2/buf.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
20 changes: 20 additions & 0 deletions plugins/protocolbuffers/cpp/v25.2/disable_cpp_editions.patch
Original file line number Diff line number Diff line change
@@ -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<const FieldDescriptor*> GetFeatureExtensions() const override {
- return {GetExtensionReflection(pb::cpp)};
+ return FEATURE_PROTO3_OPTIONAL;
}

private:
2 changes: 2 additions & 0 deletions plugins/protocolbuffers/cpp/v25.3/buf.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
7 changes: 5 additions & 2 deletions plugins/protocolbuffers/cpp/v26.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:e6ae66a5a343d7112167f9117c4e630cfffcd80db44e44302759ec13ddd2d22b AS base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bump to the latest version from .github/docker/Dockerfile.distroless-cc-debian here (this is what our plugin fetcher uses to keep base images updated).


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"]
2 changes: 2 additions & 0 deletions plugins/protocolbuffers/cpp/v26.0/buf.plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}