Implement UUID CRC32 and byte order compatibility
This commit is contained in:
@@ -34,6 +34,25 @@ TARGETS = {
|
||||
"LibreMetaverse.Voice.WebRTC": ROOT / "crates/libremetaverse-voice-webrtc/src/generated.rs",
|
||||
}
|
||||
|
||||
# Types whose failure-only generated shells have been replaced by native Rust
|
||||
# implementations. The generated module keeps catalog markers and re-exports
|
||||
# the hand-written type so coverage remains deterministic.
|
||||
NATIVE_TYPES = {
|
||||
"T:LibreMetaverse.CRC32": "crate::crc32::CRC32",
|
||||
"T:LibreMetaverse.UUID": "crate::uuid::UUID",
|
||||
}
|
||||
|
||||
NATIVE_MEMBER_BODIES = {
|
||||
"M:LibreMetaverse.Utils.ReadSingleLittleEndian(System.Byte[],System.Int32)":
|
||||
"crate::byte_order::read_single_little_endian(src, pos)",
|
||||
"M:LibreMetaverse.Utils.WriteSingleLittleEndian(System.Byte[],System.Int32,System.Single)":
|
||||
"crate::byte_order::write_single_little_endian(dest, pos, value)",
|
||||
"M:LibreMetaverse.Utils.ReadDoubleLittleEndian(System.Byte[],System.Int32)":
|
||||
"crate::byte_order::read_double_little_endian(src, pos)",
|
||||
"M:LibreMetaverse.Utils.WriteDoubleLittleEndian(System.Byte[],System.Int32,System.Double)":
|
||||
"crate::byte_order::write_double_little_endian(dest, pos, value)",
|
||||
}
|
||||
|
||||
MAIN_TARGET = ROOT / "crates/libremetaverse/src/generated.rs"
|
||||
WIRE_NAMESPACES = (
|
||||
"LibreMetaverse.Assets",
|
||||
@@ -539,6 +558,8 @@ def render_enum(item: dict, rust_name: str) -> list[str]:
|
||||
def render_body(signature: str, member_id: str, error_model: str, asyncness: str, trait: bool) -> str:
|
||||
if trait:
|
||||
signature = signature.removeprefix("pub ")
|
||||
if member_id in NATIVE_MEMBER_BODIES:
|
||||
return f" {signature} {{ {NATIVE_MEMBER_BODIES[member_id]} }}"
|
||||
failure = (
|
||||
f"libremetaverse_types::not_implemented({json.dumps(member_id)})"
|
||||
if error_model.startswith("Result")
|
||||
@@ -564,6 +585,11 @@ def rust_constant_value(item: dict) -> str:
|
||||
|
||||
def render_type(item: dict, type_row: dict, member_rows: dict[str, dict[str, str]], mapper: mapping.Mapper) -> str:
|
||||
rust_name = type_name(type_row)
|
||||
if native_path := NATIVE_TYPES.get(item["doc_id"]):
|
||||
lines = [f"/// C# type: `{item['doc_id']}`."]
|
||||
lines.extend(f"/// C# member: `{member['doc_id']}`." for member in item["members"])
|
||||
lines.append(f"pub use {native_path} as {rust_name};")
|
||||
return "\n".join(lines)
|
||||
if item["kind"] == "enum":
|
||||
return "\n".join(render_enum(item, rust_name))
|
||||
names = generic_names(item)
|
||||
@@ -803,7 +829,22 @@ def coverage_report(catalog: dict, coverage: dict[str, tuple[int, int, bool]]) -
|
||||
got_types, got_members, complete = coverage[name]
|
||||
if complete and (types, members) != (got_types, got_members):
|
||||
raise ValueError(f"incomplete generated slice for {name}")
|
||||
status = "callable failure-only shim" if complete else f"partial callable shim ({got_types:,} types / {got_members:,} members)"
|
||||
native_type_ids = {
|
||||
item["doc_id"] for item in assembly["types"] if item["doc_id"] in NATIVE_TYPES
|
||||
}
|
||||
native_member_ids = {
|
||||
member["doc_id"]
|
||||
for item in assembly["types"]
|
||||
for member in item["members"]
|
||||
if item["doc_id"] in native_type_ids or member["doc_id"] in NATIVE_MEMBER_BODIES
|
||||
}
|
||||
if native_type_ids or native_member_ids:
|
||||
status = (
|
||||
f"native implementation: {len(native_type_ids):,} types / "
|
||||
f"{len(native_member_ids):,} members; remaining surface is callable failure-only shims"
|
||||
)
|
||||
else:
|
||||
status = "callable failure-only shim" if complete else f"partial callable shim ({got_types:,} types / {got_members:,} members)"
|
||||
total_types += got_types
|
||||
total_members += got_members
|
||||
else:
|
||||
|
||||
@@ -189,6 +189,26 @@ MEMBER_TYPE_OVERRIDES = {
|
||||
),
|
||||
}
|
||||
MEMBER_SIGNATURE_OVERRIDES = {
|
||||
"M:LibreMetaverse.Utils.ReadSingleLittleEndian(System.Byte[],System.Int32)": (
|
||||
"pub fn read_single_little_endian(src: &[u8], pos: i32) -> Result<f32, crate::Error>",
|
||||
"shared_borrow,owned",
|
||||
),
|
||||
"M:LibreMetaverse.Utils.WriteSingleLittleEndian(System.Byte[],System.Int32,System.Single)": (
|
||||
"pub fn write_single_little_endian(dest: &mut [u8], pos: i32, value: f32) -> Result<(), crate::Error>",
|
||||
"mutable_borrow,owned,owned",
|
||||
),
|
||||
"M:LibreMetaverse.Utils.ReadDoubleLittleEndian(System.Byte[],System.Int32)": (
|
||||
"pub fn read_double_little_endian(src: &[u8], pos: i32) -> Result<f64, crate::Error>",
|
||||
"shared_borrow,owned",
|
||||
),
|
||||
"M:LibreMetaverse.Utils.WriteDoubleLittleEndian(System.Byte[],System.Int32,System.Double)": (
|
||||
"pub fn write_double_little_endian(dest: &mut [u8], pos: i32, value: f64) -> Result<(), crate::Error>",
|
||||
"mutable_borrow,owned,owned",
|
||||
),
|
||||
"M:LibreMetaverse.UUID.ToBytes(System.Byte[],System.Int32)": (
|
||||
"pub fn to_bytes(&self, dest: &mut [u8], pos: i32) -> Result<(), crate::Error>",
|
||||
"shared_self,mutable_borrow,owned",
|
||||
),
|
||||
"M:LibreMetaverse.AppearanceManager.#ctor(LibreMetaverse.GridClient)": (
|
||||
"pub fn new(client: Option<std::sync::Arc<libremetaverse::GridClient>>) "
|
||||
"-> Result<Self, crate::Error>",
|
||||
@@ -853,7 +873,15 @@ def validate_generated_shims() -> None:
|
||||
for body in function_bodies(text):
|
||||
if FAKE_BODY.search(body):
|
||||
raise ValueError(f"generated shim returns a plausible fallback: {path.relative_to(ROOT)}")
|
||||
if not any(marker in body for marker in ("unimplemented_api!", "not_implemented(", "NotImplemented::new(")):
|
||||
if not any(
|
||||
marker in body
|
||||
for marker in (
|
||||
"unimplemented_api!",
|
||||
"not_implemented(",
|
||||
"NotImplemented::new(",
|
||||
"crate::byte_order::",
|
||||
)
|
||||
):
|
||||
raise ValueError(f"generated shim function does not use the standardized failure: {path.relative_to(ROOT)}")
|
||||
|
||||
|
||||
@@ -983,6 +1011,8 @@ def generic_names(item: dict, owner: dict) -> set[str]:
|
||||
def method_receiver(owner: dict, item: dict) -> tuple[str, str]:
|
||||
if item.get("static") or item["kind"] == "constructor":
|
||||
return "", "none"
|
||||
if owner["doc_id"] == "T:LibreMetaverse.CRC32" and item["name"] == "Update":
|
||||
return "&mut self", "mutable_self"
|
||||
if item["name"] == "Deserialize":
|
||||
return "&mut self", "mutable_self"
|
||||
if owner["doc_id"] == "T:LibreMetaverse.Assets.AssetMaterial" and item["name"].startswith(
|
||||
|
||||
Reference in New Issue
Block a user