Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
824adb0
add xdr-generator-rust crate structure
leighmcculloch Jan 8, 2026
260dac2
add handoff documentation and fix parser edge cases
leighmcculloch Jan 9, 2026
94060fe
extract anonymous unions and inline structs during parsing
leighmcculloch Jan 9, 2026
5154442
remove handoff documentation
leighmcculloch Jan 9, 2026
4078cc6
delete test_snake example file
leighmcculloch Jan 9, 2026
463f29e
add rust code generation targets to makefile
leighmcculloch Jan 9, 2026
ddf003b
prefix input flags to each xdr file argument
leighmcculloch Jan 9, 2026
fea7888
generate with xdr-generator-rust
leighmcculloch Jan 9, 2026
ed375a3
fix differences between ruby and rust generators
leighmcculloch Jan 9, 2026
97dfb73
add topological sorting for xdr file dependencies
leighmcculloch Jan 9, 2026
e8331c4
rename generate-rust target and add to generate deps
leighmcculloch Jan 9, 2026
180e77e
remove unused fns
leighmcculloch Jan 9, 2026
af20dcf
generated with rust files
leighmcculloch Jan 9, 2026
a58bee9
add nested type tracking and parent relationships to ast
leighmcculloch Jan 9, 2026
94edc6f
update rust generated
leighmcculloch Jan 9, 2026
bda5338
refactor struct generation to use template-driven attributes
leighmcculloch Jan 9, 2026
dbd4290
replace attribute generation with boolean flags in output structs
leighmcculloch Jan 9, 2026
537a246
add xdr generator documentation and output validation
leighmcculloch Jan 9, 2026
9fb2dfe
remove rust files
leighmcculloch Jan 9, 2026
09b7c4e
remove .PHONY declaration from Makefile
leighmcculloch Jan 11, 2026
ae06f09
remove dependencies from check-generated-match
leighmcculloch Jan 12, 2026
7db6d1b
remove tokenize method and use tokenize_with_spans
leighmcculloch Jan 12, 2026
24e28eb
reorganize code into logical sections
leighmcculloch Jan 12, 2026
2e31b28
replace handwritten lexer with logos
leighmcculloch Jan 13, 2026
2e56473
simplify lexer to single Token enum
leighmcculloch Jan 13, 2026
2ad2b6f
use IntBase enum instead of is_hex boolean
leighmcculloch Jan 13, 2026
44168ba
move IntBase enum and parse functions after Token enum
leighmcculloch Jan 13, 2026
807f32c
fmt
leighmcculloch Feb 6, 2026
c968557
fmt
leighmcculloch Feb 6, 2026
cc8982a
Merge branch 'main' into rewrite-code-gen
leighmcculloch Feb 6, 2026
2ab4018
add namespace to generated template
leighmcculloch Feb 10, 2026
46ec215
Merge branch 'main' into rewrite-code-gen
leighmcculloch Feb 27, 2026
45f7ccb
add TODO list of planned improvements
leighmcculloch Mar 3, 2026
08fd7ae
Deduplicate anonymous union extraction logic in parser.rs
leighmcculloch Mar 3, 2026
b7fdf53
Unify base_rust_type_ref and base_rust_type_ref_with_info
leighmcculloch Mar 3, 2026
d550321
Replace fragile string slicing with strip_prefix/strip_suffix
leighmcculloch Mar 3, 2026
ce3708b
Extract parse_inline_struct method with documentation
leighmcculloch Mar 3, 2026
6eb3e36
Add documentation and test for fix_parent_relationships
leighmcculloch Mar 3, 2026
7a90076
Return errors from resolve_enum_value instead of silent fallback
leighmcculloch Mar 3, 2026
d4c3448
Document that const type u64 matches Ruby xdrgen behavior
leighmcculloch Mar 3, 2026
d4baca1
Add line/column info to ParseError
leighmcculloch Mar 3, 2026
075626d
Simplify rust_type_ref by returning base early for non-cyclic types
leighmcculloch Mar 3, 2026
cc7e2e2
Rewrite rust_read_call_type to pattern-match on Type AST
leighmcculloch Mar 3, 2026
7f546fe
Extract source byte helpers in parser to reduce boilerplate
leighmcculloch Mar 3, 2026
c473580
Extract parse_union_body to deduplicate union arm collection
leighmcculloch Mar 3, 2026
60818fd
Remove duplicate size_to_string, reuse size_to_rust from types
leighmcculloch Mar 3, 2026
9422524
Replace silent integer truncation with checked conversions
leighmcculloch Mar 3, 2026
e749980
Parse hex literals as u64 to handle full unsigned range
leighmcculloch Mar 3, 2026
a1387f5
Return UnexpectedEof on EOF during inline struct brace scanning
leighmcculloch Mar 3, 2026
e106b6f
Document escape_name Error->SError convention
leighmcculloch Mar 3, 2026
7a7af78
Remove default_arm support, error if encountered
leighmcculloch Mar 3, 2026
369eb31
Document why is_primitive_alias uses a hardcoded name list
leighmcculloch Mar 4, 2026
aceb1f2
Move HashMap/HashSet imports to top of file
leighmcculloch Mar 4, 2026
3a0f19c
Extract order_types_parent_first from generate method
leighmcculloch Mar 4, 2026
c4f6748
Document intentionally discarded field name in parse_union_arm
leighmcculloch Mar 4, 2026
950205a
Introduce TypeParseContext to group extraction parameters
leighmcculloch Mar 4, 2026
1a46d1f
Add debug_assert to source_slice for out-of-bounds detection
leighmcculloch Mar 4, 2026
568ab31
Extract parse_definition_into to deduplicate definition collection
leighmcculloch Mar 4, 2026
ff15326
Document AnonymousUnion as transient and add debug assertion
leighmcculloch Mar 4, 2026
7b9811f
Make Parser struct and methods private
leighmcculloch Mar 4, 2026
8d9d42b
Remove unused TypeInfo::type_names field
leighmcculloch Mar 4, 2026
ce6f655
Reword namespace template comment for clarity
leighmcculloch Mar 4, 2026
36f575b
delete TODO.md
leighmcculloch Mar 4, 2026
a2f3a27
Move AnonymousUnion out of Type into parser-local ParsedType enum
leighmcculloch Mar 4, 2026
f1250f7
Rename AST types for clarity
leighmcculloch Mar 4, 2026
11f913d
Rename MemberOutput to StructMemberOutput for consistency
leighmcculloch Mar 4, 2026
615c58e
Remove fix_parent_relationships post-processing step
leighmcculloch Mar 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
generated-rust.rs
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Contributing

