11use std:: { env, path:: * , process:: Command } ;
22
3- const OPENBLAS_VERSION : & str = "0.3.21" ;
3+ #[ allow( unused) ]
4+ fn run ( command : & mut Command ) {
5+ println ! ( "Running: `{:?}`" , command) ;
6+ match command. status ( ) {
7+ Ok ( status) => {
8+ if !status. success ( ) {
9+ panic ! ( "Failed: `{:?}` ({})" , command, status) ;
10+ }
11+ }
12+ Err ( error) => {
13+ panic ! ( "Failed: `{:?}` ({})" , command, error) ;
14+ }
15+ }
16+ }
417
518fn feature_enabled ( feature : & str ) -> bool {
619 env:: var ( format ! ( "CARGO_FEATURE_{}" , feature. to_uppercase( ) ) ) . is_ok ( )
@@ -160,17 +173,8 @@ fn build() {
160173 ) ;
161174 }
162175
163- let source = output. join ( format ! ( "OpenBLAS-{}" , OPENBLAS_VERSION ) ) ;
164- if !source. exists ( ) {
165- let crate_root = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
166- Command :: new ( "tar" )
167- . arg ( "xf" )
168- . arg ( crate_root. join ( format ! ( "OpenBLAS-{}.tar.gz" , OPENBLAS_VERSION ) ) )
169- . current_dir ( & output)
170- . status ( )
171- . expect ( "tar command not found" ) ;
172- }
173- let deliv = cfg. build ( & source, & output) . unwrap ( ) ;
176+ let source = openblas_build:: download ( & output) . unwrap ( ) ;
177+ let deliv = cfg. build ( source, & output) . unwrap ( ) ;
174178
175179 println ! ( "cargo:rustc-link-search={}" , output. display( ) ) ;
176180 for search_path in & deliv. make_conf . c_extra_libs . search_paths {
@@ -240,17 +244,7 @@ fn build() {
240244 } ;
241245
242246 if !source. exists ( ) {
243- let source_tmp = PathBuf :: from ( format ! ( "{}_tmp" , source. display( ) ) ) ;
244- if source_tmp. exists ( ) {
245- fs:: remove_dir_all ( & source_tmp) . unwrap ( ) ;
246- }
247- run ( Command :: new ( "tar" )
248- . arg ( "xf" )
249- . arg ( format ! ( "OpenBLAS-{}.tar.gz" , OPENBLAS_VERSION ) ) ) ;
250- run ( Command :: new ( "cp" )
251- . arg ( "-R" )
252- . arg ( format ! ( "OpenBLAS-{}" , OPENBLAS_VERSION ) )
253- . arg ( & source_tmp) ) ;
247+ let source_tmp = openblas_build:: download ( & output) . unwrap ( ) ;
254248 fs:: rename ( & source_tmp, & source) . unwrap ( ) ;
255249 }
256250 for name in & vec ! [ "CC" , "FC" , "HOSTCC" ] {
@@ -268,20 +262,6 @@ fn build() {
268262 output. join( "opt/OpenBLAS/lib" ) . display( ) ,
269263 ) ;
270264
271- fn run ( command : & mut Command ) {
272- println ! ( "Running: `{:?}`" , command) ;
273- match command. status ( ) {
274- Ok ( status) => {
275- if !status. success ( ) {
276- panic ! ( "Failed: `{:?}` ({})" , command, status) ;
277- }
278- }
279- Err ( error) => {
280- panic ! ( "Failed: `{:?}` ({})" , command, error) ;
281- }
282- }
283- }
284-
285265 fn binary ( ) -> & ' static str {
286266 if cfg ! ( target_pointer_width = "32" ) {
287267 "32"
0 commit comments