diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index c7c3f9dd24..4f4de34c01 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -198,7 +198,7 @@ cc_dist_library( "//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/java", - "//src/google/protobuf/compiler/java:kotlin", + "//src/google/protobuf/compiler/kotlin", "//src/google/protobuf/compiler/objectivec", "//src/google/protobuf/compiler/php", "//src/google/protobuf/compiler/python", diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 3777e86ead..0f4c0539cf 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -195,7 +195,7 @@ cc_library( "//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/java", - "//src/google/protobuf/compiler/java:kotlin", + "//src/google/protobuf/compiler/kotlin", "//src/google/protobuf/compiler/objectivec", "//src/google/protobuf/compiler/php", "//src/google/protobuf/compiler/python", diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index 3aca276057..d4ccf53240 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -45,6 +45,7 @@ cc_library( visibility = [ "//pkg:__pkg__", "//src/google/protobuf/compiler/java:__subpackages__", + "//src/google/protobuf/compiler/kotlin:__subpackages__", ], deps = [ "//src/google/protobuf", @@ -116,6 +117,7 @@ cc_library( visibility = [ "//pkg:__pkg__", "//src/google/protobuf/compiler:__pkg__", + "//src/google/protobuf/compiler/kotlin:__subpackages__", ], deps = [ ":generator_common", @@ -182,25 +184,6 @@ cc_library( ], ) -cc_library( - name = "kotlin", - srcs = ["kotlin_generator.cc"], - hdrs = ["kotlin_generator.h"], - strip_include_prefix = "/src", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":helpers", - ":java", - "//src/google/protobuf", - "//src/google/protobuf:port", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/strings", - ], -) - cc_test( name = "doc_comment_unittest", srcs = ["doc_comment_unittest.cc"], diff --git a/src/google/protobuf/compiler/kotlin/BUILD.bazel b/src/google/protobuf/compiler/kotlin/BUILD.bazel new file mode 100644 index 0000000000..82d88a0fbf --- /dev/null +++ b/src/google/protobuf/compiler/kotlin/BUILD.bazel @@ -0,0 +1,19 @@ +cc_library( + name = "kotlin", + srcs = ["generator.cc"], + hdrs = ["generator.h"], + strip_include_prefix = "/src", + visibility = [ + "//pkg:__pkg__", + "//src/google/protobuf/compiler:__pkg__", + ], + deps = [ + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/compiler/java", + "//src/google/protobuf/compiler/java:helpers", + "//src/google/protobuf/io:printer", + "@com_google_absl//absl/strings", + ], +) diff --git a/src/google/protobuf/compiler/kotlin/README.md b/src/google/protobuf/compiler/kotlin/README.md new file mode 100644 index 0000000000..5a1628bb03 --- /dev/null +++ b/src/google/protobuf/compiler/kotlin/README.md @@ -0,0 +1,16 @@ + +# Kotlin DSL Generator + +This code generator implements the Kotlin DSL. The Kotlin DSL sits on top of +another proto implementation (written in Java or Kotlin) and adds convenient +support for building proto messages using DSL syntax, as documented in +[Kotlin Generated Code Guide](https://protobuf.dev/reference/kotlin/kotlin-generated/). + +This code generator is invoked by passing `--kotlin_out` to `protoc`. + +When using Kotlin on the JVM, you will also need to pass `--java_out` to +generate the Java code that implements the generated classes themselves. + +When using Kotlin on other platforms (eg. Kotlin Native), there is currently no +support for generating message classes, so it is not possible to use the Kotlin +DSL at this time. diff --git a/src/google/protobuf/compiler/java/kotlin_generator.cc b/src/google/protobuf/compiler/kotlin/generator.cc similarity index 96% rename from src/google/protobuf/compiler/java/kotlin_generator.cc rename to src/google/protobuf/compiler/kotlin/generator.cc index 9c44c7acf1..54c2018b27 100644 --- a/src/google/protobuf/compiler/java/kotlin_generator.cc +++ b/src/google/protobuf/compiler/kotlin/generator.cc @@ -5,14 +5,20 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "google/protobuf/compiler/java/kotlin_generator.h" +#include "google/protobuf/compiler/kotlin/generator.h" + +#include +#include +#include +#include +#include #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/java/file.h" -#include "google/protobuf/compiler/java/generator.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/kotlin_generator.h b/src/google/protobuf/compiler/kotlin/generator.h similarity index 90% rename from src/google/protobuf/compiler/java/kotlin_generator.h rename to src/google/protobuf/compiler/kotlin/generator.h index a0d36816fb..cb8df6cfca 100644 --- a/src/google/protobuf/compiler/java/kotlin_generator.h +++ b/src/google/protobuf/compiler/kotlin/generator.h @@ -7,10 +7,12 @@ // Generates Kotlin code for a given .proto file. -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ +#ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ +#define GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ +#include #include +#include #include "google/protobuf/compiler/java/java_features.pb.h" #include "google/protobuf/compiler/code_generator.h" @@ -58,4 +60,4 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { #include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ +#endif // GOOGLE_PROTOBUF_COMPILER_KOTLIN_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 6df8ca5bea..8ce7368585 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -10,7 +10,7 @@ #include "google/protobuf/compiler/cpp/generator.h" #include "google/protobuf/compiler/csharp/csharp_generator.h" #include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/compiler/java/kotlin_generator.h" +#include "google/protobuf/compiler/kotlin/generator.h" #include "google/protobuf/compiler/objectivec/generator.h" #include "google/protobuf/compiler/php/php_generator.h" #include "google/protobuf/compiler/python/generator.h"