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