Skip to content

Commit 3561b05

Browse files
authored
Merge pull request #1 from protocolbuffers/plugin-binary
Made the JS generator into a plugin that builds into a binary.
2 parents 9959ab7 + d0cca7f commit 3561b05

File tree

9 files changed

+75
-3
lines changed

9 files changed

+75
-3
lines changed

BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Protobuf JS runtime
22
#
3-
# See also code generation logic under /src/google/protobuf/compiler/js.
3+
# See also code generation logic under compiler/
44

55
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
66

WORKSPACE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
workspace(name = "com_google_protobuf_javascript")
3+
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
6+
http_archive(
7+
name = "com_google_protobuf",
8+
urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.20.1.zip"],
9+
strip_prefix = "protobuf-3.20.1",
10+
)
11+
12+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
13+
protobuf_deps()

generator/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
cc_binary(
3+
name = "protoc-gen-js",
4+
srcs = [
5+
"protoc-gen-js.cc",
6+
"js_generator.cc",
7+
"js_generator.h",
8+
"well_known_types_embed.cc",
9+
"well_known_types_embed.h",
10+
],
11+
deps = [
12+
#"@com_google_absl//absl/base:core_headers",
13+
#"@com_google_absl//absl/container:flat_hash_map",
14+
#"@com_google_absl//absl/container:flat_hash_set",
15+
#"@com_google_absl//absl/strings",
16+
"@com_google_protobuf//:protobuf",
17+
"@com_google_protobuf//:protoc_lib",
18+
],
19+
)

src/google/protobuf/compiler/js/js_generator.cc renamed to generator/js_generator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131
#include <assert.h>
32-
#include <google/protobuf/compiler/js/js_generator.h>
3332
#include <google/protobuf/compiler/js/well_known_types_embed.h>
3433
#include <google/protobuf/compiler/scc.h>
3534
#include <google/protobuf/descriptor.h>
@@ -49,6 +48,8 @@
4948
#include <utility>
5049
#include <vector>
5150

51+
#include "generator/js_generator.h"
52+
5253
namespace google {
5354
namespace protobuf {
5455
namespace compiler {

generator/protoc-gen-js.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Protocol Buffers - Google's data interchange format
2+
// Copyright 2008 Google Inc. All rights reserved.
3+
// https://developers.google.com/protocol-buffers/
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
// * Redistributions in binary form must reproduce the above
12+
// copyright notice, this list of conditions and the following disclaimer
13+
// in the documentation and/or other materials provided with the
14+
// distribution.
15+
// * Neither the name of Google Inc. nor the names of its
16+
// contributors may be used to endorse or promote products derived from
17+
// this software without specific prior written permission.
18+
//
19+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
#include <google/protobuf/compiler/plugin.h>
32+
33+
#include "generator/js_generator.h"
34+
35+
int main(int argc, char** argv) {
36+
std::unique_ptr<google::protobuf::compiler::CodeGenerator> generator(
37+
new google::protobuf::compiler::js::Generator());
38+
return google::protobuf::compiler::PluginMain(argc, argv, generator.get());
39+
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function exec(command, cb) {
66
execFile('sh', ['-c', command], cb);
77
}
88

9-
var protoc = process.env.PROTOC || '../src/protoc';
9+
var protoc = process.env.PROTOC || 'bazel-bin/external/com_google_protobuf/protoc --plugin=protoc-gen-js=bazel-bin/generator/protoc-gen-js';
1010

1111
var wellKnownTypes = [
1212
'../src/google/protobuf/any.proto',

0 commit comments

Comments
 (0)