1010
1111#![ deny( warnings) ]
1212
13- #[ macro_use]
1413extern crate build_helper;
1514extern crate gcc;
1615
1716use std:: env;
18- use std:: fs:: { self , File } ;
19- use std:: path:: { Path , PathBuf } ;
17+ use std:: path:: PathBuf ;
2018use std:: process:: Command ;
21- use build_helper:: { run, rerun_if_changed_anything_in_dir , up_to_date } ;
19+ use build_helper:: { run, native_lib_boilerplate } ;
2220
2321fn main ( ) {
24- println ! ( "cargo:rerun-if-changed=build.rs" ) ;
25-
2622 // FIXME: This is a hack to support building targets that don't
2723 // support jemalloc alongside hosts that do. The jemalloc build is
2824 // controlled by a feature of the std crate, and if that feature
@@ -61,22 +57,11 @@ fn main() {
6157 return ;
6258 }
6359
64- let build_dir = env:: var_os ( "RUSTBUILD_NATIVE_DIR" ) . unwrap_or ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
65- let build_dir = PathBuf :: from ( build_dir) . join ( "jemalloc" ) ;
66- let _ = fs:: create_dir_all ( & build_dir) ;
67-
68- if target. contains ( "windows" ) {
69- println ! ( "cargo:rustc-link-lib=static=jemalloc" ) ;
70- } else {
71- println ! ( "cargo:rustc-link-lib=static=jemalloc_pic" ) ;
72- }
73- println ! ( "cargo:rustc-link-search=native={}/lib" , build_dir. display( ) ) ;
74- let src_dir = env:: current_dir ( ) . unwrap ( ) . join ( "../jemalloc" ) ;
75- rerun_if_changed_anything_in_dir ( & src_dir) ;
76- let timestamp = build_dir. join ( "rustbuild.timestamp" ) ;
77- if up_to_date ( & Path :: new ( "build.rs" ) , & timestamp) && up_to_date ( & src_dir, & timestamp) {
78- return
79- }
60+ let link_name = if target. contains ( "windows" ) { "jemalloc" } else { "jemalloc_pic" } ;
61+ let native = match native_lib_boilerplate ( "jemalloc" , "jemalloc" , link_name, "lib" ) {
62+ Ok ( native) => native,
63+ _ => return ,
64+ } ;
8065
8166 let compiler = gcc:: Config :: new ( ) . get_compiler ( ) ;
8267 // only msvc returns None for ar so unwrap is okay
@@ -88,12 +73,12 @@ fn main() {
8873 . join ( " " ) ;
8974
9075 let mut cmd = Command :: new ( "sh" ) ;
91- cmd. arg ( src_dir. join ( "configure" )
92- . to_str ( )
93- . unwrap ( )
94- . replace ( "C:\\ " , "/c/" )
95- . replace ( "\\ " , "/" ) )
96- . current_dir ( & build_dir )
76+ cmd. arg ( native . src_dir . join ( "configure" )
77+ . to_str ( )
78+ . unwrap ( )
79+ . replace ( "C:\\ " , "/c/" )
80+ . replace ( "\\ " , "/" ) )
81+ . current_dir ( & native . out_dir )
9782 . env ( "CC" , compiler. path ( ) )
9883 . env ( "EXTRA_CFLAGS" , cflags. clone ( ) )
9984 // jemalloc generates Makefile deps using GCC's "-MM" flag. This means
@@ -166,7 +151,7 @@ fn main() {
166151 run ( & mut cmd) ;
167152
168153 let mut make = Command :: new ( build_helper:: make ( & host) ) ;
169- make. current_dir ( & build_dir )
154+ make. current_dir ( & native . out_dir )
170155 . arg ( "build_lib_static" ) ;
171156
172157 // mingw make seems... buggy? unclear...
@@ -187,6 +172,4 @@ fn main() {
187172 . file ( "pthread_atfork_dummy.c" )
188173 . compile ( "libpthread_atfork_dummy.a" ) ;
189174 }
190-
191- t ! ( File :: create( & timestamp) ) ;
192175}
0 commit comments