@@ -668,6 +668,14 @@ fn opts() -> Vec<RustcOptGroup> {
668
668
"disable the minification of CSS/JS files (perma-unstable, do not use with cached files)" ,
669
669
"" ,
670
670
) ,
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
+ ) ,
671
679
// deprecated / removed options
672
680
opt(
673
681
Stable ,
@@ -751,6 +759,32 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
751
759
}
752
760
}
753
761
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
+
754
788
/// Renders and writes cross-crate info files, like the search index. This function exists so that
755
789
/// we can run rustdoc without a crate root in the `--merge=finalize` mode. Cross-crate info files
756
790
/// 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]) {
803
837
804
838
// Note that we discard any distinction between different non-zero exit
805
839
// codes from `from_matches` here.
806
- let ( input, options, render_options) =
840
+ let ( input, options, mut render_options) =
807
841
match config:: Options :: from_matches ( early_dcx, & matches, args) {
808
842
Some ( opts) => opts,
809
843
None => return ,
@@ -867,6 +901,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
867
901
let scrape_examples_options = options. scrape_examples_options . clone ( ) ;
868
902
let bin_crate = options. bin_crate ;
869
903
904
+ if let Err ( error) = generate_book ( & mut render_options) {
905
+ early_dcx. early_fatal ( error) ;
906
+ }
907
+
870
908
let config = core:: create_config ( input, options, & render_options) ;
871
909
872
910
let registered_lints = config. register_lints . is_some ( ) ;
0 commit comments