Skip to content

Commit 5f41cae

Browse files
authored
Merge pull request #229 from dibenede/update-protobuf
Update to protobuf 30.1 and drop bazel workspace configuration
2 parents 426b2e0 + eb785a9 commit 5f41cae

File tree

11 files changed

+3757
-157
lines changed

11 files changed

+3757
-157
lines changed

Diff for: .bazelrc

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1
2323
# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748
2424
build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
2525

26-
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
27-
# https://github.com/protocolbuffers/protobuf/issues/14313
28-
common --noenable_bzlmod
29-
3026
# Important: this flag ensures that we remain compliant with the C++ layering
3127
# check.
3228
build --features=layering_check

Diff for: .github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permissions: read-all
66

77
# update in build.yml and codeql.yml at same time
88
env:
9-
PROTOC_VERSION: 28.1
9+
PROTOC_VERSION: 30.1
1010

1111
jobs:
1212
build:

Diff for: .github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ permissions: read-all
1515

1616
# update in build.yml and codeql.yml at same time
1717
env:
18-
PROTOC_VERSION: 28.1
18+
PROTOC_VERSION: 30.1
1919

2020
on:
2121
push:

Diff for: .github/workflows/scorecards.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
# Needs for private repositories.
2323
contents: read
2424
actions: read
25-
25+
2626
steps:
2727
- name: "Checkout code"
2828
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0
@@ -41,8 +41,8 @@ jobs:
4141
# repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
4242

4343
# Publish the results for public repositories to enable scorecard badges. For more details, see
44-
# https://github.com/ossf/scorecard-action#publishing-results.
45-
# For private repositories, `publish_results` will automatically be set to `false`, regardless
44+
# https://github.com/ossf/scorecard-action#publishing-results.
45+
# For private repositories, `publish_results` will automatically be set to `false`, regardless
4646
# of the value entered here.
4747
publish_results: true
4848

@@ -54,7 +54,7 @@ jobs:
5454
name: SARIF file
5555
path: results.sarif
5656
retention-days: 5
57-
57+
5858
# Upload the results to GitHub's code scanning dashboard.
5959
- name: "Upload to code-scanning"
6060
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26

Diff for: MODULE.bazel

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module(name = "protobuf_javascript", version = "3.21.4")
22

3-
bazel_dep(name = "protobuf", version = "27.1", repo_name = "com_google_protobuf")
4-
bazel_dep(name = "rules_pkg", version = "0.7.0")
3+
bazel_dep(name = "protobuf", version = "30.1", repo_name = "com_google_protobuf")
4+
bazel_dep(name = "rules_pkg", version = "1.0.1")
5+
bazel_dep(name = "abseil-cpp", version = "20250127.0")

Diff for: MODULE.bazel.lock

+3,677-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: WORKSPACE

-30
This file was deleted.

Diff for: WORKSPACE.bzlmod

-2
This file was deleted.

Diff for: generator/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ cc_binary(
1515
"@com_google_protobuf//src/google/protobuf/io:printer",
1616
"@com_google_protobuf//src/google/protobuf/io:tokenizer",
1717
"@com_google_protobuf//:protoc_lib",
18-
"@com_google_absl//absl/strings",
19-
"@com_google_absl//absl/strings:str_format",
18+
"@abseil-cpp//absl/strings",
19+
"@abseil-cpp//absl/strings:str_format",
2020
],
2121
)
2222

Diff for: generator/js_generator.cc

+27-28
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum BytesMode {
8989
BYTES_U8, // Explicitly coerce to Uint8Array where needed.
9090
};
9191

