@@ -15,10 +15,10 @@ extern crate build_helper;
1515extern crate gcc;
1616
1717use std:: env;
18- use std:: fs:: { self , File } ;
19- use std:: path:: { Path , PathBuf } ;
18+ use std:: fs:: File ;
19+ use std:: path:: PathBuf ;
2020use std:: process:: Command ;
21- use build_helper:: { run, rerun_if_changed_anything_in_dir , up_to_date } ;
21+ use build_helper:: { run, native_lib_boilerplate } ;
2222
2323fn main ( ) {
2424 // FIXME: This is a hack to support building targets that don't
@@ -59,20 +59,10 @@ fn main() {
5959 return ;
6060 }
6161
62- let build_dir = env:: var_os ( "RUSTBUILD_NATIVE_DIR" ) . unwrap_or ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
63- let build_dir = PathBuf :: from ( build_dir) . join ( "jemalloc" ) ;
64- let _ = fs:: create_dir_all ( & build_dir) ;
65-
66- if target. contains ( "windows" ) {
67- println ! ( "cargo:rustc-link-lib=static=jemalloc" ) ;
68- } else {
69- println ! ( "cargo:rustc-link-lib=static=jemalloc_pic" ) ;
70- }
71- println ! ( "cargo:rustc-link-search=native={}/lib" , build_dir. display( ) ) ;
72- let src_dir = env:: current_dir ( ) . unwrap ( ) . join ( "../jemalloc" ) ;
73- rerun_if_changed_anything_in_dir ( & src_dir) ;
74- let timestamp = build_dir. join ( "rustbuild.timestamp" ) ;
75- if up_to_date ( & Path :: new ( "build.rs" ) , & timestamp) && up_to_date ( & src_dir, & timestamp) {
62+ let link_name = if target. contains ( "windows" ) { "jemalloc" } else { "jemalloc_pic" } ;
63+ let native = native_lib_boilerplate ( "jemalloc" , "jemalloc" , link_name,
64+ "rustbuild.timestamp" , "lib" ) ;
65+ if native. skip_build {
7666 return
7767 }
7868
@@ -86,12 +76,12 @@ fn main() {
8676 . join ( " " ) ;
8777
8878 let mut cmd = Command :: new ( "sh" ) ;
89- cmd. arg ( src_dir. join ( "configure" )
90- . to_str ( )
91- . unwrap ( )
92- . replace ( "C:\\ " , "/c/" )
93- . replace ( "\\ " , "/" ) )
94- . current_dir ( & build_dir )
79+ cmd. arg ( native . src_dir . join ( "configure" )
80+ . to_str ( )
81+ . unwrap ( )
82+ . replace ( "C:\\ " , "/c/" )
83+ . replace ( "\\ " , "/" ) )
84+ . current_dir ( & native . out_dir )
9585 . env ( "CC" , compiler. path ( ) )
9686 . env ( "EXTRA_CFLAGS" , cflags. clone ( ) )
9787 // jemalloc generates Makefile deps using GCC's "-MM" flag. This means
@@ -164,7 +154,7 @@ fn main() {
164154 run ( & mut cmd) ;
165155
166156 let mut make = Command :: new ( build_helper:: make ( & host) ) ;
167- make. current_dir ( & build_dir )
157+ make. current_dir ( & native . out_dir )
168158 . arg ( "build_lib_static" ) ;
169159
170160 // mingw make seems... buggy? unclear...
@@ -186,5 +176,5 @@ fn main() {
186176 . compile ( "libpthread_atfork_dummy.a" ) ;
187177 }
188178
189- t ! ( File :: create( & timestamp) ) ;
179+ t ! ( File :: create( & native . timestamp) ) ;
190180}
0 commit comments