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

Proc macros are executed in the wrong working directory #7057

Closed
jonas-schievink opened this issue Dec 28, 2020 · 7 comments
Closed

Proc macros are executed in the wrong working directory #7057

jonas-schievink opened this issue Dec 28, 2020 · 7 comments
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now

Comments

@jonas-schievink
Copy link
Contributor

Reported in #7052 (comment), it seems like proc macros should be executed in the directory containing the invoking crate's main file (lib.rs/main.rs, or whatever would be passed to rustc as the crate root to compile).

@jonas-schievink jonas-schievink added the A-macro macro expansion label Dec 28, 2020
@edwin0cheng edwin0cheng added the S-actionable Someone could pick this issue up and work on it right now label Dec 28, 2020
@jonas-schievink
Copy link
Contributor Author

It seems fairly hard to obtain the correct directory, since that requires VFS access, and the compiler crates aren't really supposed to have that (they're mostly supposed to care only about FileId, but that isn't enough here). Since correctly expanding file!() etc. would require breaking through this abstraction anyways, maybe this is fine and needs to be changed anyways? cc @matklad

@edwin0cheng
Copy link
Member

edwin0cheng commented Dec 28, 2020

We already get the dylib path information from cargo-metadata and can we get crate root directory from that too ?

@jonas-schievink
Copy link
Contributor Author

We already know the crate root of the invoking crate (the root_file_id in CrateData), but it's stored as a FileId, and the compiler crates aren't supposed to know about actual paths. Seems like we have to make an exception for this, perhaps?

@flodiebold
Copy link
Member

I feel like this is a very similar thing as e.g. the env in the CrateData.

@edwin0cheng
Copy link
Member

edwin0cheng commented Jan 7, 2021

I just reread the bug reported in #7052 (comment) , the actual error is, the proc-macro cannot find the related env CARGO_MANIFEST_DIR variable to use for include!(concat!(..)) and it is fixed in #6820 by @jonas-schievink .

OTOH, what is working directory inside proc-macro in rustc ? And is it stable ?

@bjorn3
Copy link
Member

bjorn3 commented Jan 7, 2021

The working directory is whatever cargo chooses when running rustc. In the past this was the working directory cargo was invoked from. It was later changed to the root of the workspace. I don't think there are any explicit guarantees from cargo.

@flodiebold
Copy link
Member

Presumably fixed by #11353?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants