@@ -122,7 +122,15 @@ impl Build {
122
122
false
123
123
}
124
124
125
+ #[ track_caller]
125
126
pub fn build ( & mut self ) -> Artifacts {
127
+ match self . try_build ( ) {
128
+ Ok ( a) => a,
129
+ Err ( e) => panic ! ( "\n \n \n {e}\n \n \n " ) ,
130
+ }
131
+ }
132
+
133
+ pub fn try_build ( & mut self ) -> Result < Artifacts , String > {
126
134
let target = & self . target . as_ref ( ) . expect ( "TARGET dir not set" ) [ ..] ;
127
135
let host = & self . host . as_ref ( ) . expect ( "HOST dir not set" ) [ ..] ;
128
136
let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR not set" ) ;
@@ -575,24 +583,24 @@ impl Build {
575
583
576
584
// And finally, run the perl configure script!
577
585
configure. current_dir ( & inner_dir) ;
578
- self . run_command ( configure, "configuring OpenSSL build" ) ;
586
+ self . run_command ( configure, "configuring OpenSSL build" ) ? ;
579
587
580
588
// On MSVC we use `nmake.exe` with a slightly different invocation, so
581
589
// have that take a different path than the standard `make` below.
582
590
if target. contains ( "msvc" ) {
583
591
let mut build =
584
592
cc:: windows_registry:: find ( target, "nmake.exe" ) . expect ( "failed to find nmake" ) ;
585
593
build. arg ( "build_libs" ) . current_dir ( & inner_dir) ;
586
- self . run_command ( build, "building OpenSSL" ) ;
594
+ self . run_command ( build, "building OpenSSL" ) ? ;
587
595
588
596
let mut install =
589
597
cc:: windows_registry:: find ( target, "nmake.exe" ) . expect ( "failed to find nmake" ) ;
590
598
install. arg ( "install_dev" ) . current_dir ( & inner_dir) ;
591
- self . run_command ( install, "installing OpenSSL" ) ;
599
+ self . run_command ( install, "installing OpenSSL" ) ? ;
592
600
} else {
593
601
let mut depend = self . cmd_make ( ) ;
594
602
depend. arg ( "depend" ) . current_dir ( & inner_dir) ;
595
- self . run_command ( depend, "building OpenSSL dependencies" ) ;
603
+ self . run_command ( depend, "building OpenSSL dependencies" ) ? ;
596
604
597
605
let mut build = self . cmd_make ( ) ;
598
606
build. arg ( "build_libs" ) . current_dir ( & inner_dir) ;
@@ -608,11 +616,11 @@ impl Build {
608
616
build. env ( "CROSS_SDK" , components[ 1 ] ) ;
609
617
}
610
618
611
- self . run_command ( build, "building OpenSSL" ) ;
619
+ self . run_command ( build, "building OpenSSL" ) ? ;
612
620
613
621
let mut install = self . cmd_make ( ) ;
614
622
install. arg ( "install_dev" ) . current_dir ( & inner_dir) ;
615
- self . run_command ( install, "installing OpenSSL" ) ;
623
+ self . run_command ( install, "installing OpenSSL" ) ? ;
616
624
}
617
625
618
626
let libs = if target. contains ( "msvc" ) {
@@ -623,39 +631,43 @@ impl Build {
623
631
624
632
fs:: remove_dir_all ( & inner_dir) . unwrap ( ) ;
625
633
626
- Artifacts {
634
+ Ok ( Artifacts {
627
635
lib_dir : install_dir. join ( "lib" ) ,
628
636
bin_dir : install_dir. join ( "bin" ) ,
629
637
include_dir : install_dir. join ( "include" ) ,
630
638
libs : libs,
631
639
target : target. to_string ( ) ,
632
- }
640
+ } )
633
641
}
634
642
635
643
#[ track_caller]
636
- fn run_command ( & self , mut command : Command , desc : & str ) {
644
+ fn run_command ( & self , mut command : Command , desc : & str ) -> Result < ( ) , String > {
637
645
println ! ( "running {:?}" , command) ;
638
646
let status = command. status ( ) ;
639
647
640
648
let verbose_error = match status {
641
- Ok ( status) if status. success ( ) => return ,
642
- Ok ( status) => format ! ( "'{exe}' reported failure with {status}" , exe = command. get_program( ) . to_string_lossy( ) ) ,
649
+ Ok ( status) if status. success ( ) => return Ok ( ( ) ) ,
650
+ Ok ( status) => format ! (
651
+ "'{exe}' reported failure with {status}" ,
652
+ exe = command. get_program( ) . to_string_lossy( )
653
+ ) ,
643
654
Err ( failed) => match failed. kind ( ) {
644
- std:: io:: ErrorKind :: NotFound => format ! ( "Command '{exe}' not found. Is {exe} installed?" , exe = command. get_program( ) . to_string_lossy( ) ) ,
645
- _ => format ! ( "Could not run '{exe}', because {failed}" , exe = command. get_program( ) . to_string_lossy( ) ) ,
646
- }
655
+ std:: io:: ErrorKind :: NotFound => format ! (
656
+ "Command '{exe}' not found. Is {exe} installed?" ,
657
+ exe = command. get_program( ) . to_string_lossy( )
658
+ ) ,
659
+ _ => format ! (
660
+ "Could not run '{exe}', because {failed}" ,
661
+ exe = command. get_program( ) . to_string_lossy( )
662
+ ) ,
663
+ } ,
647
664
} ;
648
665
println ! ( "cargo:warning={desc}: {verbose_error}" ) ;
649
- panic ! (
650
- "
651
-
652
-
653
- Error {desc}:
666
+ Err ( format ! (
667
+ "Error {desc}:
654
668
{verbose_error}
655
- Command failed: {command:?}
656
-
657
-
658
- " ) ;
669
+ Command failed: {command:?}"
670
+ ) )
659
671
}
660
672
}
661
673
0 commit comments