@@ -668,6 +668,14 @@ fn opts() -> Vec<RustcOptGroup> {
668668 "disable the minification of CSS/JS files (perma-unstable, do not use with cached files)" ,
669669 "" ,
670670 ) ,
671+ opt(
672+ Unstable ,
673+ Opt ,
674+ "" ,
675+ "book-location" ,
676+ "URL where the book is hosted or the folder where the mdBook source is located" ,
677+ "PATH or URL" ,
678+ ) ,
671679 // deprecated / removed options
672680 opt(
673681 Stable ,
@@ -751,6 +759,32 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
751759 }
752760}
753761
762+ fn generate_book ( render_options : & mut config:: RenderOptions ) -> Result < ( ) , String > {
763+ let Some ( config:: PathOrUrl :: Path ( ref mut book_dir) ) = render_options. book_location else {
764+ return Ok ( ( ) ) ;
765+ } ;
766+ if !book_dir. is_dir ( ) {
767+ return Err ( format ! (
768+ "`{}` is not a folder, expected a folder or a URL for `--book-location` argument" ,
769+ book_dir. display( ) ,
770+ ) ) ;
771+ }
772+ let mut book = match mdbook:: MDBook :: load ( & book_dir) {
773+ Ok ( book) => book,
774+ Err ( error) => return Err ( format ! ( "failed to load book: {error:?}" ) ) ,
775+ } ;
776+ let output_dir = render_options. output . join ( "doc-book" ) ;
777+ * book_dir = output_dir. join ( "index.html" ) ;
778+ book. config . build . build_dir = output_dir;
779+ if let Err ( error) = book. build ( ) {
780+ return Err ( format ! (
781+ "failed to generate book into `{}`: {error:?}" ,
782+ book. config. build. build_dir. display( )
783+ ) ) ;
784+ }
785+ Ok ( ( ) )
786+ }
787+
754788/// Renders and writes cross-crate info files, like the search index. This function exists so that
755789/// we can run rustdoc without a crate root in the `--merge=finalize` mode. Cross-crate info files
756790/// discovered via `--include-parts-dir` are combined and written to the doc root.
@@ -803,7 +837,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
803837
804838 // Note that we discard any distinction between different non-zero exit
805839 // codes from `from_matches` here.
806- let ( input, options, render_options) =
840+ let ( input, options, mut render_options) =
807841 match config:: Options :: from_matches ( early_dcx, & matches, args) {
808842 Some ( opts) => opts,
809843 None => return ,
@@ -867,6 +901,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
867901 let scrape_examples_options = options. scrape_examples_options . clone ( ) ;
868902 let bin_crate = options. bin_crate ;
869903
904+ if let Err ( error) = generate_book ( & mut render_options) {
905+ early_dcx. early_fatal ( error) ;
906+ }
907+
870908 let config = core:: create_config ( input, options, & render_options) ;
871909
872910 let registered_lints = config. register_lints . is_some ( ) ;
0 commit comments