Skip to content

Commit 870825b

Browse files
committed
Add proc-macro dependency to rustc crates
1 parent cdc5493 commit 870825b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/project-model/src/workspace.rs

+15
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ fn cargo_to_crate_graph(
717717
load_proc_macro,
718718
&mut pkg_to_lib_crate,
719719
&public_deps,
720+
libproc_macro,
720721
cargo,
721722
&pkg_crates,
722723
build_scripts,
@@ -782,6 +783,7 @@ fn handle_rustc_crates(
782783
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult,
783784
pkg_to_lib_crate: &mut FxHashMap<Package, CrateId>,
784785
public_deps: &SysrootPublicDeps,
786+
libproc_macro: Option<CrateId>,
785787
cargo: &CargoWorkspace,
786788
pkg_crates: &FxHashMap<Package, Vec<(CrateId, TargetKind)>>,
787789
build_scripts: &WorkspaceBuildScripts,
@@ -843,6 +845,19 @@ fn handle_rustc_crates(
843845
rustc_workspace[tgt].is_proc_macro,
844846
);
845847
pkg_to_lib_crate.insert(pkg, crate_id);
848+
849+
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
850+
// (just none of the APIs work when called outside of a proc macro).
851+
if let Some(proc_macro) = libproc_macro {
852+
add_dep_with_prelude(
853+
crate_graph,
854+
crate_id,
855+
CrateName::new("proc_macro").unwrap(),
856+
proc_macro,
857+
cargo[tgt].is_proc_macro,
858+
);
859+
}
860+
846861
// Add dependencies on core / std / alloc for this crate
847862
public_deps.add(crate_id, crate_graph);
848863
rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);

0 commit comments

Comments
 (0)