Skip to content

Commit a285e7e

Browse files
dexteroMarcin Radomski
andauthored
Rust reflection: simplify dependencies, fix Android build compatibility (#8512)
* flatbuffers Rust reflection: replace num with num-traits num crate is a wrapper over num-traits and a few other crates, that reexports the APIs from all of them. We only need num-traits. Signed-off-by: Marcin Radomski <[email protected]> * Rust reflection: drop dependency on stdint crate We only use it to get intmax_t for deriving alignment, which is an alias for `core::ffi::c_long` [1]. We can use that directly instead. [1] https://docs.rs/stdint/1.0.0/stdint/type.intmax_t.html Signed-off-by: Marcin Radomski <[email protected]> * Rust reflection: drop dependency on escape_string crate It's used to format a string used for debugging only, so we might as well use the builtin Debug representation of a string. Signed-off-by: Marcin Radomski <[email protected]> * Rust codegen: add derives on generated bitflags Otherwise it limits the use of structs generated for reflection.fbs in Rust reflection API. Signed-off-by: Marcin Radomski <[email protected]> * Rust flatbuffers: update bitflags dependency to 2.8 Signed-off-by: Marcin Radomski <[email protected]> * Rust codegen: use bitflags v2 API for converting from bits from_bits_unchecked was replaced with safe from_bits_retain. Signed-off-by: Marcin Radomski <[email protected]> * Regenerate Rust code after idl change Signed-off-by: Marcin Radomski <[email protected]> * Regenerate reflection_generated.rs With flatc --rust ../../../reflection/reflection.fbs Signed-off-by: Marcin Radomski <[email protected]> * ts/BUILD.bazel: add missing import Found by Buildifire presubmit: Function "sh_binary" is not global anymore and needs to be loaded from "@rules_shell//shell:sh_binary.bzl". Signed-off-by: Marcin Radomski <[email protected]> * Update expected value in generated_code_debug_prints_correctly test In bitflags v2, the debug string representation of enum values is different than it was in v1: Blue -> Color(Blue) (empty) -> LongEnum(0x0) This change adjusts the expected test value. Signed-off-by: Marcin Radomski <[email protected]> * Fix tests build on Swift 5.8 grpc-swift 1.4.1 depends on swift-nio-ssl 2.14.0+ [1]. swift-nio-ssl 2.29.1 published on 2025-01-30, introduced some code [2] that uses a "switch expression syntax" supported since Swift 5.9 [3]. Attempts to compile it with Swift 5.8 cause build errors. swift-nio-ssl project doesn't seem to support Swift 5.8. A commit from 2024-10-29 removes a "deprecated reference to a Swift 5.8 pipeline" [4]. swift-nio-ssl 2.29.0 is the last version that can be compiled with Swift 5.8. This commit pins it to that exact version. [1] https://github.com/grpc/grpc-swift/blob/66e27d7e84a2f51df6b8d5c4c3649639cfe478c1/Package.swift#L33 [2] apple/swift-nio-ssl@3cb4d5a#diff-bc1db1321ff689c2819245dcce1a3080554f0fc13f81b8d326c97e7d42717c8fR54 [3] https://github.com/swiftlang/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md [4] apple/swift-nio-ssl@8a6b89d --------- Signed-off-by: Marcin Radomski <[email protected]> Co-authored-by: Marcin Radomski <[email protected]>
1 parent 0312061 commit a285e7e

File tree

14 files changed

+2343
-3095
lines changed

14 files changed

+2343
-3095
lines changed

MODULE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ bazel_dep(
4343
name = "rules_nodejs",
4444
version = "6.3.3",
4545
)
46+
bazel_dep(
47+
name = "rules_shell",
48+
version = "0.3.0",
49+
)
4650
bazel_dep(
4751
name = "rules_swift",
4852
version = "1.18.0",

rust/flatbuffers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ std = []
1717
serialize = ["serde"]
1818

1919
[dependencies]
20-
bitflags = "1.2.1"
20+
bitflags = "2.8.0"
2121
serde = { version = "1.0", optional = true }
2222

2323
[build-dependencies]

rust/reflection/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
flatbuffers = { path = "../flatbuffers"}
8-
escape_string = "0.1.2"
9-
stdint = "0.2.0"
10-
num = "0.4.1"
8+
num-traits = "0.2.19"
119
anyhow = "1.0.75"
1210
thiserror = "1.0"

rust/reflection/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ use flatbuffers::{
2929
use reflection_generated::reflection::{BaseType, Field, Object, Schema};
3030

3131
use core::mem::size_of;
32-
use escape_string::escape;
33-
use num::traits::float::Float;
34-
use num::traits::int::PrimInt;
35-
use num::traits::FromPrimitive;
36-
use stdint::uintmax_t;
32+
use num_traits::float::Float;
33+
use num_traits::int::PrimInt;
34+
use num_traits::FromPrimitive;
3735
use thiserror::Error;
3836

3937
#[derive(Error, Debug, PartialEq)]
@@ -541,7 +539,9 @@ pub unsafe fn set_string(
541539

542540
if delta != 0 {
543541
// Rounds the delta up to the nearest multiple of the maximum int size to keep the types after the insersion point aligned.
544-
let mask = (size_of::<uintmax_t>() - 1) as isize;
542+
// stdint crate defines intmax_t as an alias for c_long; use it directly to avoid extra
543+
// dependency.
544+
let mask = (size_of::<core::ffi::c_long>() - 1) as isize;
545545
let offset = (delta + mask) & !mask;
546546
let mut visited_vec = vec![false; buf.len()];
547547

@@ -715,7 +715,8 @@ unsafe fn get_any_value_string(
715715
}
716716
let mut field_value = get_any_field_string(&table, &field, schema);
717717
if field.type_().base_type() == BaseType::String {
718-
field_value = escape(field_value.as_str()).to_string();
718+
// Escape the string
719+
field_value = format!("{:?}", field_value.as_str());
719720
}
720721
s += field.name();
721722
s += ": ";

0 commit comments

Comments
 (0)