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

#import "file" without list of names should err/warn #97

Open
kornelski opened this issue Jul 5, 2024 · 7 comments
Open

#import "file" without list of names should err/warn #97

kornelski opened this issue Jul 5, 2024 · 7 comments

Comments

@kornelski
Copy link

Import with a file path, but without a list of names, "fails" silently:

#import "common.wgsl"

This syntax is very similar to C's #include that just imports everything, so I did not think of specifying individual type names, and was puzzled why this directive doesn't seem to do anything, and doesn't even cause a compilation error.

@robtfm
Copy link
Collaborator

robtfm commented Jul 5, 2024

It would make sense for this to be an “unused” warning.

It isn’t failing, it’s just not necessary since we added the ability to refer to fully qualified items without importing.

If you don’t import any items you’re importing the module, which means you can use items from it with mod::item syntax. But since you can refer to fully qualified items directly there’s never a need to import top-level modules. It can still be useful to import nested modules (#import a::b and then b::item).
we also don’t currently support import mod::* which is what you want from the sounds of it. That’s also something I’d like to add in future.

@robtfm
Copy link
Collaborator

robtfm commented Jul 5, 2024

Oh, also to note, particularly for custom bevy shaders which are quoted like your “common.wgsl” it’s useful to alias them - #import “common.wgsl” as common and let x = common::func() is nicer than having let x = “common.wgsl”::func() which is pretty clunky.

@kornelski
Copy link
Author

I didn't even know such syntax existed. The readme doesn't explain the "file" case.

@robtfm
Copy link
Collaborator

robtfm commented Jul 5, 2024

Which bit is not explained? I thought it was all in there.

@kornelski
Copy link
Author

The readme has examples for #import predefined::name, but zero uses of #import "./path".

https://docs.rs/naga_oil/ has nothing about imports and looks empty.

@robtfm
Copy link
Collaborator

robtfm commented Jul 5, 2024

Ah, right. The treatment/resolution of quoted names is bevy-specific, naga oil itself doesn’t treat quoted names any differently.

@kornelski
Copy link
Author

Do you think naga should get a first-class support for path names, or should complain about handling of these to Bevy?

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