A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/1b4b5fc1ff28bf642b51008a413c2a65046b2aa1 below:

Update Rust generator to output minidescriptors instead of C minitables · protocolbuffers/protobuf@1b4b5fc · GitHub

File tree Expand file treeCollapse file tree 26 files changed

+462

-99

lines changed

Filter options

Expand file treeCollapse file tree 26 files changed

+462

-99

lines changed Original file line number Diff line number Diff line change

@@ -7,7 +7,6 @@ load("@rules_rust//rust/private:providers.bzl", "CrateInfo", "DepInfo", "DepVari

7 7 8 8

# buildifier: disable=bzl-visibility

9 9

load("@rules_rust//rust/private:rustc.bzl", "rustc_compile_action")

10 -

load("//bazel:upb_minitable_proto_library.bzl", "UpbMinitableCcInfo", "upb_minitable_proto_library_aspect")

11 10

load("//bazel/common:proto_common.bzl", "proto_common")

12 11

load("//bazel/common:proto_info.bzl", "ProtoInfo")

13 12

load("//bazel/private:cc_proto_aspect.bzl", "cc_proto_aspect")

@@ -347,9 +346,8 @@ def _rust_proto_aspect_common(target, ctx, is_upb):

347 346

is_upb,

348 347

)

349 348 350 -

if is_upb:

351 -

thunks_cc_info = target[UpbMinitableCcInfo].cc_info

352 -

else:

349 +

dep_variant_info_for_native_gencode = []

350 +

if not is_upb:

353 351

dep_cc_infos = []

354 352

for dep in proto_deps:

355 353

dep_cc_infos.append(dep[CcInfo])

@@ -363,6 +361,8 @@ def _rust_proto_aspect_common(target, ctx, is_upb):

363 361

cc_infos = [target[CcInfo]] + [dep[CcInfo] for dep in ctx.attr._cpp_thunks_deps] + dep_cc_infos,

364 362

) for thunk in cc_thunks_gencode])

365 363 364 +

dep_variant_info_for_native_gencode = [DepVariantInfo(cc_info = thunks_cc_info)]

365 + 366 366

runtime = proto_lang_toolchain.runtime

367 367

dep_variant_info_for_runtime = DepVariantInfo(

368 368

crate_info = runtime[CrateInfo] if CrateInfo in runtime else None,

@@ -371,14 +371,12 @@ def _rust_proto_aspect_common(target, ctx, is_upb):

371 371

build_info = None,

372 372

)

373 373 374 -

dep_variant_info_for_native_gencode = DepVariantInfo(cc_info = thunks_cc_info)

375 - 376 374

dep_variant_info = _compile_rust(

377 375

ctx = ctx,

378 376

attr = ctx.rule.attr,

379 377

src = entry_point_rs_output,

380 378

extra_srcs = rs_gencode,

381 -

deps = [dep_variant_info_for_runtime, dep_variant_info_for_native_gencode] + dep_variant_infos,

379 +

deps = [dep_variant_info_for_runtime] + dep_variant_info_for_native_gencode + dep_variant_infos,

382 380

runtime = runtime,

383 381

)

384 382

