Description
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,
- 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?
- 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.