Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust reflection: simplify dependencies, fix Android build compatibility #8512

Merged
merged 11 commits into from
Feb 4, 2025
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ bazel_dep(
name = "rules_nodejs",
version = "6.3.3",
)
bazel_dep(
name = "rules_shell",
version = "0.3.0",
)
bazel_dep(
name = "rules_swift",
version = "1.18.0",
Expand Down
2 changes: 1 addition & 1 deletion rust/flatbuffers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std = []
serialize = ["serde"]

[dependencies]
bitflags = "1.2.1"
bitflags = "2.8.0"
serde = { version = "1.0", optional = true }

[build-dependencies]
Expand Down
4 changes: 1 addition & 3 deletions rust/reflection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ edition = "2021"

[dependencies]
flatbuffers = { path = "../flatbuffers"}
escape_string = "0.1.2"
stdint = "0.2.0"
num = "0.4.1"
num-traits = "0.2.19"
anyhow = "1.0.75"
thiserror = "1.0"
15 changes: 8 additions & 7 deletions rust/reflection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ use flatbuffers::{
use reflection_generated::reflection::{BaseType, Field, Object, Schema};

use core::mem::size_of;
use escape_string::escape;
use num::traits::float::Float;
use num::traits::int::PrimInt;
use num::traits::FromPrimitive;
use stdint::uintmax_t;
use num_traits::float::Float;
use num_traits::int::PrimInt;
use num_traits::FromPrimitive;
use thiserror::Error;

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

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

Expand Down Expand Up @@ -715,7 +715,8 @@ unsafe fn get_any_value_string(
}
let mut field_value = get_any_field_string(&table, &field, schema);
if field.type_().base_type() == BaseType::String {
field_value = escape(field_value.as_str()).to_string();
// Escape the string
field_value = format!("{:?}", field_value.as_str());
}
s += field.name();
s += ": ";
Expand Down
Loading
Loading