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

Cargo doesn't pass rustc correct compile flags when using compiler plugins & cross-compiling #3343

Closed
golddranks opened this issue Nov 29, 2016 · 2 comments

Comments

@golddranks
Copy link
Contributor

golddranks commented Nov 29, 2016

I have a project that uses Diesel and diesel_codegen crate to implement a database schema compile-time. As of late, I refactored my project into two crates. The crate with compiler plugins is a library (ganbare_backend). My binary crate (ganbare) doesn't refer to diesel or diesel_codegen directly in Cargo.toml. However, when cross-compiling this project to a Musl target, the build fails:

error[E0463]: can't find crate for `diesel_codegen` which `ganbare_backend` depends on
 --> src/main.rs:7:1
  |
7 | pub extern crate ganbare_backend;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

When I compile with --verbose, I find out that the libdiesel_codegen-<HASH>.so, the plugin, isn't passed to rustc – it is passed however when compiling ganbare_backend. If I declare diesel_codegen in Cargo.toml and use extern crate in ganbare too, the compiler flags are passed and the build works.

What's notable is that Cargo doesn't pass the plugin when compiling to native target, either. However for reasons unclear to me, the build doesn't fail in that case. It would be enlightening if somebody could tell me,

  1. if some dependency uses compiler plugins, are the plugins needed also, when compiling the final binary, not only that dependency? That is, should ganbare expect to have access to the compiler plugin?
  2. if the compiler plugin is needed by the final binary, but the path isn't passed by Cargo, does rustc use some probing mechanism to be able to find it?

Either way, there's something funny. If the compiler plugin isn't needed, why does the build fail? On the other hand, if it is, why doesn't Cargo pass the flag to help rustc locate it?

Also, the error message is a bit funny too. It says (while compiling ganbare, that doesn't even depend on it directly) that it can't find diesel_codegen, yet it says "can't find crate" about the ganbare_backend. Judging from the passed flags, it IS able to find ganbare_backend.

@alexcrichton
Copy link
Member

I believe this was a recent nightly regression and should be fixed by #3335

@golddranks
Copy link
Contributor Author

Great to hear. I'll close this when that lands and if it works.

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