mirror of
https://github.com/php-win-ext/grpc.git
synced 2026-04-28 03:23:23 +02:00
9b77c0d4df
Fixes the issue with gRPC protobuf plugins declaring the support for `protobuf::Edition::EDITION_2024`, which is higher than the one supported by the protobuf we're using at the moment: `EDITION_2023` at google/protobuf@74211c0dfc. Related: - Effectively undoes #40957 Closes #41357 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/41357 from sergiitk:fix/compiler/protobuf-edition-2023 c3d7b9b27ead199e5e4c66052d4d91d32a7370c6 PiperOrigin-RevId: 853371790
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
/*
|
|
*
|
|
* Copyright 2015 gRPC authors.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
// Generates Ruby gRPC service interface out of Protobuf IDL.
|
|
|
|
#include <memory>
|
|
|
|
#include "src/compiler/config.h"
|
|
#include "src/compiler/ruby_generator.h"
|
|
#include "src/compiler/ruby_generator_helpers-inl.h"
|
|
|
|
class RubyGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
|
|
public:
|
|
RubyGrpcGenerator() {}
|
|
~RubyGrpcGenerator() {}
|
|
|
|
uint64_t GetSupportedFeatures() const override {
|
|
return FEATURE_PROTO3_OPTIONAL
|
|
#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
|
|
| FEATURE_SUPPORTS_EDITIONS
|
|
#endif
|
|
;
|
|
}
|
|
|
|
#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
|
|
grpc::protobuf::Edition GetMinimumEdition() const override {
|
|
return grpc::protobuf::Edition::EDITION_PROTO2;
|
|
}
|
|
grpc::protobuf::Edition GetMaximumEdition() const override {
|
|
// TODO(yuanweiz): Remove when the protobuf is updated to a version
|
|
// that supports edition 2024.
|
|
#if !defined(GOOGLE_PROTOBUF_VERSION) || GOOGLE_PROTOBUF_VERSION >= 6032000
|
|
return grpc::protobuf::Edition::EDITION_2024;
|
|
#else
|
|
return grpc::protobuf::Edition::EDITION_2023;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
bool Generate(const grpc::protobuf::FileDescriptor* file,
|
|
const std::string& /*parameter*/,
|
|
grpc::protobuf::compiler::GeneratorContext* context,
|
|
std::string* /*error*/) const override {
|
|
std::string code = grpc_ruby_generator::GetServices(file);
|
|
if (code.size() == 0) {
|
|
return true; // don't generate a file if there are no services
|
|
}
|
|
|
|
// Get output file name.
|
|
std::string file_name;
|
|
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
|
|
return false;
|
|
}
|
|
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
|
|
context->Open(file_name));
|
|
grpc::protobuf::io::CodedOutputStream coded_out(output.get());
|
|
coded_out.WriteRaw(code.data(), code.size());
|
|
return true;
|
|
}
|
|
};
|
|
|
|
int main(int argc, char* argv[]) {
|
|
RubyGrpcGenerator generator;
|
|
return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
|
|
}
|