Skip to content

Commit 9e2eee1

Browse files
authored
Enable bzlmod by default (#12)
Fixes compilation using bzlmod and makes bzlmod the default.
1 parent 54910de commit 9e2eee1

File tree

6 files changed

+139
-14
lines changed

6 files changed

+139
-14
lines changed

.bazelrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
2-
# https://github.com/protocolbuffers/protobuf/issues/14313
3-
common --noenable_bzlmod
1+
common --enable_bzlmod

BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pkg_files(
2121
name = "dist_files",
2222
srcs = glob([
2323
"google/protobuf/*.js",
24-
"google/protobuf/compiler/*.js"
24+
"google/protobuf/compiler/*.js",
2525
]) + [
2626
"google-protobuf.js",
2727
"package.json",
@@ -58,5 +58,5 @@ filegroup(
5858
srcs = [
5959
":dist_tar",
6060
":dist_zip",
61-
]
61+
],
6262
)

MODULE.bazel

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
module(name = "protobuf_javascript_gonzojive", version = "3.21.5")
1+
module(
2+
name = "protobuf_javascript_gonzojive",
3+
version = "3.21.5",
4+
)
25

3-
bazel_dep(name = "protobuf", version = "27.1", repo_name = "com_google_protobuf")
6+
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
7+
bazel_dep(name = "abseil-cpp", version = "20211102.0")
48
bazel_dep(name = "rules_pkg", version = "0.7.0")
9+
10+
# For VS Code autocompletion:
11+
# https://github.com/hedronvision/bazel-compile-commands-extractor#usage
12+
#
13+
# Not currently working due to https://github.com/hedronvision/bazel-compile-commands-extractor/issues/199
14+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
15+
git_override(
16+
module_name = "hedron_compile_commands",
17+
commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97",
18+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
19+
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
20+
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
21+
)

MODULE.bazel.lock

+110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ cc_binary(
99
],
1010
visibility = ["//visibility:public"],
1111
deps = [
12+
"@abseil-cpp//absl/strings:str_format",
1213
"@com_google_protobuf//:protobuf",
1314
"@com_google_protobuf//:protoc_lib",
1415
],
1516
)
16-

generator/js_generator.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <google/protobuf/io/zero_copy_stream.h>
3838
#include <google/protobuf/stubs/common.h>
3939
#include <google/protobuf/stubs/logging.h>
40-
#include <google/protobuf/stubs/stringprintf.h>
40+
#include "absl/strings/str_format.h"
4141
#include <google/protobuf/stubs/strutil.h>
4242

4343
#include <algorithm>
@@ -679,9 +679,9 @@ bool EscapeJSString(const std::string& in, std::string* out) {
679679
if (codepoint >= 0x20 && codepoint <= 0x7e) {
680680
*out += static_cast<char>(codepoint);
681681
} else if (codepoint >= 0x100) {
682-
*out += StringPrintf("\\u%04x", codepoint);
682+
*out += absl::StrFormat("\\u%04x", codepoint);
683683
} else {
684-
*out += StringPrintf("\\x%02x", codepoint);
684+
*out += absl::StrFormat("\\x%02x", codepoint);
685685
}
686686
break;
687687
}
@@ -1276,7 +1276,7 @@ std::string FieldDefinition(const GeneratorOptions& options,
12761276
} else {
12771277
value_type = ProtoTypeName(options, value_field);
12781278
}
1279-
return StringPrintf("map<%s, %s> %s = %d;", key_type.c_str(),
1279+
return absl::StrFormat("map<%s, %s> %s = %d;", key_type.c_str(),
12801280
value_type.c_str(), field->name().c_str(),
12811281
field->number());
12821282
} else {
@@ -1295,7 +1295,7 @@ std::string FieldDefinition(const GeneratorOptions& options,
12951295
type = ProtoTypeName(options, field);
12961296
name = field->name();
12971297
}
1298-
return StringPrintf("%s %s %s = %d;", qualifier.c_str(), type.c_str(),
1298+
return absl::StrFormat("%s %s %s = %d;", qualifier.c_str(), type.c_str(),
12991299
name.c_str(), field->number());
13001300
}
13011301
}
@@ -3676,7 +3676,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
36763676
" * @type {!jspb.ExtensionFieldInfo<$extensionType$>}\n"
36773677
" */\n"
36783678
"$class$.$name$ = new jspb.ExtensionFieldInfo(\n",
3679-
"class", extension_scope_name, "name", extension_object_field_name, "extensionType",
3679+
"class", extension_scope_name, "name", extension_object_field_name, "extensionType",
36803680
JSFieldTypeAnnotation(options, field,
36813681
/* is_setter_argument = */ false,
36823682
/* force_present = */ true,

0 commit comments

Comments
 (0)