I have a proc macro that needs to read files relative to the caller location:
// main_crate/src/lib.rd
use other_crate::my_proc_macro;
my_proc_macro!(file1, file2)
This would mean the proc macto needs to read main_crate/some_dir/file1.txt
and main_crate/some_dir/file2.txt
. When To do this properly so it can be used as a dependency, I need to know the absolute path to main_crate
when running my_proc_macro
to be able to generate constants.
I don't think I can use the #[track_caller]
attribute because that wouldn't give me an absolute path and would be run after the proc macro has finished. I also can't use include_str!
because that's expanded after the proc macro is finished. Same issue with file!
.
Thanks in advance