Skip to content

Feat/wesl-toml#185

Merged
k2d222 merged 18 commits into
webgpu-tools:mainfrom
mighdoll:feat/wesl-toml
Mar 21, 2026
Merged

Feat/wesl-toml#185
k2d222 merged 18 commits into
webgpu-tools:mainfrom
mighdoll:feat/wesl-toml

Conversation

@mighdoll

@mighdoll mighdoll commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

PkgBuilder::scan_toml() builds packages from config.

fix for #149

and fix build warning

Comment thread crates/wesl/src/wesl_toml.rs Outdated
Comment thread crates/wesl/src/wesl_toml.rs Outdated
Comment thread crates/wesl/src/wesl_toml.rs Outdated
Comment thread crates/wesl/src/wesl_toml.rs

let pattern_str = pattern_path.to_string_lossy();
let glob_iter =
glob::glob(&pattern_str).map_err(|e| ScanTomlError::InvalidGlob(pattern.clone(), e))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot actually use the glob library for finding all relevant wesl files. We have two requirements

  • One shouldn't visit the same file twice
  • Excluded directories should be completely skipped

The first requirement is not straightforward to pull off, since we start out with an array of globs. Here's an example of a nasty user input ["./shaders/**/*", "./shaders/../shaders/*", "./shaders/foo/*"]

One way of correctly doing it is with the algorithm from here webgpu-tools/wesl-spec#172

And since we cannot really use the glob library, we shouldn't be including it just to validate the globs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluded directories are skipped in the end, see isExcluded, though doing it after the fact is inefficient.

Visiting a file twice during scanning nasty user input doesn't seem tragic. The current implementation deduplicates, so multiple paths shouldn't be reported, though I see there's a quick fix needed there for the pathological case.

I can also try a fix with the more custom scanning approach. That would be a bit more efficient at runtime, and give us a base for whatever we decide on spec #172. I suppose it'll be a fair bit more code than relying on glob to do most the work, so we could make that a separate PR depending on what y'all prefer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think addressed the other suggestions but perhaps best to defer this one? That'll keep this largish PR from growing even larger. Scanning efficiency improvements and an implementation for spec#172 would go well together.

@mighdoll

mighdoll commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

added **/node_modules as the default to exclude: as discussed in spec#172

@k2d222 k2d222 linked an issue Feb 10, 2026 that may be closed by this pull request
@k2d222

k2d222 commented Feb 10, 2026

Copy link
Copy Markdown
Collaborator

@mighdoll I've combined your representation layout with the stricter one I used in branch wesl-toml. I delegate parsing to intermediate types with to/from conversion functions for the parts which don't fit easily serde's data model (in particular dependencies). Didn't touch the scanning logic which looks good.

The PR is ready to review

@mighdoll mighdoll left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k2d222 the changes look good me, thx for the lessons. They pass the tests upstream on https://github.com/mighdoll/lygia/tree/feat/cargo too.

@mighdoll

Copy link
Copy Markdown
Contributor Author

what's next for this PR? I hope I didn't do something wrong with the gh wrangling.. is there more to discuss or implement?

@k2d222 k2d222 linked an issue Mar 18, 2026 that may be closed by this pull request
@k2d222

k2d222 commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

looks good to me!

I added one fix for #149: sub-dependencies are renamed foo/bar during the process, when merging paths we should only consider the last segment to check if it's an import from the current package.

@mighdoll

Copy link
Copy Markdown
Contributor Author

awesome and I will dbl check the draft lygia cargo branch too

Comment thread crates/wesl/src/package.rs Outdated
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct WeslToml {
/// Package configuration.
#[serde(flatten)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package fields in wesl.toml are flattened.

package fields are flattened into the wesl.toml root
@k2d222 k2d222 merged commit be95efd into webgpu-tools:main Mar 21, 2026
10 checks passed
mighdoll added a commit to mighdoll/wesl-rs that referenced this pull request Mar 23, 2026
webgpu-tools#185 includes a test case for a pathological wesl.toml config with overlapping globs

previously, we deduplicated for that by using canonical fs paths, following symlinks
to absolute paths. But pnpm uses symlinks inside node_modules/,
so absolute paths might not match user exclude paths in wesl.toml. This broke in
lygia when I was using a link: dependency for development.

In this commit we switch to using lexical path normalization for deduplication,
processing '.' and '..' in paths. That way user exclude paths match.

And if a user wants to intentionally duplicate a file or path with a symlink,
they can now do that too.
k2d222 pushed a commit that referenced this pull request May 19, 2026
* fix for wesl.toml glob dedup w/o following symlinks

#185 includes a test case for a pathological wesl.toml config with overlapping globs

previously, we deduplicated for that by using canonical fs paths, following symlinks
to absolute paths. But pnpm uses symlinks inside node_modules/,
so absolute paths might not match user exclude paths in wesl.toml. This broke in
lygia when I was using a link: dependency for development.

In this commit we switch to using lexical path normalization for deduplication,
processing '.' and '..' in paths. That way user exclude paths match.

And if a user wants to intentionally duplicate a file or path with a symlink,
they can now do that too.

* Replace glob expansion with directory walk to support nested wesl.toml

* fmt

* use Path::absolute on wesl.toml root path

intead of manually stripping ./

* simplify error report during stack walk
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

Successfully merging this pull request may close these issues.

self-reference package imports

3 participants