-
Notifications
You must be signed in to change notification settings - Fork 1
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
debug mode on linux does not load assets from relative paths #10
Comments
Glad the library is of help! You're using the standard field In that case, if If Possible solutions, but it depends on your overall problem:
Let me know if that helps. |
Hmm, quite unintuitive. Especially seeing as my Windows workaround in #11 (which was unable to find any of the paths at compile-time) does relative path lookup at runtime. Perhaps to shed some light on my use-case. I have an artist collaborator that is on Windows, while I compile everything on Linux (even the Windows binaries) and was in fact never able to even get Rust compilation working on Windows itself. Maybe I try out the env var, but it’s basically same amount of effort as symlinking. |
This can’t be right, or? I wouldn’t have any |
Agreed, it can be confusing. The reason for this has to do with the library generating code that contains Note that the standard field So, a But a custom macro_rules! my_initialize {
($relative_path:literal, $absolute_path:literal) => {
Asset {
my_get_str: {
fn get() -> std::borrow::Cow<'static, str> {
if cfg!(debug_assertions) {
// Nota bene:
std::fs::read_to_string($relative_path).unwrap().into()
} else {
include_str!($absolute_path).into()
}
}
get
},
}
};
}
#[iftree::include_file_tree(
"
debug = true
paths = '/my_assets/**'
template.initializer = 'my_initialize'
"
)]
pub struct Asset {
my_get_str: fn() -> std::borrow::Cow<'static, str>,
}
fn main() {
eprintln!("---\n{DEBUG}\n---");
use base::my_assets;
println!("my_assets/my_file: {:?}", (my_assets::MY_FILE.my_get_str)());
} Demo:
You can use By the way, in this context forward slashes |
Closing this. Feel free to reopen if not addressed adequately. |
Hey there, thank you for this cool library.
I have noticed one issue when running debug build on Linux, specifically what is profile "live" here.
I am building on Linux, then moving the executable into a different folder with different assets.
E.g.
In this case,
executable
will not load assets relative tomy_different_env
, but it will still load all assets relative to~/projects/my_project/
! Meaning it probably uses absolute system paths - although in the ifree macro invocations I am only using relative paths.Interestingly, if I cross-build for windows (
--target x86_64-pc-windows-gnu
) the produced executable has the correct behavior when I move it to a Windows PC and run it there. (But I am cross-compiling for windows with some adjustment, see #11, so this may be due to the fact that the paths in Windows case are impossible to resolve at build time.)On Linux, I only figured out a workaround, if e.g. my assets are in
~/projects/my_project/assets
, then I can temporarily rename that foldermv assets __assets
, and link the desiredln -s ~/my_different_env/assets ~/projects/my_project/assets
.The text was updated successfully, but these errors were encountered: