Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cargo watt subcommand #41

@jakobhellermann

Description

@jakobhellermann

I made a cargo subcommand called 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

#[proc_macro]
pub fn the_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    /* ... */
}

with

#[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<proc_macro::TokenStream> does not exist in wasm.

So my solution was to just replace the TokenStreams and hope for the best, while also using a patched version of syn 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions