Generate native packet catalog (#46)
Some checks failed
Native code generation / deterministic (macos-latest) (push) Has been cancelled
Native code generation / deterministic (ubuntu-latest) (push) Has been cancelled
Native code generation / deterministic (windows-latest) (push) Has been cancelled
Imaging and meshing gate / native (macos-latest) (push) Has been cancelled
Imaging and meshing gate / native (ubuntu-latest) (push) Has been cancelled
Imaging and meshing gate / native (windows-latest) (push) Has been cancelled
JPEG 2000 feature / linux (push) Has been cancelled
JPEG 2000 feature / macos (push) Has been cancelled
JPEG 2000 feature / windows (push) Has been cancelled
Skia feature / linux (push) Has been cancelled
Skia feature / macos (push) Has been cancelled
Skia feature / windows (push) Has been cancelled

This commit is contained in:
2026-08-09 06:08:34 +00:00
parent 9f7a4e323f
commit fb7d0c6836
15 changed files with 57777 additions and 10692 deletions

View File

@@ -9,9 +9,11 @@ description = "Deterministic native generators for pinned LibreMetaverse data"
publish = false
[dependencies]
prettyplease = "0.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.11"
syn = { version = "2", features = ["full"] }
[lints]
workspace = true

File diff suppressed because it is too large Load Diff

View File

@@ -38,6 +38,7 @@ TARGETS = {
# implementations. The generated module keeps catalog markers and re-exports
# the hand-written type so coverage remains deterministic.
NATIVE_TYPES = {
"T:LibreMetaverse.Packets.PacketType": "crate::packet_catalog::PacketType",
"T:LibreMetaverse.PrimMesher.Coord": "crate::prim_mesher::Coord",
"T:LibreMetaverse.PrimMesher.Face": "crate::prim_mesher::Face",
"T:LibreMetaverse.PrimMesher.Path": "crate::prim_mesher::Path",
@@ -741,11 +742,32 @@ def render_enum(item: dict, rust_name: str) -> list[str]:
return lines
def native_member_body(member_id: str) -> str | None:
body = NATIVE_MEMBER_BODIES.get(member_id)
if body is not None:
return body
if re.fullmatch(r"M:LibreMetaverse\.Packets\.[^.]+Packet\.#ctor", member_id):
return "Ok(<Self as crate::packet_catalog::GeneratedPacket>::new_generated())"
if re.fullmatch(r"M:LibreMetaverse\.Packets\.[^.]+Packet\.[^.]+Block\.#ctor", member_id):
return "Ok(<Self as crate::packet_catalog::GeneratedBlock>::new_generated())"
if re.fullmatch(r"P:LibreMetaverse\.Packets\.[^.]+Packet\.Length", member_id):
return "<Self as crate::packet_catalog::GeneratedPacket>::generated_length(self)"
if re.fullmatch(r"P:LibreMetaverse\.Packets\.[^.]+Packet\.UsesBufferPooling", member_id):
return "<Self as crate::packet_catalog::GeneratedPacket>::USES_BUFFER_POOLING"
if re.fullmatch(r"P:LibreMetaverse\.Packets\.[^.]+Packet\.[^.]+Block\.Length", member_id):
return "<Self as crate::packet_catalog::GeneratedBlock>::generated_length(self)"
if member_id == "M:LibreMetaverse.Packets.Packet.GetType(System.UInt16,LibreMetaverse.PacketFrequency)":
return "Ok(crate::packet_catalog::packet_type(id, frequency))"
if member_id == "M:LibreMetaverse.Packets.Packet.BuildPacket(LibreMetaverse.Packets.PacketType)":
return "crate::packet_catalog::build_packet(type_)"
return None
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]} }}"
if body := native_member_body(member_id):
return f" {signature} {{ {body} }}"
failure = (
f"libremetaverse_types::not_implemented({json.dumps(member_id)})"
if error_model.startswith("Result")
@@ -1035,7 +1057,7 @@ def coverage_report(catalog: dict, coverage: dict[str, tuple[int, int, bool]]) -
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 item["doc_id"] in native_type_ids or native_member_body(member["doc_id"]) is not None
}
if native_type_ids or native_member_ids:
type_noun = "type" if len(native_type_ids) == 1 else "types"

View File

@@ -984,6 +984,7 @@ def validate_generated_shims() -> None:
"crate::dispatch::",
"crate::json_codec::",
"crate::notation::",
"crate::packet_catalog::",
"crate::protobuf::",
"crate::xml_codec::",
)