@@ -29,10 +29,11 @@ use rustc_resolve::Resolver;
29
29
use rustc_session:: config:: { CrateType , Input , OutFileName , OutputFilenames , OutputType } ;
30
30
use rustc_session:: cstore:: Untracked ;
31
31
use rustc_session:: output:: { collect_crate_types, filename_for_input} ;
32
+ use rustc_session:: parse:: feature_err;
32
33
use rustc_session:: search_paths:: PathKind ;
33
34
use rustc_session:: { Limit , Session } ;
34
35
use rustc_span:: {
35
- ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
36
+ DUMMY_SP , ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
36
37
} ;
37
38
use rustc_target:: spec:: PanicStrategy ;
38
39
use rustc_trait_selection:: traits;
@@ -235,6 +236,7 @@ fn configure_and_expand(
235
236
sess,
236
237
features,
237
238
& krate,
239
+ tcx. is_sdylib_interface_build ( ) ,
238
240
resolver. lint_buffer ( ) ,
239
241
)
240
242
} ) ;
@@ -251,6 +253,9 @@ fn configure_and_expand(
251
253
sess. dcx ( ) . emit_err ( errors:: MixedProcMacroCrate ) ;
252
254
}
253
255
}
256
+ if crate_types. contains ( & CrateType :: Sdylib ) && !tcx. features ( ) . export ( ) {
257
+ feature_err ( sess, sym:: export, DUMMY_SP , "`sdylib` crate type is unstable" ) . emit ( ) ;
258
+ }
254
259
255
260
if is_proc_macro_crate && sess. panic_strategy ( ) == PanicStrategy :: Abort {
256
261
sess. dcx ( ) . emit_warn ( errors:: ProcMacroCratePanicAbort ) ;
@@ -715,6 +720,27 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {
715
720
}
716
721
}
717
722
723
+ pub fn write_interface < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
724
+ if !tcx. crate_types ( ) . contains ( & rustc_session:: config:: CrateType :: Sdylib )
725
+ || tcx. is_sdylib_interface_build ( )
726
+ {
727
+ return ;
728
+ }
729
+ let _timer = tcx. sess . timer ( "write_interface" ) ;
730
+ let ( _, krate) = & * tcx. resolver_for_lowering ( ) . borrow ( ) ;
731
+
732
+ let krate = rustc_ast_pretty:: pprust:: print_crate_as_interface (
733
+ krate,
734
+ tcx. sess . psess . edition ,
735
+ & tcx. sess . psess . attr_id_generator ,
736
+ ) ;
737
+ let export_output = tcx. output_filenames ( ( ) ) . interface_path ( ) ;
738
+ let mut file = fs:: File :: create_buffered ( export_output) . unwrap ( ) ;
739
+ if let Err ( err) = write ! ( file, "{}" , krate) {
740
+ tcx. dcx ( ) . fatal ( format ! ( "error writing interface file: {}" , err) ) ;
741
+ }
742
+ }
743
+
718
744
pub static DEFAULT_QUERY_PROVIDERS : LazyLock < Providers > = LazyLock :: new ( || {
719
745
let providers = & mut Providers :: default ( ) ;
720
746
providers. analysis = analysis;
@@ -883,6 +909,10 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
883
909
CStore :: from_tcx( tcx) . report_unused_deps( tcx) ;
884
910
} ,
885
911
{
912
+ if tcx. crate_types( ) . contains( & CrateType :: Sdylib ) {
913
+ tcx. ensure_ok( ) . exportable_items( LOCAL_CRATE ) ;
914
+ tcx. ensure_ok( ) . stable_order_of_exportable_impls( LOCAL_CRATE ) ;
915
+ }
886
916
tcx. par_hir_for_each_module( |module| {
887
917
tcx. ensure_ok( ) . check_mod_loops( module) ;
888
918
tcx. ensure_ok( ) . check_mod_attrs( module) ;
0 commit comments