vulkano
vulkano copied to clipboard
Using shader! macro through other crates without importing vulkano
I have a crate I wrote for myself to use across multiple projects for graphics that uses vulkano, however the shader macro will not run as the compiler cannot fund vulkano in the list of imported crates, is there a workaround for this, or will I have to import vulkano into every project along with my crate?
Use statement in my crate:
pub use vulkano_shaders::shader;
Shader code in my project:
mod fs {
graphics::shader!{
ty: "fragment",
path: "assets/shaders/frag.glsl"
}
}
Error produced when run:
error[E0433]: failed to resolve: could not find `vulkano` in the list of imported crates
--> src/heightmap_erosion/mod.rs:13:5
|
13 | / graphics::shader!{
14 | | ty: "vertex",
15 | | path: "assets/shaders/heightmap_vert.glsl",
16 | | include: ["assets/shaders/include/light_maths.glsl"]
17 | | }
| |_____^ could not find `vulkano` in the list of imported crates
|
= note: this error originates in the macro `graphics::shader` (in Nightly builds, run with -Z macro-backtrace for more info)
If you look at the macro's expansion, there's quite a few types from vulkano that it uses. What would you expect the macro to generate without using vulkano?
Ah my bad, I think I misread your question. Your only concern is that you have to add vulkano
to your Cargo.toml
s correct?
Yes that is correct
My thinking was that since it is in the list of dependencies for my crate it would be able to generate but I'm assuming that is not the case?
Yes that is correct
I see, I'm sorry for by inability to read haha. This is an age old problem with proc macros in general, and I'm not sure if it's solvable.
My thinking was that since it is in the list of dependencies for my crate it would be able to generate but I'm assuming that is not the case?
Unortunately not. The place where the code is generated is in a downstream crate, and so if we generate types from the vulkano crate, that downstream crate must include it in its dependencies (just like in any other cicumstance, it's just that the code is generated in this case).
I'll do some testing with what I have in mind, maybe it'll work.
I don't think it's possible unfortunately. Even if we provided some way for a crate to configure where to find vulkano (e.g. re-exported from another crate), unless I'm mistaken there's still no (non-cursed) way to provide such a configuration without the user's involvement.