92-
bool IsReserved(const std::string& ident) {
92+
bool IsReserved(absl::string_view ident) {
9393
for (int i = 0; i < kNumKeyword; i++) {
9494
if (ident == kKeyword[i]) {
9595
return true;
@@ -98,9 +98,8 @@ bool IsReserved(const std::string& ident) {
9898
return false;
9999
}
100100

101-
std::string GetSnakeFilename(const std::string& filename) {
102-
std::string snake_name = filename;
103-
return absl::StrReplaceAll(snake_name, {{"/", "_"}});
101+
std::string GetSnakeFilename(absl::string_view filename) {
102+
return absl::StrReplaceAll(filename, {{"/", "_"}});
104103
}
105104

106105
// Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript
@@ -135,7 +134,7 @@ std::string GetRootPath(const std::string& from_filename,
135134

136135
// Returns the alias we assign to the module of the given .proto filename
137136
// when importing.
138-
std::string ModuleAlias(const std::string& filename) {
137+
std::string ModuleAlias(absl::string_view filename) {
139138
// This scheme could technically cause problems if a file includes any 2 of:
140139
// foo/bar_baz.proto
141140
// foo_bar_baz.proto
@@ -157,7 +156,7 @@ std::string GetNamespace(const GeneratorOptions& options,
157156
if (!options.namespace_prefix.empty()) {
158157
return options.namespace_prefix;
159158
} else if (!file->package().empty()) {
160-
return "proto." + file->package();
159+
return absl::StrCat("proto.", file->package());
161160
} else {
162161
return "proto";
163162
}
@@ -204,7 +203,7 @@ std::string GetMessagePathPrefix(const GeneratorOptions& options,
204203
// message descriptor.
205204
std::string GetMessagePath(const GeneratorOptions& options,
206205
const Descriptor* descriptor) {
207-
return GetMessagePathPrefix(options, descriptor) + descriptor->name();
206+
return absl::StrCat(GetMessagePathPrefix(options, descriptor), descriptor->name());
208207
}
209208

210209
// Returns the fully normalized JavaScript path prefix for the given
@@ -219,7 +218,7 @@ std::string GetEnumPathPrefix(const GeneratorOptions& options,
219218
// enumeration descriptor.
220219
std::string GetEnumPath(const GeneratorOptions& options,
221220
const EnumDescriptor* enum_descriptor) {
222-
return GetEnumPathPrefix(options, enum_descriptor) + enum_descriptor->name();
221+
return absl::StrCat(GetEnumPathPrefix(options, enum_descriptor), enum_descriptor->name());
223222
}
224223

225224
std::string MaybeCrossFileRef(const GeneratorOptions& options,
@@ -230,9 +229,9 @@ std::string MaybeCrossFileRef(const GeneratorOptions& options,
230229
from_file != to_message->file()) {
231230
// Cross-file ref in CommonJS needs to use the module alias instead of
232231
// the global name.
233-
return ModuleAlias(to_message->file()->name()) +
234-
GetNestedMessageName(to_message->containing_type()) + "." +
235-
to_message->name();
232+
return absl::StrCat(ModuleAlias(to_message->file()->name()),
233+
GetNestedMessageName(to_message->containing_type()), ".",
234+
to_message->name());
236235
} else {
237236
// Within a single file we use a full name.
238237
return GetMessagePath(options, to_message);
@@ -262,7 +261,7 @@ char ToLowerASCII(char c) {
262261
}
263262
}
264263

265-
std::vector<std::string> ParseLowerUnderscore(const std::string& input) {
264+
std::vector<std::string> ParseLowerUnderscore(absl::string_view input) {
266265
std::vector<std::string> words;
267266
std::string running = "";
268267
for (auto c : input) {
@@ -281,7 +280,7 @@ std::vector<std::string> ParseLowerUnderscore(const std::string& input) {
281280
return words;
282281
}
283282

284-
std::vector<std::string> ParseUpperCamel(const std::string& input) {
283+
std::vector<std::string> ParseUpperCamel(absl::string_view input) {
285284
std::vector<std::string> words;
286285
std::string running = "";
287286
for (auto c : input) {
@@ -326,7 +325,7 @@ std::string ToUpperCamel(const std::vector<std::string>& words) {
326325
// Based on code from descriptor.cc (Thanks Kenton!)
327326
// Uppercases the entire string, turning ValueName into
328327
// VALUENAME.
329-
std::string ToEnumCase(const std::string& input) {
328+
std::string ToEnumCase(absl::string_view input) {
330329
std::string result;
331330
result.reserve(input.size());
332331

@@ -341,7 +340,7 @@ std::string ToEnumCase(const std::string& input) {
341340
return result;
342341
}
343342

344-
std::string ToLower(const std::string& input) {
343+
std::string ToLower(absl::string_view input) {
345344
std::string result;
346345
result.reserve(input.size());
347346

@@ -625,7 +624,7 @@ uint16_t DecodeUTF8Codepoint(uint8_t* bytes, size_t* length) {
625624
// Returns false if |out| was truncated because |in| contained invalid UTF-8 or
626625
// codepoints outside the BMP.
627626
// TODO(b/115551870): Support codepoints outside the BMP.
628-
bool EscapeJSString(const std::string& in, std::string* out) {
627+
bool EscapeJSString(absl::string_view in, std::string* out) {
629628
size_t decoded = 0;
630629
for (size_t i = 0; i < in.size(); i += decoded) {
631630
uint16_t codepoint = 0;
@@ -697,7 +696,7 @@ bool EscapeJSString(const std::string& in, std::string* out) {
697696
return true;
698697
}
699698

700-
std::string EscapeBase64(const std::string& in) {
699+
std::string EscapeBase64(absl::string_view in) {
701700
static const char* kAlphabet =
702701
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
703702
std::string result;
@@ -1074,7 +1073,7 @@ std::string JSFieldTypeAnnotation(const GeneratorOptions& options,
10741073
}
10751074

10761075
std::string JSBinaryMethodType(const FieldDescriptor* field, bool is_writer) {
1077-
std::string name = field->type_name();
1076+
std::string name = std::string(field->type_name());
10781077
if (name[0] >= 'a' && name[0] <= 'z') {
10791078
name[0] = (name[0] - 'a') + 'A';
10801079
}
@@ -1226,9 +1225,9 @@ std::string RelativeTypeName(const FieldDescriptor* field) {
12261225
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE);
12271226
// For a field with an enum or message type, compute a name relative to the
12281227
// path name of the message type containing this field.
1229-
std::string package = field->file()->package();
1230-
std::string containing_type = field->containing_type()->full_name() + ".";
1231-
std::string type = (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM)
1228+
absl::string_view package = field->file()->package();
1229+
std::string containing_type = absl::StrCat(field->containing_type()->full_name(), ".");
1230+
absl::string_view type = (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM)
12321231
? field->enum_type()->full_name()
12331232
: field->message_type()->full_name();
12341233

@@ -1245,7 +1244,7 @@ std::string RelativeTypeName(const FieldDescriptor* field) {
12451244
}
12461245
}
12471246

1248-
return type.substr(prefix);
1247+
return std::string(type).substr(prefix);
12491248
}
12501249

12511250
std::string JSExtensionsObjectName(const GeneratorOptions& options,
@@ -1285,8 +1284,8 @@ std::string FieldDefinition(const GeneratorOptions& options,
12851284
} else {
12861285
value_type = ProtoTypeName(options, value_field);
12871286
}
1288-
return absl::StrFormat("map<%s, %s> %s = %d;", key_type.c_str(),
1289-
value_type.c_str(), field->name().c_str(),
1287+
return absl::StrFormat("map<%s, %s> %s = %d;", key_type,
1288+
value_type, field->name(),
12901289
field->number());
12911290
} else {
12921291
std::string qualifier =
@@ -3588,8 +3587,8 @@ bool Generator::GenerateFile(const FileDescriptor* file,
35883587
std::string filename =
35893588
options.output_dir + "/" +
35903589
GetJSFilename(options, use_short_name
3591-
? file->name().substr(file->name().rfind('/'))
3592-
: file->name());
3590+
? std::string(file->name().substr(file->name().rfind('/')))
3591+
: std::string(file->name()));
35933592
std::unique_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
35943593
ABSL_CHECK(output);
35953594
GeneratedCodeInfo annotations;
@@ -3649,12 +3648,12 @@ void Generator::GenerateFile(const GeneratorOptions& options,
36493648
}
36503649

36513650
for (int i = 0; i < file->dependency_count(); i++) {
3652-
const std::string& name = file->dependency(i)->name();
3651+
const std::string name = std::string(file->dependency(i)->name());
36533652
printer->Print(
36543653
"var $alias$ = require('$file$');\n"
36553654
"goog.object.extend(proto, $alias$);\n",
36563655
"alias", ModuleAlias(name), "file",
3657-
GetRootPath(file->name(), name) + GetJSFilename(options, name));
3656+
GetRootPath(std::string(file->name()), name) + GetJSFilename(options, name));
36583657
}
36593658
}
36603659

0 commit comments

Comments
 (0)