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

Relative paths #11

Open
anowell opened this issue Feb 8, 2017 · 4 comments
Open

Relative paths #11

anowell opened this issue Feb 8, 2017 · 4 comments

Comments

@anowell
Copy link

anowell commented Feb 8, 2017

When I move modules around, I end up breaking Bart rendered components because of the path being relative to crate root. It might just be that I also happen to be using a lot of include_str! which has me used to using paths relative to the file that invokes the macro, but I find relative paths to be a bit nicer. On the flip side, someone with all their templates in a root templates dir would probably feel the opposite, so take this with a grain of salt. I wonder if you could use a prefix / to indicate crate root.

(feel free to disregard/close.. just sharing feedback)

@maghoff
Copy link
Owner

maghoff commented Feb 8, 2017

The crux here seems to be that I don't know how to implement relative include paths. My preference is to relative paths as well. Leading / for crate root would probably also be a nice feature.

I have not been able to figure out which rust source file is currently being compiled when the procedural macro gets executed, so the only thing I have to go by is the current working directory, which is the crate root.

@maghoff maghoff changed the title Feedback: relative paths Relative paths Feb 8, 2017
@maghoff
Copy link
Owner

maghoff commented Dec 7, 2018

Hm, maybe https://www.reddit.com/r/rust/comments/a3fgp6/procmacro_determining_the_callers_module_path/ is a lead. I would first need to get hold of a Span. Maybe I could go token_stream.iter().next().unwrap().span().call_site().source_file() or something like that.

Note: source_file() is experimental (rust-lang/rust#54725)

@TheButlah
Copy link

TheButlah commented Apr 5, 2022

Just discovered this, maybe its helpful. It doesn't work on the current version of Rust but I've submitted a pr to fix it.

Its also very cursed.

@maghoff
Copy link
Owner

maghoff commented Apr 5, 2022

@TheButlah Ah, cool. Definitely something for me to keep an eye on. Not too stoked about using nightly, but thank you for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants