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

Fails to compile if proc-macro2 is a dependency #125

Closed
lukaslueg opened this issue Jul 25, 2018 · 4 comments
Closed

Fails to compile if proc-macro2 is a dependency #125

lukaslueg opened this issue Jul 25, 2018 · 4 comments

Comments

@lukaslueg
Copy link

I'm unsure which tree to bark up against, so I'm reporting this here:

If a crate has a dependency on proc-macro2 (any version, currently resolved to 0.4.9), compilation via cargo web build (on 0.6.4) fails with can't find crate for 'proc_macro' while compiling proc-macro2. The offending line in proc-macro2 is extern crate proc_macro;.

It fails for all targets, except native targets, on stable and nightly-2018-07-23.

@koute
Copy link
Owner

koute commented Jul 25, 2018

This happens because the proc_macro crate is not distributed for the asmjs/wasm targets, i.e. here we have it:

$ ls ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib | grep proc_macro
libproc_macro-1ea4ba9e4f6cdbc1.so

and here we don't:

$ ls ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib | grep proc_macro

You can easily reproduce this issue using only cargo:

$ cargo new foobar
$ cd foobar
$ echo 'proc-macro2 = "*"' >> Cargo.toml
$ cargo build --target=wasm32-unknown-unknown
   Compiling unicode-xid v0.1.0                                                                                                                                                                                                              
   Compiling proc-macro2 v0.4.9
error[E0463]: can't find crate for `proc_macro`
  --> /home/kou/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.9/src/lib.rs:50:1
   |
50 | extern crate proc_macro;
   | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

So if this is a problem for you then you should report it as an Rust issue.

However, why would you actually want to use the proc_macro2 crate with the web targets? AFAIK that crate is only useful when writing procedural plugins which use your native target instead of the one for which you're compiling for.

@lukaslueg
Copy link
Author

proc_macro was being pulled in due to a dependency on syn, which pulled proc_macro2, which pulled in proc_macro. There is a knob in syn to turn this off, so problem solved for now.

@lukaslueg
Copy link
Author

Reopening because I still think it's a bug with cargo-web:

This builds using cargo web build

[dependencies]
proc-macro2 = { version = "0.4", default_features = false }

This also builds using cargo web build

[dependencies]
stdweb = { version = "0.4" }

But with both dependencies

[dependencies]
proc-macro2 = { version = "0.4", default_features = false }
stdweb = { version = "0.4" }

... cargo web build fails due to missing proc_macro-crate. It does, however, build using cargo build.

@lukaslueg lukaslueg reopened this Jul 29, 2018
@lukaslueg
Copy link
Author

Re-closing because after some tinkering I now think it's actually cargo's fault :-/

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