@@ -658,6 +658,14 @@ fn opts() -> Vec<RustcOptGroup> {
658658 "disable the minification of CSS/JS files (perma-unstable, do not use with cached files)" ,
659659 "" ,
660660 ) ,
661+ opt(
662+ Unstable ,
663+ Opt ,
664+ "" ,
665+ "book-location" ,
666+ "URL where the book is hosted or the folder where the mdBook source is located" ,
667+ "PATH or URL" ,
668+ ) ,
661669 // deprecated / removed options
662670 opt(
663671 Stable ,
@@ -741,6 +749,32 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
741749 }
742750}
743751
752+ fn generate_book ( render_options : & mut config:: RenderOptions ) -> Result < ( ) , String > {
753+ let Some ( config:: PathOrURL :: Path ( ref mut book_dir) ) = render_options. book_location else {
754+ return Ok ( ( ) ) ;
755+ } ;
756+ if !book_dir. is_dir ( ) {
757+ return Err ( format ! (
758+ "`{}` is not a folder, expected a folder or a URL for `--book-location` argument" ,
759+ book_dir. display( ) ,
760+ ) ) ;
761+ }
762+ let mut book = match mdbook:: MDBook :: load ( & book_dir) {
763+ Ok ( book) => book,
764+ Err ( error) => return Err ( format ! ( "failed to load book: {error:?}" ) ) ,
765+ } ;
766+ let output_dir = render_options. output . join ( "doc-book" ) ;
767+ * book_dir = output_dir. join ( "index.html" ) ;
768+ book. config . build . build_dir = output_dir;
769+ if let Err ( error) = book. build ( ) {
770+ return Err ( format ! (
771+ "failed to generate book into `{}`: {error:?}" ,
772+ book. config. build. build_dir. display( )
773+ ) ) ;
774+ }
775+ Ok ( ( ) )
776+ }
777+
744778/// Renders and writes cross-crate info files, like the search index. This function exists so that
745779/// we can run rustdoc without a crate root in the `--merge=finalize` mode. Cross-crate info files
746780/// discovered via `--include-parts-dir` are combined and written to the doc root.
@@ -793,7 +827,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
793827
794828 // Note that we discard any distinction between different non-zero exit
795829 // codes from `from_matches` here.
796- let ( input, options, render_options) =
830+ let ( input, options, mut render_options) =
797831 match config:: Options :: from_matches ( early_dcx, & matches, args) {
798832 Some ( opts) => opts,
799833 None => return ,
@@ -857,6 +891,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
857891 let scrape_examples_options = options. scrape_examples_options . clone ( ) ;
858892 let bin_crate = options. bin_crate ;
859893
894+ if let Err ( error) = generate_book ( & mut render_options) {
895+ early_dcx. early_fatal ( error) ;
896+ }
897+
860898 let config = core:: create_config ( input, options, & render_options) ;
861899
862900 let registered_lints = config. register_lints . is_some ( ) ;
0 commit comments