@@ -12,8 +12,8 @@ use rustc_session::Session;
1212use rustc_span:: edition:: Edition ;
1313use rustc_span:: { sym, FileName , Symbol } ;
1414
15- use super :: copy_dir:: copy_dir_all;
1615use super :: print_item:: { full_path, item_path, print_item} ;
16+ use super :: search_index:: build_index;
1717use super :: write_shared:: write_shared;
1818use super :: {
1919 collect_spans_and_sources, scrape_examples_help,
@@ -133,8 +133,6 @@ pub(crate) struct SharedContext<'tcx> {
133133 pub ( crate ) cache : Cache ,
134134
135135 pub ( crate ) call_locations : AllCallLocations ,
136- /// Controls whether we write to the doc root. Default is true from cli.
137- write_rendered_cci : bool ,
138136}
139137
140138impl SharedContext < ' _ > {
@@ -471,7 +469,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
471469 call_locations,
472470 no_emit_shared,
473471 html_no_source,
474- include_rendered_docs,
475472 ..
476473 } = options;
477474
@@ -557,7 +554,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
557554 span_correspondence_map : matches,
558555 cache,
559556 call_locations,
560- write_rendered_cci : options. write_rendered_cci ,
561557 } ;
562558
563559 let dst = output;
@@ -575,16 +571,18 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
575571 is_inside_inlined_module : false ,
576572 } ;
577573
578- for extern_docs in include_rendered_docs. iter ( ) {
579- try_err ! ( copy_dir_all( & extern_docs. 0 , & cx. dst) , & extern_docs. 0 ) ;
580- }
581-
582574 if emit_crate {
583575 sources:: render ( & mut cx, & krate) ?;
584576 }
585577
586578 if !no_emit_shared {
587- write_shared ( & mut cx, & krate, & md_opts, tcx) ?;
579+ // Build our search index
580+ let index = build_index ( & krate, & mut Rc :: get_mut ( & mut cx. shared ) . unwrap ( ) . cache , tcx) ;
581+
582+ // Write shared runs within a flock; disable thread dispatching of IO temporarily.
583+ Rc :: get_mut ( & mut cx. shared ) . unwrap ( ) . fs . set_sync_only ( true ) ;
584+ write_shared ( & mut cx, & krate, index, & md_opts) ?;
585+ Rc :: get_mut ( & mut cx. shared ) . unwrap ( ) . fs . set_sync_only ( false ) ;
588586 }
589587
590588 Ok ( ( cx, krate) )
@@ -649,99 +647,92 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
649647 ) ;
650648 shared. fs . write ( final_file, v) ?;
651649
652- // if to avoid writing files to doc root unless we're on the final invocation
653- if shared. write_rendered_cci {
654- // Generating settings page.
655- page. title = "Settings" ;
656- page. description = "Settings of Rustdoc" ;
657- page. root_path = "./" ;
658- page. rust_logo = true ;
650+ // Generating settings page.
651+ page. title = "Settings" ;
652+ page. description = "Settings of Rustdoc" ;
653+ page. root_path = "./" ;
654+ page. rust_logo = true ;
659655
660- let sidebar = "<h2 class=\" location\" >Settings</h2><div class=\" sidebar-elems\" ></div>" ;
661- let v = layout:: render (
662- & shared. layout ,
663- & page,
664- sidebar,
665- |buf : & mut Buffer | {
666- write ! (
667- buf,
668- "<div class=\" main-heading\" >\
669- <h1>Rustdoc settings</h1>\
670- <span class=\" out-of-band\" >\
671- <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
672- Back\
673- </a>\
674- </span>\
675- </div>\
676- <noscript>\
677- <section>\
678- You need to enable JavaScript be able to update your settings.\
679- </section>\
680- </noscript>\
681- <script defer src=\" {static_root_path}{settings_js}\" ></script>",
682- static_root_path = page. get_static_root_path( ) ,
683- settings_js = static_files:: STATIC_FILES . settings_js,
684- ) ;
685- // Pre-load all theme CSS files, so that switching feels seamless.
686- //
687- // When loading settings.html as a popover, the equivalent HTML is
688- // generated in main.js.
689- for file in & shared. style_files {
690- if let Ok ( theme) = file. basename ( ) {
691- write ! (
692- buf,
693- "<link rel=\" preload\" href=\" {root_path}{theme}{suffix}.css\" \
694- as=\" style\" >",
695- root_path = page. static_root_path. unwrap_or( "" ) ,
696- suffix = page. resource_suffix,
697- ) ;
698- }
656+ let sidebar = "<h2 class=\" location\" >Settings</h2><div class=\" sidebar-elems\" ></div>" ;
657+ let v = layout:: render (
658+ & shared. layout ,
659+ & page,
660+ sidebar,
661+ |buf : & mut Buffer | {
662+ write ! (
663+ buf,
664+ "<div class=\" main-heading\" >\
665+ <h1>Rustdoc settings</h1>\
666+ <span class=\" out-of-band\" >\
667+ <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
668+ Back\
669+ </a>\
670+ </span>\
671+ </div>\
672+ <noscript>\
673+ <section>\
674+ You need to enable JavaScript be able to update your settings.\
675+ </section>\
676+ </noscript>\
677+ <script defer src=\" {static_root_path}{settings_js}\" ></script>",
678+ static_root_path = page. get_static_root_path( ) ,
679+ settings_js = static_files:: STATIC_FILES . settings_js,
680+ ) ;
681+ // Pre-load all theme CSS files, so that switching feels seamless.
682+ //
683+ // When loading settings.html as a popover, the equivalent HTML is
684+ // generated in main.js.
685+ for file in & shared. style_files {
686+ if let Ok ( theme) = file. basename ( ) {
687+ write ! (
688+ buf,
689+ "<link rel=\" preload\" href=\" {root_path}{theme}{suffix}.css\" \
690+ as=\" style\" >",
691+ root_path = page. static_root_path. unwrap_or( "" ) ,
692+ suffix = page. resource_suffix,
693+ ) ;
699694 }
700- } ,
701- & shared . style_files ,
702- ) ;
703- shared . fs . write ( settings_file , v ) ? ;
704- }
695+ }
696+ } ,
697+ & shared . style_files ,
698+ ) ;
699+ shared . fs . write ( settings_file , v ) ? ;
705700
706- // if to avoid writing files to doc root unless we're on the final invocation
707- if shared. write_rendered_cci {
708- // Generating help page.
709- page. title = "Help" ;
710- page. description = "Documentation for Rustdoc" ;
711- page. root_path = "./" ;
712- page. rust_logo = true ;
701+ // Generating help page.
702+ page. title = "Help" ;
703+ page. description = "Documentation for Rustdoc" ;
704+ page. root_path = "./" ;
705+ page. rust_logo = true ;
713706
714- let sidebar = "<h2 class=\" location\" >Help</h2><div class=\" sidebar-elems\" ></div>" ;
715- let v = layout:: render (
716- & shared. layout ,
717- & page,
718- sidebar,
719- |buf : & mut Buffer | {
720- write ! (
721- buf,
722- "<div class=\" main-heading\" >\
723- <h1>Rustdoc help</h1>\
724- <span class=\" out-of-band\" >\
725- <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
726- Back\
727- </a>\
728- </span>\
729- </div>\
730- <noscript>\
731- <section>\
732- <p>You need to enable JavaScript to use keyboard commands or search.</p>\
733- <p>For more information, browse the <a href=\" https://doc.rust-lang.org/rustdoc/\" >rustdoc handbook</a>.</p>\
734- </section>\
735- </noscript>",
736- )
737- } ,
738- & shared. style_files ,
739- ) ;
740- shared. fs . write ( help_file, v) ?;
741- }
707+ let sidebar = "<h2 class=\" location\" >Help</h2><div class=\" sidebar-elems\" ></div>" ;
708+ let v = layout:: render (
709+ & shared. layout ,
710+ & page,
711+ sidebar,
712+ |buf : & mut Buffer | {
713+ write ! (
714+ buf,
715+ "<div class=\" main-heading\" >\
716+ <h1>Rustdoc help</h1>\
717+ <span class=\" out-of-band\" >\
718+ <a id=\" back\" href=\" javascript:void(0)\" onclick=\" history.back();\" >\
719+ Back\
720+ </a>\
721+ </span>\
722+ </div>\
723+ <noscript>\
724+ <section>\
725+ <p>You need to enable JavaScript to use keyboard commands or search.</p>\
726+ <p>For more information, browse the <a href=\" https://doc.rust-lang.org/rustdoc/\" >rustdoc handbook</a>.</p>\
727+ </section>\
728+ </noscript>",
729+ )
730+ } ,
731+ & shared. style_files ,
732+ ) ;
733+ shared. fs . write ( help_file, v) ?;
742734
743- // if to avoid writing files to doc root unless we're on the final invocation
744- if shared. layout . scrape_examples_extension && shared. write_rendered_cci {
735+ if shared. layout . scrape_examples_extension {
745736 page. title = "About scraped examples" ;
746737 page. description = "How the scraped examples feature works in Rustdoc" ;
747738 let v = layout:: render (
0 commit comments