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

Using shader! macro through other crates without importing vulkano #2255

Open
hindlet opened this issue Jul 7, 2023 · 6 comments
Open

Using shader! macro through other crates without importing vulkano #2255

hindlet opened this issue Jul 7, 2023 · 6 comments

Comments

@hindlet
Copy link

hindlet commented Jul 7, 2023

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)
@marc0246
Copy link
Contributor

marc0246 commented Jul 8, 2023

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
Copy link
Contributor

marc0246 commented Jul 8, 2023

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

@hindlet
Copy link
Author

hindlet commented Jul 8, 2023

Yes that is correct

@hindlet
Copy link
Author

hindlet commented Jul 8, 2023

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?

@marc0246
Copy link
Contributor

marc0246 commented Jul 8, 2023

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
Copy link
Contributor

marc0246 commented Jul 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants