10
10
11
11
#![ deny( warnings) ]
12
12
13
- #[ macro_use]
14
13
extern crate build_helper;
15
14
extern crate gcc;
16
15
17
16
use std:: env;
18
- use std:: fs:: { self , File } ;
19
- use std:: path:: { Path , PathBuf } ;
17
+ use std:: path:: PathBuf ;
20
18
use 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 } ;
22
20
23
21
fn main ( ) {
24
- println ! ( "cargo:rerun-if-changed=build.rs" ) ;
25
-
26
22
// FIXME: This is a hack to support building targets that don't
27
23
// support jemalloc alongside hosts that do. The jemalloc build is
28
24
// controlled by a feature of the std crate, and if that feature
@@ -61,22 +57,11 @@ fn main() {
61
57
return ;
62
58
}
63
59
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
+ } ;
80
65
81
66
let compiler = gcc:: Config :: new ( ) . get_compiler ( ) ;
82
67
// only msvc returns None for ar so unwrap is okay
@@ -88,12 +73,12 @@ fn main() {
88
73
. join ( " " ) ;
89
74
90
75
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 )
97
82
. env ( "CC" , compiler. path ( ) )
98
83
. env ( "EXTRA_CFLAGS" , cflags. clone ( ) )
99
84
// jemalloc generates Makefile deps using GCC's "-MM" flag. This means
@@ -166,7 +151,7 @@ fn main() {
166
151
run ( & mut cmd) ;
167
152
168
153
let mut make = Command :: new ( build_helper:: make ( & host) ) ;
169
- make. current_dir ( & build_dir )
154
+ make. current_dir ( & native . out_dir )
170
155
. arg ( "build_lib_static" ) ;
171
156
172
157
// mingw make seems... buggy? unclear...
@@ -187,6 +172,4 @@ fn main() {
187
172
. file ( "pthread_atfork_dummy.c" )
188
173
. compile ( "libpthread_atfork_dummy.a" ) ;
189
174
}
190
-
191
- t ! ( File :: create( & timestamp) ) ;
192
175
}
0 commit comments