`pathfinder_gpu::FilesystemResourceLoader`, packaging, and location search strategies
I have a minimal test put together. When creating the FilesystemResourceLoader, this panic occurs:
thread 'main' panicked at 'No suitable `resources/` directory found!', C:\Users\adamn\.cargo\git\checkouts\pathfinder-f0bd20e7aa700f92\f89ed90\gpu\src\resources.rs:54:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Based on the code for locate, this looks in the current directory and all of its parents for a resources directory from which to load shaders, textures, etc. This clearly works well in-tree, but it will be problematic to run all of my tests from within a vendored pathfinder directory as I'd prefer to use upstream git revisions in Cargo.toml instead of a local checkout. I suspect that this search strategy will present an obstacle to publishing to crates.io. Not trying to throw stones, y'all are definitely aware of limitations here 😸 .
Do you have a plan for handling this in the future, especially w.r.t. packaging apps which use pathfinder? If the resources are small and used by most pathfinder dependents, I'd perhaps be interested in an option to include_bytes the resources. Not sure whether that's feasible.
EDIT: On a re-read, it occurs to me that I forgot to phrase the follow-up question: or should I just implement the trait myself?
I build a small resource loader that compiles everything into pathfinder… maybe it is useful? (code + build script). It could possibly benefit from some compression
It's very useful! Thank you.
I did a search and it looks like https://crates.io/crates/include-flate was recently published. If I make this work for my needs I'm thinking it's worth sending a PR here behind a feature gate. What do you think?
I'm also curious whether you have thoughts about buildscript vs. proc macro. A proc macro is perhaps a little sketchy, but it would avoid adding a build.rs pass for users who have different resource loaders.
I think what could work, is to turn pathfinder/resources into a crate. Ideally it would have a bunch of data that can be combined with the Add operator to allow something like: resources::SHADERS + resources::FONTS. For the lazy ones there would be resources::ALL.
The main reason for this is that I don't want to have to trigger recompiles when I modify shaders. WebRender did something similar. But I realize it can be inconvenient, so I'm open to ideas for better things to do here.
I like Rust Embed https://crates.io/crates/rust-embed. It leaves the resources in the filesystem for debug builds, but embeds them for release builds.
@Slyklaw seems like a good idea.
@pcwalton: I tried to use it from crates.io but I've got the same message: thread 'main' panicked at 'No suitable resources/ directory found!', /Users/florian.blasius/.cargo/registry/src/github.com-1ecc6299db9ec823/pathfinder_resources-0.5.0/src/fs.rs:47:9. How can I bring it to work?
The main reason for this is that I don't want to have to trigger recompiles when I modify shaders.
I actually didn't find that it makes a big impact (assuming incremental compilation).
I'm also trying this out from crates.io and stumble upon this issue. This should definitely be fixes as it makes it hard to include pathfinder in external apps as a crate. I would not care having to recompile when shaders change, user crates won't probably change shaders that often, right?
This is what the EmbeddedResourceLoader is for. Does it work for you?
@pcwalton thanks for mentioning EmbeddedResourceLoader, i didn't realize it existed. the project i started on was cargo culted from one of the things in examples/. would you be open to switching to EmbeddedResourceLoader in the examples so others don't hit this? i can make that change if so
@frewsxcv Sure, works for me.
Opened a pull request here: https://github.com/servo/pathfinder/pull/330