@@ -685,7 +685,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
685
685
686
686
match result {
687
687
( LoadResult :: Previous ( cnum) , None ) => {
688
- info ! ( "library for `{}` was loaded previously" , name) ;
688
+ info ! ( "library for `{}` was loaded previously, cnum {cnum} " , name) ;
689
689
// When `private_dep` is none, it indicates the directly dependent crate. If it is
690
690
// not specified by `--extern` on command line parameters, it may be
691
691
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
@@ -1031,6 +1031,39 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1031
1031
}
1032
1032
}
1033
1033
1034
+ fn inject_compiler_builtins ( & mut self , krate : & ast:: Crate ) {
1035
+ if attr:: contains_name ( & krate. attrs , sym:: compiler_builtins)
1036
+ || attr:: contains_name ( & krate. attrs , sym:: no_core)
1037
+ {
1038
+ // `compiler_builtins` does not get extern builtins, nor do `#![no_core]` crates
1039
+ info ! ( "`compiler_builtins` unneeded" ) ;
1040
+ return ;
1041
+ }
1042
+
1043
+ for ( cnum, cmeta) in self . cstore . iter_crate_data ( ) {
1044
+ if cmeta. is_compiler_builtins ( ) {
1045
+ info ! ( "`compiler_builtins` already exists (cnum = {cnum}); skipping injection" ) ;
1046
+ return ;
1047
+ }
1048
+ }
1049
+
1050
+ let Ok ( cnum) = self . maybe_resolve_crate (
1051
+ sym:: compiler_builtins,
1052
+ CrateDepKind :: Implicit ,
1053
+ CrateOrigin :: Injected ,
1054
+ ) else {
1055
+ info ! ( "`compiler_builtins` not resolved" ) ;
1056
+ return ;
1057
+ } ;
1058
+
1059
+ let cmeta = self . cstore . get_crate_data ( cnum) ;
1060
+
1061
+ // Sanity check the loaded crate to ensure it is indeed compiler_builtins
1062
+ if !cmeta. is_compiler_builtins ( ) {
1063
+ self . dcx ( ) . emit_err ( errors:: CrateNotCompilerBuiltins { crate_name : cmeta. name ( ) } ) ;
1064
+ }
1065
+ }
1066
+
1034
1067
fn inject_dependency_if (
1035
1068
& mut self ,
1036
1069
krate : CrateNum ,
@@ -1140,6 +1173,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1140
1173
}
1141
1174
1142
1175
pub fn postprocess ( & mut self , krate : & ast:: Crate ) {
1176
+ info ! ( "POSTPROCESS" ) ;
1177
+ self . inject_compiler_builtins ( krate) ;
1143
1178
self . inject_forced_externs ( ) ;
1144
1179
self . inject_profiler_runtime ( ) ;
1145
1180
self . inject_allocator_crate ( krate) ;
@@ -1171,12 +1206,18 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1171
1206
}
1172
1207
None => item. ident . name ,
1173
1208
} ;
1209
+
1174
1210
let dep_kind = if attr:: contains_name ( & item. attrs , sym:: no_link) {
1175
1211
CrateDepKind :: MacrosOnly
1176
1212
} else {
1177
1213
CrateDepKind :: Explicit
1178
1214
} ;
1179
1215
1216
+ if name == sym:: compiler_builtins {
1217
+ info ! ( "BUILTINS DETECTED dep_kind {dep_kind:?}" ) ;
1218
+ return None ;
1219
+ }
1220
+
1180
1221
let cnum = self . resolve_crate ( name, item. span , dep_kind, CrateOrigin :: AstExtern ) ?;
1181
1222
1182
1223
let path_len = definitions. def_path ( def_id) . data . len ( ) ;
0 commit comments