rustype / typestate-rs

Proc-macro typestate DSL for Rust
https://rustype.github.io/typestate-rs/
Apache License 2.0
139 stars 11 forks source link

Feature Request: include the code generated UML and dotfile in the generated code. #46

Open andrew-otiv opened 1 year ago

andrew-otiv commented 1 year ago

I spent a few hours today unsuccessfully trying to integrate typestate-rs's UML generation into a bazel (or buck2) build.

The challenge is that the extra artifacts containing the UML or dotfile are generated at compile-time by the procedural macro code, but the starlark rules in rules_rust (and prelude for buck2) don't know anything about the extra build-time output. I tried forking or vendoring the rules and modifying them to declare the extra output, but this stuff is so complex I think it would take me days to get working.

Similarly, genrule doesn't have ~any of that logic needed to find the toolchain and build the rust binary. I tried to write a run_binary command that runs the "cargo expand" tool, but then I would need to build and include that tool too in my CICD environment, even if I ~could figure out how to get "run_binary" to find cargo (I couldn't).

I looked briefly at how the procedural macros work, but they're getting compiled to a .so file.

I think a possible way forward would be for typestate-rs to optionally include the UML (and dot) in the generated source file as a static string. Then I could make a build target that just outputs the UML when called, and call that from run_binary.

Anyway, appologies for the noise if nobody has interest in getting this particular feature of this particular library working in this particular build system; just wanted to share an experince. Most of my difficulty stems from being new to both bazel and procedural macros; typestate-rs is working as documented!

jmg-duarte commented 1 year ago

I'm not experienced with bazel/buck2 but I think reading the bindgen bazel rules might prove useful. https://github.com/bazelbuild/rules_rust/blob/main/bindgen/bindgen.bzl

From what I understood you can do something like:

My intuition is that on a build depending on bindgen you will definitely need the output of the first step on the second step, so I'd start there.

I'm curious as to why use bazel/buck2 with Rust, since you already have cargo. If you could share, I'm keen on learning something new!