dtolnay / watt

Runtime for executing procedural macros as WebAssembly
Apache License 2.0
1.25k stars 29 forks source link

Cannot depend on crates that depends on procedural macro? #45

Open MashPlant opened 3 years ago

MashPlant commented 3 years ago

In my procedural macro, I need several crates that further depends on procedural macro. For example:

#[derive(serde::Deserialize)]
struct Config {
  ...
}

use proc_macro2::TokenStream;

#[no_mangle]
pub extern "C" fn the_macro(input: TokenStream) -> TokenStream {
    /* use struct Config to help manipulating TokenStream */
}

and in my Cargo.toml I have:

[lib]
crate-type = ["cdylib"]

[patch.crates-io]
proc-macro2 = { git = "https://github.com/dtolnay/watt" }

[dependencies]
serde = { version = "*", features = ["derive"] }

When I compile, I get:

$ cargo build --release --target wasm32-unknown-unknown
   Compiling serde v1.0.116
error: /home/mashplant/Code/CLionProjects/lalr1-wasm/target/release/deps/libserde_derive-cbe50235eb5bda1c.so: undefined symbol: print_panic
   --> /home/mashplant/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/serde-1.0.116/src/lib.rs:285:1
    |
285 | extern crate serde_derive;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `serde`
MashPlant commented 3 years ago

Note: I cannot simply replace

[patch.crates-io]
proc-macro2 = { git = "https://github.com/dtolnay/watt" }

with

[dependencies]
proc-macro2 = { git = "https://github.com/dtolnay/watt" }

either, because I also depend on syn and quote, which require the patched version of proc-macro2.

peter-lyons-kehl commented 3 years ago

Hi Chenhao @MashPlant,

Have you tried it with https://crates.io/crates/wa-serde-derive?

Also, watt is at https://crates.io/crates/watt now, so you can depend on it from there rather than from Github.