fasterthanlime , Englisch
@fasterthanlime@hachyderm.io avatar

re offline Rust: everything in crate docs, or rustdoc (the cargo manual, incl. unstable features, etc.) you can take with, but, for example, neither serde_derive nor serde_macros actual documents container/field attributes.

reading proc macro sources in anger is no fun!

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

I had the same issue with at least another crate, the rust doc comments were pretty short and linked to the website heavily, which... I wish I thought about httrack'ing before the flight, but, reader, I didn't.

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

In other news, I'm excited to announce that instead of writing a proc macro (I definitely can't off the top of my head + didn't have the right deps offline), I wrote a program that invokes cargo rustdoc, parses its JSON output, and pipes generated code to rustfmt

Because there's no reason gophers should get all the codegen fun!

mjk ,
@mjk@hachyderm.io avatar

@fasterthanlime

tired: proc macros
wired: build.rs scripts

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

@mjk well it's not even a build script, since those slow down compilation a lot too.. it's just a separate crate that generates the sources for another crate. I need to remember to run it manually now and then.

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

I'm not even sure this could be a proc macro tbh? Since its output is a macro-by-example. Can proc macros output MBEs?

https://github.com/bearcove/fluke/blob/09afc3aafeac74647cf1502fefcf414f68486581/crates/httpwg-gen/src/main.rs

mgattozzi ,
@mgattozzi@hachyderm.io avatar

@fasterthanlime I don't see why not. It just takes in a stream of tokens and outputs a stream of tokens.

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

@mgattozzi I guess one hard bit is that... I sorta want my proc macro to be stateful? Like.. I'm registering (http2 compliance suite) test cases and then there should be another macro that generates the macro.. that generates rust test cases (against a specific implementation)

it's.. confusing. and I'm not exactly sure how a proc macro crate would keep track of all that.

mgattozzi ,
@mgattozzi@hachyderm.io avatar

@fasterthanlime hmmm I wonder if like a static variable is shared across invocations of the macro or not. I'm leaning towards not, but you know, who's to stop you from commiting crimes and bincoding data to disk to be read by a later invocation.

fasterthanlime OP ,
@fasterthanlime@hachyderm.io avatar

@mgattozzi cargo caching is the thing stopping me from doing that x)

imagine only some invocations get done, or in a different order…

mgattozzi ,
@mgattozzi@hachyderm.io avatar

@fasterthanlime damn. They really out here like:

  • do crimes
  • fast builds
  • the code you actually want

Pick 2

roastveg ,
@roastveg@mastodonapp.uk avatar

@fasterthanlime pyo3 has this problem too

  • Alle
  • Abonniert
  • Moderiert
  • Favoriten
  • random
  • haupteingang
  • Alle Magazine