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

Canonicalize CARGO_MANIFEST_DIR #5702

Closed

Conversation

golddranks
Copy link

@golddranks golddranks commented Aug 15, 2022

Objective

  • Usually cargo sets CARGO_MANIFEST_DIR, and it sets it as an absolute path.
  • However, the user might want to set it manually when running the built binary directly to point Bevy to the correct asset path.
  • In that scenario, it makes sense to accept relative paths also.
  • Currently FileAssetIo tends to crash with root set as relpath because of the same problem described here Filesystem watching crashes with symlinks pointing outside the asset folder #5689.

Solution

  • Canonicalize CARGO_MANIFEST_DIR when setting the root.

@golddranks golddranks force-pushed the canonicalize_cargo_manifest_dir branch from c615d97 to bf5b49d Compare August 15, 2022 11:48
@bjorn3
Copy link
Contributor

bjorn3 commented Aug 15, 2022

std::fs::canonicalize can fail on Windows. To be specific at least one ram disk program doesn't support it.

@golddranks
Copy link
Author

Thanks for pointing that out! In that case it makes sense to revert to the original path in case of a failure.

@golddranks golddranks force-pushed the canonicalize_cargo_manifest_dir branch 2 times, most recently from a5c1a20 to e3e0afe Compare August 15, 2022 13:21
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds labels Aug 15, 2022
@alice-i-cecile alice-i-cecile added the C-Usability A simple quality-of-life change that makes Bevy easier to use label Aug 15, 2022
@alice-i-cecile
Copy link
Member

Will this also fix #5689?

@golddranks
Copy link
Author

@alice-i-cecile Unfortunately, it doesn't. However, I'm planning to play around with canonicalize and the co. a bit and see if there is any easy solution.

@golddranks golddranks force-pushed the canonicalize_cargo_manifest_dir branch from e3e0afe to b1a786b Compare August 15, 2022 16:10
@golddranks
Copy link
Author

golddranks commented Aug 15, 2022

Hmm, I think I failed to understand what @bjorn3 meant; according to rust-lang/rust#59117 , canonicalized path names on Windows may cause problems even in cases the canonicalization itself succeeds. This made me to change the implementation once more: it now performs the canonicalization only if the path is relative. (AssetServer doesn't expect relative paths, so it only tries to fix cases that were already broken, so this shouldn't break anything that currently works.)

@golddranks
Copy link
Author

Once rust-lang/rust#92750 stabilizes, this should use it instead? (If relative paths are still unsupported by AssetServer at that point.)

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Aug 23, 2022
// Some Windows software don't support canonicalized path names, so let's avoid them
// unless the path is relative, in which case we currently need to make it absolute
// (See more: https://github.com/rust-lang/rust/issues/59117 )
if Path::new(&manifest_dir).is_relative() {
Copy link
Member

@cart cart Aug 24, 2022

Choose a reason for hiding this comment

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

I don't think overloading CARGO_MANIFEST_DIR with the responsibility of "configuring deployed app asset folder root relative paths" is the right path forward, especially if it is consistently an absolute path within the context of cargo. At the very least, we should have a new environment variable for this scenario.

However, I don't think we should be encouraging "user-configurable" asset roots at all by default. Asset path logic should be determined by the app developer, not the app consumer. The defaults will work in 99.99% of cases and forcing standardization here (by default) is valuable from a tooling and ecosystem perspective.

If you want your game to support non-standard user-configurable asset paths, I think the correct solution is to use AssetServerSettings::asset_folder (and maybe add a configurable custom_root_path: Option<PathBuf> to the settings). You could wire that up to whatever environment variable you choose. And you could use whatever path processing logic you want (ex: canonicalize).

@cart
Copy link
Member

cart commented Aug 30, 2022

Closing this as I've got strong opinions (see my comment above). But feel free keep the conversation going. Happy to listen to counterarguments.

@cart cart closed this Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants