<div dir="ltr"><div>Hi everyone,</div><div><br></div><div>I've been working for a while on a little project that ended up taking quite a chunk of my time, and while it's nowhere near done, I feel like it's time to show the current progress. <b>In other words: that stuff ain't ready, don't put it in prod.</b></div><div><br></div><div>Here we go: we can <b>build vmods using pure rust</b>.</div><div>For example, this guys: <a href="https://github.com/gquintard/varnish-rs/tree/main/examples">https://github.com/gquintard/varnish-rs/tree/main/examples</a></div><div>And the crates `varnish` and `varnish-sys`, that make this possible have been published on <a href="http://crates.io">crates.io</a>, and we have documentation! <a href="https://docs.rs/varnish/latest/varnish/">https://docs.rs/varnish/latest/varnish/</a></div><div><br></div><div>Without trying to start a language war, there are a few benefits to using Rust over C:</div><div>- the language is designed to prevent a few classes of annoying bugs, and the compiler is very good at explaining where you went wrong</div><div>- a lot of the C practices (assert everywhere, miniobj, etc.) are basically baked into Rust</div><div>- the barrier between C and Rust is razor-thin, with almost zero overhead cost (curse you, null-terminated strings!)</div><div>- the tooling is absolutely stellar</div><div>- string manipulation is sane (yeah, easy stab at C, but I had to do it)</div><div><br></div><div>What you get at the moment:</div><div>- few dependencies: you only need cargo, python3 and the libvarnish dev files to get going<br></div><div>- write the same vmod.vcc as you would for C, the boilerplate is generated for you</div><div>- building is literally just one command: `cargo build`</div><div>- automatic type translation so you can write pure rust, and never need to see the `VCL` objects under their C form (<a href="https://docs.rs/varnish/latest/varnish/vcl/convert/index.html">https://docs.rs/varnish/latest/varnish/vcl/convert/index.html</a>)<br></div><div>- support for PRIVobjects (<a href="https://github.com/gquintard/varnish-rs/blob/main/examples/vmod_object/vmod.vcc">https://github.com/gquintard/varnish-rs/blob/main/examples/vmod_object/vmod.vcc</a> and <a href="https://github.com/gquintard/varnish-rs/blob/main/examples/vmod_object/src/lib.rs">https://github.com/gquintard/varnish-rs/blob/main/examples/vmod_object/src/lib.rs</a>)<br></div><div>- you can iterate through and modify the HTTP objects easily (<a href="https://docs.rs/varnish/latest/varnish/vcl/ctx/struct.Ctx.html">https://docs.rs/varnish/latest/varnish/vcl/ctx/struct.Ctx.html</a>)</div><div><br></div><div>What you don't get for now:</div><div>- a comprehensive API, some bits are still missing, like WS_ReserveAll/WS_Release, but because of the type conversion, you can possibly live without it</div><div>- a stable API. I'm heavily working on it, and things will change twenty times before the next Varnish release (but it doesn't matter as the crates are version-locked)</div><div>- something based solely on the public library (libvarnishapi), I reimplemented some stuff using private bits to avoid copies</div><div>- all the types. I only implemented a subset of VCL types, but fret not, the others will come.</div><div>- a sensible boilerplate code generation, the current approach involves embedding a python script that imports `vmodtool.py` and running it from rust. But there's a plan to fix that</div><div><br></div><div>In case you want to try it, I've also created a minimal example repo that you can play with:</div><div style="margin-left:40px"><span style="font-family:monospace">git clone <a href="https://github.com/gquintard/vmod-rs-template.git">https://github.com/gquintard/vmod-rs-template.git</a></span></div><div style="margin-left:40px"><span style="font-family:monospace">cd vmod-rs-template</span></div><div style="margin-left:40px"><span style="font-family:monospace">cargo build</span></div><div style="margin-left:40px"><span style="font-family:monospace">cargo test</span></div><div><br></div><div>I will continue working on expanding the API, documentation and will start filing issues to come up with a roadmap. If you are interested in helping, have questions or feedback, please do ping me, I'd love to hear from you.</div><div><br></div><div>Cheers!</div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div><div>Guillaume Quintard<br></div></div></div></div></div>