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

Made the JS generator into a plugin that builds into a binary. #1

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
13 changes: 13 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions generator/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -49,6 +48,8 @@
#include <utility>
#include <vector>

#include "generator/js_generator.h"

namespace google {
namespace protobuf {
namespace compiler {
Expand Down
File renamed without changes.
39 changes: 39 additions & 0 deletions generator/protoc-gen-js.cc
Original file line number Diff line number Diff line change
@@ -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());
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function exec(command, cb) {
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',
Expand Down