## XDR Generators

This repository has two XDR-to-Rust code generators:

1. **Ruby generator** (`xdr-generator/`) - The original generator using xdrgen. Outputs to `src/*/generated.rs`.

2. **Rust generator** (`xdr-generator-rust/`) - A new generator written in Rust. Outputs to `src/*/generated-rust.rs`.

The plan is to migrate to the Rust generator once it has been validated to produce identical output. Currently both generators run during `make generate` and the outputs are compared to ensure they match.

## How to Regenerate From XDR
To regenerate types from XDR definitions:

Expand Down
32 changes: 31 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,42 @@ readme:
watch:
cargo watch --clear --watch-when-idle --shell '$(MAKE)'

generate: generate-xdrgen-files xdr/curr-version xdr/next-version xdr-json/curr xdr-json/next
generate: generate-xdrgen-files generate-rust-files xdr/curr-version xdr/next-version xdr-json/curr xdr-json/next check-generated-match

generate-xdrgen-files: src/curr/generated.rs src/next/generated.rs
docker run -i --rm -v $$PWD:/wd -w /wd docker.io/library/ruby:3.1 /bin/bash -c \
'cd xdr-generator && bundle install --quiet && bundle exec ruby generate.rb'
rustfmt $^

CUSTOM_DEFAULT_IMPL=TransactionEnvelope
CUSTOM_STR_IMPL=PublicKey,AccountId,ContractId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12,ClaimableBalanceId,PoolId,MuxedEd25519Account,Int128Parts,UInt128Parts,Int256Parts,UInt256Parts

generate-rust-files: src/curr/generated-rust.rs src/next/generated-rust.rs

src/curr/generated-rust.rs: $(sort $(wildcard xdr/curr/*.x))
cargo run --manifest-path xdr-generator-rust/Cargo.toml -- \
$(addprefix --input ,$(sort $(wildcard xdr/curr/*.x))) \
--output $@ \
--custom-default $(CUSTOM_DEFAULT_IMPL) \
--custom-str $(CUSTOM_STR_IMPL)
rustfmt $@

src/next/generated-rust.rs: $(sort $(wildcard xdr/next/*.x))
cargo run --manifest-path xdr-generator-rust/Cargo.toml -- \
$(addprefix --input ,$(sort $(wildcard xdr/next/*.x))) \
--output $@ \
--custom-default $(CUSTOM_DEFAULT_IMPL) \
--custom-str $(CUSTOM_STR_IMPL)
rustfmt $@

check-generated-match:
@echo "Checking that Ruby and Rust generators produce identical output..."
@diff -q src/curr/generated.rs src/curr/generated-rust.rs || \
(echo "ERROR: src/curr/generated.rs and src/curr/generated-rust.rs differ" && exit 1)
@diff -q src/next/generated.rs src/next/generated-rust.rs || \
(echo "ERROR: src/next/generated.rs and src/next/generated-rust.rs differ" && exit 1)
@echo "OK: Ruby and Rust generator outputs match"

src/next/generated.rs: $(sort $(wildcard xdr/curr/*.x))
> $@

Expand All @@ -59,6 +88,7 @@ xdr-json/next: src/next/generated.rs

clean:
rm -f src/*/generated.rs
rm -f src/*/generated-rust.rs
rm -f xdr/*-version
rm -fr xdr-json/curr
rm -fr xdr-json/next
Expand Down
1 change: 1 addition & 0 deletions xdr-generator-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Loading