return [RustProtoInfo(

@@ -396,7 +394,7 @@ def _make_proto_library_aspect(is_upb):

396 394

return aspect(

397 395

implementation = (_rust_upb_proto_aspect_impl if is_upb else _rust_cc_proto_aspect_impl),

398 396

attr_aspects = ["deps"],

399 -

requires = ([upb_minitable_proto_library_aspect] if is_upb else [cc_proto_aspect]),

397 +

requires = ([] if is_upb else [cc_proto_aspect]),

400 398

attrs = {

401 399

"_collect_cc_coverage": attr.label(

402 400

default = Label("@rules_rust//util:collect_coverage"),

Original file line number Diff line number Diff line change

@@ -116,10 +116,6 @@ def _rust_upb_aspect_test_impl(ctx):

116 116

# The action needs to produce a .rlib artifact (sometimes .rmeta as well, not tested here).

117 117

asserts.true(env, rustc_action.outputs.to_list()[0].path.endswith(".rlib"))

118 118 119 -

# The aspect needs to provide CcInfo that passes UPB gencode to the eventual linking.

120 -

_find_linker_input(target_under_test[RustProtoInfo], "child.upb_minitable")

121 -

_find_linker_input(target_under_test[RustProtoInfo], "parent.upb_minitable")

122 - 123 119

return analysistest.end(env)

124 120 125 121

rust_upb_aspect_test = analysistest.make(_rust_upb_aspect_test_impl)

Original file line number Diff line number Diff line change

@@ -320,6 +320,7 @@ rust_test(

320 320

},

321 321

deps = [

322 322

"//rust:protobuf_cpp_export",

323 +

"//rust/test:map_unittest_cpp_rust_proto",

323 324

"//rust/test:nested_cpp_rust_proto",

324 325

"@crate_index//:googletest",

325 326

],

@@ -333,6 +334,7 @@ rust_test(

333 334

},

334 335

deps = [

335 336

"//rust:protobuf_upb_export",

337 +

"//rust/test:map_unittest_upb_rust_proto",

336 338

"//rust/test:nested_upb_rust_proto",

337 339

"@crate_index//:googletest",

338 340

],

Original file line number Diff line number Diff line change

@@ -6,9 +6,11 @@

6 6

// https://developers.google.com/open-source/licenses/bsd

7 7 8 8

use googletest::prelude::*;

9 +

use map_unittest_rust_proto::TestRecursiveMapMessage;

9 10

use nested_rust_proto::outer::inner::InnerEnum;

10 11

use nested_rust_proto::outer::InnerView;

11 12

use nested_rust_proto::*;

13 +

use protobuf::prelude::*;

12 14 13 15

#[gtest]

14 16

fn test_deeply_nested_message() {

@@ -120,3 +122,12 @@ fn test_recursive_mut() {

120 122

// let nested = rec.rec_mut().rec_mut().rec_mut();

121 123

// assert_that!(nested.num(), eq(0));

122 124

}

125 + 126 +

#[gtest]

127 +

fn test_recursive_map() {

128 +

let mut m1 = TestRecursiveMapMessage::new();

129 +

m1.a_mut().insert("k", TestRecursiveMapMessage::new());

130 +

let m2 = TestRecursiveMapMessage::parse(&m1.serialize().unwrap()).unwrap();

131 +

assert_that!(m2.a().len(), eq(1));

132 +

expect_that!(m2.a().get("k"), not(none()));

133 +

}

Original file line number Diff line number Diff line change

@@ -49,3 +49,16 @@ rust_test(

49 49

"@crate_index//:googletest",

50 50

],

51 51

)

52 + 53 +

rust_test(

54 +

name = "thread_local_arena_test",

55 +

srcs = ["thread_local_arena_test.rs"],

56 +

aliases = {

57 +

"//rust:protobuf_upb_export": "protobuf",

58 +

},

59 +

deps = [

60 +

"//rust:protobuf_upb_export",

61 +

"//rust/test:unittest_upb_rust_proto",

62 +

"@crate_index//:googletest",

63 +

],

64 +

)

Original file line number Diff line number Diff line change

@@ -0,0 +1,27 @@

1 +

// Protocol Buffers - Google's data interchange format

2 +

// Copyright 2024 Google LLC. All rights reserved.

3 +

//

4 +

// Use of this source code is governed by a BSD-style

5 +

// license that can be found in the LICENSE file or at

6 +

// https://developers.google.com/open-source/licenses/bsd

7 + 8 +

use googletest::prelude::*;

9 +

use protobuf::prelude::*;

10 +

use unittest_rust_proto::TestAllTypes;

11 + 12 +

#[gtest]

13 +

fn test_thread_local_arena() {

14 +

// We use a thread-local arena to allocate minitables, so let's verify that a minitable remains

15 +

// valid even after that the thread that initialized it has exited.

16 +

let handle = std::thread::spawn(|| {

17 +

let mut m = TestAllTypes::new();

18 +

m.set_optional_int32(3);

19 +

let _ = m.serialize();

20 +

});

21 +

handle.join().unwrap();

22 + 23 +

let mut m1 = TestAllTypes::new();

24 +

m1.set_optional_int32(5);

25 +

let m2 = TestAllTypes::parse(&m1.serialize().unwrap()).unwrap();

26 +

assert_that!(m1.optional_int32(), eq(m2.optional_int32()));

27 +

}

Original file line number Diff line number Diff line change

@@ -33,6 +33,18 @@ pub type RawRepeatedField = upb::RawArray;

33 33

pub type RawMap = upb::RawMap;

34 34

pub type PtrAndLen = upb::StringView;

35 35 36 +

// This struct represents a raw minitable pointer. We need it to be Send and Sync so that we can

37 +

// store it in a static OnceLock for lazy initialization of minitables. It should not be used for

38 +

// any other purpose.

39 +

pub struct MiniTablePtr(pub *mut upb_MiniTable);

40 +

unsafe impl Send for MiniTablePtr {}

41 +

unsafe impl Sync for MiniTablePtr {}

42 + 43 +

// Same as above, but for enum minitables.

44 +

pub struct MiniTableEnumPtr(pub *const upb_MiniTableEnum);

45 +

unsafe impl Send for MiniTableEnumPtr {}

46 +

unsafe impl Sync for MiniTableEnumPtr {}

47 + 36 48

impl From<&ProtoStr> for PtrAndLen {

37 49

fn from(s: &ProtoStr) -> Self {

38 50

let bytes = s.as_bytes();

@@ -61,6 +73,12 @@ impl ScratchSpace {

61 73

}

62 74

}

63 75 76 +

thread_local! {

77 +

// We need to avoid dropping this Arena, because we use it to build mini tables that

78 +

// effectively have 'static lifetimes.

79 +

pub static THREAD_LOCAL_ARENA: ManuallyDrop<Arena> = ManuallyDrop::new(Arena::new());

80 +

}

81 + 64 82

#[doc(hidden)]

65 83

pub type SerializedData = upb::OwnedArenaBox<[u8]>;

66 84 Original file line number Diff line number Diff line change

@@ -52,6 +52,7 @@ cc_library(

52 52

"//upb:message",

53 53

"//upb:message_compare",

54 54

"//upb:message_copy",

55 +

"//upb/mini_descriptor",

55 56

"//upb/mini_table",

56 57

"//upb/text:debug",

57 58

],

Original file line number Diff line number Diff line change

@@ -6,9 +6,10 @@

6 6

// https://developers.google.com/open-source/licenses/bsd

7 7 8 8

use super::upb_MiniTable;

9 +

use super::upb_MiniTableEnum;

9 10 10 -

/// A trait for types which have a constant associated MiniTable (e.g.

11 -

/// generated messages, and their mut and view proxy types).

11 +

/// A trait for types which have an associated MiniTable (e.g. generated

12 +

/// messages, and their mut and view proxy types).

12 13

///

13 14

/// upb_Message in C is effectively a DST type, where instances are created with

14 15

/// a MiniTable (and have a size dependent on the given MiniTable). Many upb

@@ -20,12 +21,6 @@ use super::upb_MiniTable;

20 21

/// which hold upb_Message* to simplify ensuring the upb C invariants

21 22

/// are maintained.

22 23

///

23 -

/// Note that this would prefer to be a `const MINI_TABLE: *const upb_MiniTable`

24 -

/// to statically associate a single MiniTable, but as long as the MiniTable is

25 -

/// an extern "C" we cannot do that without the unstable `const_refs_to_static`.

26 -

/// After that feature is stabilized (or if we move the MiniTable generation to

27 -

/// .rs) this will be switched.

28 -

///

29 24

/// SAFETY:

30 25

/// - The MiniTable pointer must be from Protobuf code generation and follow the

31 26

/// corresponding invariants associated with upb's C API (the pointer should

@@ -34,3 +29,8 @@ use super::upb_MiniTable;

34 29

pub unsafe trait AssociatedMiniTable {

35 30

fn mini_table() -> *const upb_MiniTable;

36 31

}

32 + 33 +

/// A trait for closed enums that have an associated MiniTable.

34 +

pub unsafe trait AssociatedMiniTableEnum {

35 +

fn mini_table() -> *const upb_MiniTableEnum;

36 +

}

Original file line number Diff line number Diff line change

@@ -19,7 +19,7 @@ pub use array::{

19 19

};

20 20 21 21

mod associated_mini_table;

22 -

pub use associated_mini_table::AssociatedMiniTable;

22 +

pub use associated_mini_table::{AssociatedMiniTable, AssociatedMiniTableEnum};

23 23 24 24

mod ctype;

25 25

pub use ctype::CType;

@@ -41,8 +41,9 @@ pub use message_value::{upb_MessageValue, upb_MutableMessageValue};

41 41 42 42

mod mini_table;

43 43

pub use mini_table::{

44 -

upb_MiniTable, upb_MiniTableField, upb_MiniTable_FindFieldByNumber,

45 -

upb_MiniTable_GetFieldByIndex, upb_MiniTable_SubMessage, RawMiniTable, RawMiniTableField,

44 +

upb_MiniTable, upb_MiniTableEnum, upb_MiniTableEnum_Build, upb_MiniTableField,

45 +

upb_MiniTable_Build, upb_MiniTable_FindFieldByNumber, upb_MiniTable_GetFieldByIndex,

46 +

upb_MiniTable_Link, upb_MiniTable_SubMessage, upb_Status, RawMiniTable, RawMiniTableField,

46 47

};

47 48 48 49

mod opaque_pointee;

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4