wgsl-tooling-wg / wesl-spec

A set of well-specified language extensions and tools for WGSL
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

allow .wgsl/.wesl file suffixes in path? #12

Open mighdoll opened 2 weeks ago

mighdoll commented 2 weeks ago

Ought we allow import ./foo/bar.wgsl/zip;? (with the .wgsl suffix attached)

Usually import ./foo/bar/zip; will suffice, but that allowing suffixes would allow distinguishing bar.wgsl from bar.wesl, or importing from bar.wesl.orig.

k2d222 commented 1 week ago

I would like to not allow importing with the wesl extension.

If at some point we want to import other types of files e.g. wgsl, glsl, hlsl, spv, slang etc then it would make sense to me that we allow an unrestricted import syntax.

We probably don't want to standardize what types of files can be imported, because it would be an implementation burden and there is too many file types.

The syntax could allow arbitrary import identifiers as string literals. Then it's up to the linker to support them. It means that using them leads to implementation-dependent code. But it would allow stuff like

import "foo.hlsl"/{my_fn, my_struct};
import "https://example.com/shader.glsl";

import "codegen:compilation_timestamp" as compile_date; // an u32 containing the unix timestamp when the module was linked, good for versionning

import "runtime:hot_reload_if_changed"; // a directive to the runtime to watch file changes and hot-reload

import "rng"/random_int;
import "randomized_test_cases"; // randomized testing!

Which is close to my heart for arbitrary code injection ♥️

Sorry I realize I side-tracked a lot 🥶

mighdoll commented 1 week ago

re: a permissive syntax for importing all sorts of other things, perhaps useful to distinguish between libraries and apps.

For example, allowing an import from a rust or typescript code generator to produce would just fine for one app, but we wouldn't want a library user to need a rust/typescript code generator to use a wgsl library.

I allow importing from code generators written in typescript in the previous rev of the wgsl-linker, but I'm hoping we can find for libraries to find any needed flexibility in other ways.

mighdoll commented 1 week ago

allowing the importing other things is mostly orthogonal to the issue of allowing explicit importing of foo.wgsl and foo.wesl, or foo.wgsl.orig.

I'm not arguing hard for this feature, though, seems mostly like a corner case.

I think my current code tries matching full file names and then matching with the suffixes dropped, and so I raised this issue to clarify the corner cases.

mighdoll commented 6 hours ago

consensus is to leave the file suffixes implicit in import paths.

i.e. we expect the file suffix to be .wesl (or .wgsl if #26 is accepted.)