@@ -30,10 +30,11 @@ use rustc_resolve::Resolver;
30
30
use rustc_session:: config:: { CrateType , Input , OutFileName , OutputFilenames , OutputType } ;
31
31
use rustc_session:: cstore:: Untracked ;
32
32
use rustc_session:: output:: { collect_crate_types, filename_for_input} ;
33
+ use rustc_session:: parse:: feature_err;
33
34
use rustc_session:: search_paths:: PathKind ;
34
35
use rustc_session:: { Limit , Session } ;
35
36
use rustc_span:: {
36
- ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
37
+ DUMMY_SP , ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
37
38
} ;
38
39
use rustc_target:: spec:: PanicStrategy ;
39
40
use rustc_trait_selection:: traits;
@@ -236,6 +237,7 @@ fn configure_and_expand(
236
237
sess,
237
238
features,
238
239
& krate,
240
+ tcx. is_sdylib_interface_build ( ) ,
239
241
resolver. lint_buffer ( ) ,
240
242
)
241
243
} ) ;
@@ -252,6 +254,9 @@ fn configure_and_expand(
252
254
sess. dcx ( ) . emit_err ( errors:: MixedProcMacroCrate ) ;
253
255
}
254
256
}
257
+ if crate_types. contains ( & CrateType :: Sdylib ) && !tcx. features ( ) . export ( ) {
258
+ feature_err ( sess, sym:: export, DUMMY_SP , "`sdylib` crate type is unstable" ) . emit ( ) ;
259
+ }
255
260
256
261
if is_proc_macro_crate && sess. panic_strategy ( ) == PanicStrategy :: Abort {
257
262
sess. dcx ( ) . emit_warn ( errors:: ProcMacroCratePanicAbort ) ;
@@ -741,6 +746,25 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {
741
746
}
742
747
}
743
748
749
+ pub fn write_interface < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
750
+ if !tcx. crate_types ( ) . contains ( & rustc_session:: config:: CrateType :: Sdylib ) {
751
+ return ;
752
+ }
753
+ let _timer = tcx. sess . timer ( "write_interface" ) ;
754
+ let ( _, krate) = & * tcx. resolver_for_lowering ( ) . borrow ( ) ;
755
+
756
+ let krate = rustc_ast_pretty:: pprust:: print_crate_as_interface (
757
+ krate,
758
+ tcx. sess . psess . edition ,
759
+ & tcx. sess . psess . attr_id_generator ,
760
+ ) ;
761
+ let export_output = tcx. output_filenames ( ( ) ) . interface_path ( ) ;
762
+ let mut file = fs:: File :: create_buffered ( export_output) . unwrap ( ) ;
763
+ if let Err ( err) = write ! ( file, "{}" , krate) {
764
+ tcx. dcx ( ) . fatal ( format ! ( "error writing interface file: {}" , err) ) ;
765
+ }
766
+ }
767
+
744
768
pub static DEFAULT_QUERY_PROVIDERS : LazyLock < Providers > = LazyLock :: new ( || {
745
769
let providers = & mut Providers :: default ( ) ;
746
770
providers. analysis = analysis;
@@ -913,6 +937,8 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
913
937
CStore :: from_tcx( tcx) . report_unused_deps( tcx) ;
914
938
} ,
915
939
{
940
+ tcx. ensure_ok( ) . exportable_items( LOCAL_CRATE ) ;
941
+ tcx. ensure_ok( ) . stable_order_of_exportable_impls( LOCAL_CRATE ) ;
916
942
tcx. par_hir_for_each_module( |module| {
917
943
tcx. ensure_ok( ) . check_mod_loops( module) ;
918
944
tcx. ensure_ok( ) . check_mod_attrs( module) ;
0 commit comments