`cargo watt` subcommand
- Dominant language
- Rust
- Stars
- 1.5k
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
I made a cargo subcommand called [cargo watt](https://github.com/jakobhellermann/cargo-watt), which aims to improve the tooling listed in the README.
Currently, it does two things:
1. Compile a proc-macro crate (locally, from git or from crates.io) and generate a crate which exposes the compiled wasm
2. Verify that that wasm file was compiled from some source
Initially I wanted to replace
```rust
#[proc_macro]
pub fn the_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/* ... */
}
```
with
```rust
#[no_mangle]
pub extern "C" fn the_macro(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
the_macro_inner(input.into().into()
}
pub fn the_macro_inner(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/* ... */
}
```
but that doesn't work because [Into does not exist in wasm](https://github.com/dtolnay/watt/blob/master/proc-macro/src/lib.rs#L50).
So my solution was to just replace the TokenStreams and hope for the best, while also using a [patched version of syn](https://github.com/jakobhellermann/syn-watt) which basically just has all instances of `proc_macro` replaced with `proc_macro2`.
This actually works for quite a few crates (e.g. `serde-derive`, `typed-builder`, `tracing-attributes`) but it doesn't for some other ones (everything depending on `synstructure` and some others).
Now I am wondering:
Is it fundamentally impossible to provide the `From`-impls because `proc-macro` just doesn't exist in wasm, or would it be possible to do this transformation in some other way?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with proc-macro/src/lib.rs at the cited conversion area, then compare the cargo watt behavior with the patched syn-watt repository and the listed failing crates. Determine whether the requested conversions can be supported in wasm or require a different transformation; done means reaching a reproducible conclusion about the approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- compilers, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100