Skip to content

About

Incremental, bottom-up migration of libgit2 from C to safe Rust, produced by Crustify

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

libgit2-crustify

An incremental, bottom-up migration of libgit2 from C to Rust.

So far, 41.9% of libgit2's public C API is available as safe Rust bindings: a safe, idiomatic Rust interface, implemented for now by libgit2's C through unsafe Rust, with the raw bindings in the libgit2-sys crate.

Roadmap

  1. Bind (in progress): put a safe Rust API in front of all of libgit2's public C API.
  2. Migrate: module by module, from the bottom of the dependency order up, port the C behind the bindings to safe Rust and swap it in for the unsafe implementation, without breaking the API's consumers.
  3. Ship hybrids: every step ships as an interoperable build that mixes C and Rust, the modules migrated so far in Rust and the rest still in C.

How it was made

The bindings were generated by Crustify, a specification-driven AI co-translator developed at UC Berkeley, and reviewed by its own independent, adversarial agents; the paper details the campaign.

  • Models: mainly Claude Opus 5.5. GPT-6.1 Sol wrapped the config module and GPT-6 Astra most of the first index wave; Claude Fable 5.1 ran the early reviews.
  • wavefront: CodeQL-based analysis of the C that plans the work in dependency order.
  • ffibox: ownership and borrowed-handle types the bindings hold C memory through.
  • ffimap: maps the unsafe code and raw pointers left on the public API.
  • bindgen for the raw bindings; ASan/UBSan, TSan, Miri and BorrowSanitizer to check for undefined behavior.
  • glibc-bindings, openssl-bindings, pcre2-bindings and zlib-bindings for the libraries libgit2 links: each is built per sanitizer variant and wraps what libgit2's API uses as the campaign reaches it.

Results

Public API wrapped 480 of 1,146 items (41.9%): 69 of 165 types, 411 of 981 symbols
Tests 2,064: 787 unit, 489 equivalence with the C, 688 UB on the safe API, 100 UB on the unsafe API
Line coverage 98.9% of the Rust, 46.0% of the C
unsafe public functions 42 of 2,663 (1.6%) on the consumer-facing interface; 102 (3.8%) with ffibox's trait methods and raw constructors
Raw pointers in 2 consumer-facing public functions' signatures (0.1%); none in public fields
UB defects the reviewers fixed 8
Rust 17,571 lines of code
Wall-clock time, cost 51.9 hours, $2,308 for every agent

The campaign's plan, review reports and dashboard are under crustify/.

License

GPL-2.0-only with the GCC linking exception, as libgit2.

About

Incremental, bottom-up migration of libgit2 from C to safe Rust, produced by Crustify

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages