@@ -666,6 +666,14 @@ fn opts() -> Vec<RustcOptGroup> {
666666 "disable the minification of CSS/JS files (perma-unstable, do not use with cached files)" ,
667667 "" ,
668668 ) ,
669+ opt(
670+ Unstable ,
671+ Opt ,
672+ "" ,
673+ "book-location" ,
674+ "URL where the book is hosted or the folder where the mdBook source is located" ,
675+ "PATH or URL" ,
676+ ) ,
669677 // deprecated / removed options
670678 opt(
671679 Stable ,
@@ -749,6 +757,32 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
749757 }
750758}
751759
760+ fn generate_book ( render_options : & mut config:: RenderOptions ) -> Result < ( ) , String > {
761+ let Some ( config:: PathOrUrl :: Path ( ref mut book_dir) ) = render_options. book_location else {
762+ return Ok ( ( ) ) ;
763+ } ;
764+ if !book_dir. is_dir ( ) {
765+ return Err ( format ! (
766+ "`{}` is not a folder, expected a folder or a URL for `--book-location` argument" ,
767+ book_dir. display( ) ,
768+ ) ) ;
769+ }
770+ let mut book = match mdbook:: MDBook :: load ( & book_dir) {
771+ Ok ( book) => book,
772+ Err ( error) => return Err ( format ! ( "failed to load book: {error:?}" ) ) ,
773+ } ;
774+ let output_dir = render_options. output . join ( "doc-book" ) ;
775+ * book_dir = output_dir. join ( "index.html" ) ;
776+ book. config . build . build_dir = output_dir;
777+ if let Err ( error) = book. build ( ) {
778+ return Err ( format ! (
779+ "failed to generate book into `{}`: {error:?}" ,
780+ book. config. build. build_dir. display( )
781+ ) ) ;
782+ }
783+ Ok ( ( ) )
784+ }
785+
752786/// Renders and writes cross-crate info files, like the search index. This function exists so that
753787/// we can run rustdoc without a crate root in the `--merge=finalize` mode. Cross-crate info files
754788/// discovered via `--include-parts-dir` are combined and written to the doc root.
@@ -801,7 +835,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
801835
802836 // Note that we discard any distinction between different non-zero exit
803837 // codes from `from_matches` here.
804- let ( input, options, render_options) =
838+ let ( input, options, mut render_options) =
805839 match config:: Options :: from_matches ( early_dcx, & matches, args) {
806840 Some ( opts) => opts,
807841 None => return ,
@@ -865,6 +899,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
865899 let scrape_examples_options = options. scrape_examples_options . clone ( ) ;
866900 let bin_crate = options. bin_crate ;
867901
902+ if let Err ( error) = generate_book ( & mut render_options) {
903+ early_dcx. early_fatal ( error) ;
904+ }
905+
868906 let config = core:: create_config ( input, options, & render_options) ;
869907
870908 let registered_lints = config. register_lints . is_some ( ) ;
0 commit comments