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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/bevy_asset/src/io/file_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ impl FileAssetIo {
/// instead. It's set by cargo when running with `cargo run`.
pub fn get_base_path() -> PathBuf {
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
PathBuf::from(manifest_dir)
// 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).

fs::canonicalize(&manifest_dir).unwrap_or_else(|_| PathBuf::from(manifest_dir))
} else {
PathBuf::from(manifest_dir)
}
} else {
env::current_exe()
.map(|path| {
Expand Down