Made the JS generator into a plugin that builds into a binary.
diff --git a/BUILD b/BUILD index baa93be..ea37196 100644 --- a/BUILD +++ b/BUILD
@@ -1,6 +1,6 @@ # Protobuf JS runtime # -# See also code generation logic under /src/google/protobuf/compiler/js. +# See also code generation logic under compiler/ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..375671f --- /dev/null +++ b/WORKSPACE
@@ -0,0 +1,13 @@ + +workspace(name = "com_google_protobuf_javascript") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "com_google_protobuf", + urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.20.1.zip"], + strip_prefix = "protobuf-3.20.1", +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") +protobuf_deps()
diff --git a/generator/BUILD b/generator/BUILD new file mode 100644 index 0000000..18b6869 --- /dev/null +++ b/generator/BUILD
@@ -0,0 +1,19 @@ + +cc_binary( + name = "protoc-gen-js", + srcs = [ + "protoc-gen-js.cc", + "js_generator.cc", + "js_generator.h", + "well_known_types_embed.cc", + "well_known_types_embed.h", + ], + deps = [ + #"@com_google_absl//absl/base:core_headers", + #"@com_google_absl//absl/container:flat_hash_map", + #"@com_google_absl//absl/container:flat_hash_set", + #"@com_google_absl//absl/strings", + "@com_google_protobuf//:protobuf", + "@com_google_protobuf//:protoc_lib", + ], +)
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/generator/js_generator.cc similarity index 99% rename from src/google/protobuf/compiler/js/js_generator.cc rename to generator/js_generator.cc index 8c20b79..eb8aa73 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/generator/js_generator.cc
@@ -29,7 +29,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <assert.h> -#include <google/protobuf/compiler/js/js_generator.h> #include <google/protobuf/compiler/js/well_known_types_embed.h> #include <google/protobuf/compiler/scc.h> #include <google/protobuf/descriptor.h> @@ -49,6 +48,8 @@ #include <utility> #include <vector> +#include "generator/js_generator.h" + namespace google { namespace protobuf { namespace compiler {
diff --git a/src/google/protobuf/compiler/js/js_generator.h b/generator/js_generator.h similarity index 100% rename from src/google/protobuf/compiler/js/js_generator.h rename to generator/js_generator.h
diff --git a/generator/protoc-gen-js.cc b/generator/protoc-gen-js.cc new file mode 100644 index 0000000..4529fdc --- /dev/null +++ b/generator/protoc-gen-js.cc
@@ -0,0 +1,39 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <google/protobuf/compiler/plugin.h> + +#include "generator/js_generator.h" + +int main(int argc, char** argv) { + std::unique_ptr<google::protobuf::compiler::CodeGenerator> generator( + new google::protobuf::compiler::js::Generator()); + return google::protobuf::compiler::PluginMain(argc, argv, generator.get()); +}
diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.cc b/generator/well_known_types_embed.cc similarity index 100% rename from src/google/protobuf/compiler/js/well_known_types_embed.cc rename to generator/well_known_types_embed.cc
diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.h b/generator/well_known_types_embed.h similarity index 100% rename from src/google/protobuf/compiler/js/well_known_types_embed.h rename to generator/well_known_types_embed.h
diff --git a/gulpfile.js b/gulpfile.js index 00a6d64..1c9fba5 100644 --- a/gulpfile.js +++ b/gulpfile.js
@@ -6,7 +6,7 @@ execFile('sh', ['-c', command], cb); } -var protoc = process.env.PROTOC || '../src/protoc'; +var protoc = process.env.PROTOC || 'bazel-bin/external/com_google_protobuf/protoc --plugin=protoc-gen-js=bazel-bin/generator/protoc-gen-js'; var wellKnownTypes = [ '../src/google/protobuf/any.proto',