Use correct working directory for non-workspace proc-macro execution

This commit is contained in:
Mehul Arora 2025-02-12 14:43:25 -05:00
parent d10388096e
commit 3a31741627
15 changed files with 159 additions and 31 deletions

View file

@ -238,6 +238,9 @@ impl CustomProcMacroExpander {
let krate_graph = db.crate_graph();
// Proc macros have access to the environment variables of the invoking crate.
let env = &krate_graph[calling_crate].env;
let current_dir =
krate_graph[calling_crate].proc_macro_cwd.as_deref().map(ToString::to_string);
match proc_macro.expander.expand(
tt,
attr_arg,
@ -245,10 +248,7 @@ impl CustomProcMacroExpander {
def_site,
call_site,
mixed_site,
db.crate_workspace_data()[&calling_crate]
.proc_macro_cwd
.as_ref()
.map(ToString::to_string),
current_dir,
) {
Ok(t) => ExpandResult::ok(t),
Err(err) => match err {