From 870825b3761c1dde188dd881b3d4223c39a738c3 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 1 Oct 2022 21:29:14 +0200 Subject: [PATCH] Add proc-macro dependency to rustc crates --- crates/project-model/src/workspace.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 72ddf809288..8c3e8681d98 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -717,6 +717,7 @@ fn cargo_to_crate_graph( load_proc_macro, &mut pkg_to_lib_crate, &public_deps, + libproc_macro, cargo, &pkg_crates, build_scripts, @@ -782,6 +783,7 @@ fn handle_rustc_crates( load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult, pkg_to_lib_crate: &mut FxHashMap, public_deps: &SysrootPublicDeps, + libproc_macro: Option, cargo: &CargoWorkspace, pkg_crates: &FxHashMap>, build_scripts: &WorkspaceBuildScripts, @@ -843,6 +845,19 @@ fn handle_rustc_crates( rustc_workspace[tgt].is_proc_macro, ); pkg_to_lib_crate.insert(pkg, crate_id); + + // Even crates that don't set proc-macro = true are allowed to depend on proc_macro + // (just none of the APIs work when called outside of a proc macro). + if let Some(proc_macro) = libproc_macro { + add_dep_with_prelude( + crate_graph, + crate_id, + CrateName::new("proc_macro").unwrap(), + proc_macro, + cargo[tgt].is_proc_macro, + ); + } + // Add dependencies on core / std / alloc for this crate public_deps.add(crate_id, crate_graph); rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);