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