bonzini/raisin

Another build system, but Rewrite It In Rust edition

★ 2Forks 0RustGitHub ↗Compare

README

Another build system, but Rewrite It In Rust edition

This is an experiment in rewriting typed Python to idiomatic Rust, and specifically trying to understand how much can be transcribed around a careful Rust reimplementation of the core concept.

In particular, the idea is to implement from scratch core components such as the command-line dispatch or the interpreter loop, and transcribe the "boring" (but complex!) parts of the implementation as literally as possible.

This is partly made possible by the use of mypy on the Python side: while Meson uses casts here and there, in general it is fairly well-behaved and the contact points between the components (interpreter, build graph, backend) are well-defined.

AI usage

Yes, there is obviously AI involved. The point of the exercise is exactly to design and implement by hand the core concepts, in a shape such that the language-independent bits can be converted from Python to Rust mechanically. It doesn't matter to me whether the mechanical parts are done by a machine or a person; it matters that the resulting code is well done.

raisin started as a discussion with an LLM about the next steps of cleaning up Meson's typing annotations. While the chat started with repeated mentions (by me) of "let's think of what this type would look like in Rust", at some point I switched to "I'm curious about how this concept would be implemented in Rust". And then I got nerd-sniped into actually doing it. The documents in docs/ are the result of the discussion; sometimes the AI corrected me, sometimes I did. They are extremely terse and full of LLM tropes, but they help with the transcription work.

What raisin is

raisin is first and foremost an educational project. In particular, it is:

A way to improve Meson. Some of the ideas behind raisin have led to refactoring Meson and improving its usage of type annotations; for example replacing type unions (enums in Rust) with protocols (dyn traits), and avoiding implicit Optional. The unit tests can also be ported back to Meson, to improve Meson where its integration tests do not provide sufficient code coverage.

A way for me to learn Rust. It's more common to work on an established codebase than to have to make all the top-level decisions. This means it's hard to get hands-on experience with how those decisions are made; you learn what idiomatic Rust looks like but not how you get there. Here I have the luxury of doing the opposite: I create the core design, and see it turned into a full program.

Maybe, in the future, a way for me to learn PyO3. It's plausible that I will (try to) integrate Meson's rich test suite into raisin.

What raisin is not

raisin is not hostile to Meson. In particular, it is not:

An attempt to replace Meson. I have no plans to reimplement all of Meson right now. Every now and then I might add more core pieces, depending on what I want to learn. Right now there is nothing but a parser and AST-walking interpreter.

An attempt to copyright-wash Meson. The AI is not "imagining" what Meson would look like (as in the infamous Claude C compiler) but explicitly uses existing code as the reference; therefore, I consider this code to be a derivative of Meson, and I am releasing it under the same license (Apache 2.0). It would be in bad faith to do otherwise.

An attempt to vibe-code Meson. Every design decision is mine and I would defend it on my own; the files in docs/ are just a summary. I convert the design to a Rust skeleton before handing it to the AI for transcription of Meson's Python code; manual implementation and automated transcription alternate as a way to validate the design in small pieces.

How to run it

raisin builds with a stable Rust toolchain that supports edition 2024, and has no other dependencies outside what is in crates.io:

$ cargo build

The command line follows Meson's, but only introspect does anything so far; the other subcommands stop with an error.

By pointing introspect --ast at a source directory or a meson.build file, it prints the AST of that file as JSON. The output has the same shape as meson introspect --ast (but comes out about 100 times faster):

$ cargo run -- introspect --ast --indent path/to/project
{
  "node": "CodeBlockNode",
  "lineno": 1,
  ...

The remaining introspect flags (--targets, --buildoptions, ...) are able to read the meson-info/intro-*.json files of a configured build directory, but Meson must be used to produce them.

Other parts that are implemented are only reachable via unit tests:

$ cargo test --workspace

Legal info

Meson is a registered trademark of Jussi Pakkanen.

Contributors

bonzini

Issues