@@ -717,6 +717,7 @@ fn cargo_to_crate_graph(
717
717
load_proc_macro,
718
718
& mut pkg_to_lib_crate,
719
719
& public_deps,
720
+ libproc_macro,
720
721
cargo,
721
722
& pkg_crates,
722
723
build_scripts,
@@ -782,6 +783,7 @@ fn handle_rustc_crates(
782
783
load_proc_macro : & mut dyn FnMut ( & str , & AbsPath ) -> ProcMacroLoadResult ,
783
784
pkg_to_lib_crate : & mut FxHashMap < Package , CrateId > ,
784
785
public_deps : & SysrootPublicDeps ,
786
+ libproc_macro : Option < CrateId > ,
785
787
cargo : & CargoWorkspace ,
786
788
pkg_crates : & FxHashMap < Package , Vec < ( CrateId , TargetKind ) > > ,
787
789
build_scripts : & WorkspaceBuildScripts ,
@@ -843,6 +845,19 @@ fn handle_rustc_crates(
843
845
rustc_workspace[ tgt] . is_proc_macro ,
844
846
) ;
845
847
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
+
846
861
// Add dependencies on core / std / alloc for this crate
847
862
public_deps. add ( crate_id, crate_graph) ;
848
863
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
0 commit comments