Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrew-otiv opened this issue Jun 22, 2023 · 1 comment

Comments

@andrew-otiv
Copy link

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
Copy link
Contributor

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:

  • Run cargo expand
  • Compile the crate

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants