vulkano icon indicating copy to clipboard operation
vulkano copied to clipboard

Using shader! macro through other crates without importing vulkano

Open hindlet opened this issue 1 year ago • 6 comments

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)

hindlet avatar Jul 07 '23 22:07 hindlet

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?

marc0246 avatar Jul 08 '23 03:07 marc0246

Ah my bad, I think I misread your question. Your only concern is that you have to add vulkano to your Cargo.tomls correct?

marc0246 avatar Jul 08 '23 04:07 marc0246

Yes that is correct

hindlet avatar Jul 08 '23 07:07 hindlet

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?

hindlet avatar Jul 08 '23 07:07 hindlet

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.

marc0246 avatar Jul 08 '23 07:07 marc0246

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.

marc0246 avatar Jul 08 '23 08:07 marc0246