@@ -7,30 +7,29 @@ pub struct Build {
7
7
out_dir : Option < PathBuf > ,
8
8
target : Option < String > ,
9
9
host : Option < String > ,
10
- options : Options ,
10
+ lua52compat : bool ,
11
11
}
12
12
13
13
pub struct Artifacts {
14
- include_dir : PathBuf ,
15
14
lib_dir : PathBuf ,
16
15
libs : Vec < String > ,
17
16
}
18
17
19
- #[ derive( Default , Clone , Copy ) ]
20
- struct Options {
21
- lua52compat : bool ,
22
- }
23
-
24
- impl Build {
25
- #[ allow( clippy:: new_without_default) ]
26
- pub fn new ( ) -> Build {
18
+ impl Default for Build {
19
+ fn default ( ) -> Self {
27
20
Build {
28
- out_dir : env:: var_os ( "OUT_DIR" ) . map ( |s| PathBuf :: from ( s ) . join ( "luajit-build" ) ) ,
21
+ out_dir : env:: var_os ( "OUT_DIR" ) . map ( PathBuf :: from) ,
29
22
target : env:: var ( "TARGET" ) . ok ( ) ,
30
23
host : env:: var ( "HOST" ) . ok ( ) ,
31
- options : Options :: default ( ) ,
24
+ lua52compat : false ,
32
25
}
33
26
}
27
+ }
28
+
29
+ impl Build {
30
+ pub fn new ( ) -> Build {
31
+ Build :: default ( )
32
+ }
34
33
35
34
pub fn out_dir < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Build {
36
35
self . out_dir = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
@@ -48,7 +47,7 @@ impl Build {
48
47
}
49
48
50
49
pub fn lua52compat ( & mut self , enabled : bool ) -> & mut Build {
51
- self . options . lua52compat = enabled;
50
+ self . lua52compat = enabled;
52
51
self
53
52
}
54
53
@@ -75,22 +74,18 @@ impl Build {
75
74
let host = & self . host . as_ref ( ) . expect ( "HOST not set" ) [ ..] ;
76
75
let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR not set" ) ;
77
76
let source_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "luajit2" ) ;
78
- let build_dir = out_dir. join ( "build" ) ;
79
- let lib_dir = out_dir. join ( "lib" ) ;
80
- let include_dir = out_dir. join ( "include" ) ;
81
-
82
- for dir in & [ & build_dir, & lib_dir, & include_dir] {
83
- if dir. exists ( ) {
84
- fs:: remove_dir_all ( dir)
85
- . unwrap_or_else ( |e| panic ! ( "cannot remove {}: {}" , dir. display( ) , e) ) ;
86
- }
87
- fs:: create_dir_all ( dir)
88
- . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , dir. display( ) , e) ) ;
77
+ let build_dir = out_dir. join ( "luajit-build" ) ;
78
+
79
+ // Cleanup
80
+ if build_dir. exists ( ) {
81
+ fs:: remove_dir_all ( & build_dir) . unwrap ( ) ;
89
82
}
83
+ fs:: create_dir_all ( & build_dir)
84
+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
90
85
cp_r ( & source_dir, & build_dir) ;
91
86
92
87
let mut cc = cc:: Build :: new ( ) ;
93
- cc. target ( target ) . host ( host ) . warnings ( false ) . opt_level ( 2 ) ;
88
+ cc. warnings ( false ) ;
94
89
let compiler = cc. get_compiler ( ) ;
95
90
let compiler_path = compiler. path ( ) . to_str ( ) . unwrap ( ) ;
96
91
@@ -179,27 +174,21 @@ impl Build {
179
174
}
180
175
181
176
let mut xcflags = vec ! [ "-fPIC" ] ;
182
- if self . options . lua52compat {
177
+ if self . lua52compat {
183
178
xcflags. push ( "-DLUAJIT_ENABLE_LUA52COMPAT" ) ;
184
179
}
180
+ if cfg ! ( debug_assertions) {
181
+ xcflags. push ( "-DLUA_USE_ASSERT" ) ;
182
+ xcflags. push ( "-DLUA_USE_APICHECK" ) ;
183
+ }
185
184
186
185
make. env ( "BUILDMODE" , "static" ) ;
187
186
make. env ( "XCFLAGS" , xcflags. join ( " " ) ) ;
188
187
self . run_command ( make, "building LuaJIT" ) ;
189
188
190
- for f in & [ "lauxlib.h" , "lua.h" , "luaconf.h" , "luajit.h" , "lualib.h" ] {
191
- fs:: copy ( build_dir. join ( "src" ) . join ( f) , include_dir. join ( f) ) . unwrap ( ) ;
192
- }
193
- fs:: copy (
194
- build_dir. join ( "src" ) . join ( "libluajit.a" ) ,
195
- lib_dir. join ( "libluajit-5.1.a" ) ,
196
- )
197
- . unwrap ( ) ;
198
-
199
189
Artifacts {
200
- lib_dir,
201
- include_dir,
202
- libs : vec ! [ "luajit-5.1" . to_string( ) ] ,
190
+ lib_dir : build_dir. join ( "src" ) ,
191
+ libs : vec ! [ "luajit" . to_string( ) ] ,
203
192
}
204
193
}
205
194
@@ -209,23 +198,19 @@ impl Build {
209
198
let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
210
199
let source_dir = manifest_dir. join ( "luajit2" ) ;
211
200
let extras_dir = manifest_dir. join ( "extras" ) ;
212
- let build_dir = out_dir. join ( "build" ) ;
213
- let lib_dir = out_dir. join ( "lib" ) ;
214
- let include_dir = out_dir. join ( "include" ) ;
215
-
216
- for dir in & [ & build_dir, & lib_dir, & include_dir] {
217
- if dir. exists ( ) {
218
- fs:: remove_dir_all ( dir)
219
- . unwrap_or_else ( |e| panic ! ( "cannot remove {}: {}" , dir. display( ) , e) ) ;
220
- }
221
- fs:: create_dir_all ( dir)
222
- . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , dir. display( ) , e) ) ;
201
+ let build_dir = out_dir. join ( "luajit-build" ) ;
202
+
203
+ // Cleanup
204
+ if build_dir. exists ( ) {
205
+ fs:: remove_dir_all ( & build_dir) . unwrap ( ) ;
223
206
}
207
+ fs:: create_dir_all ( & build_dir)
208
+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
224
209
cp_r ( & source_dir, & build_dir) ;
225
210
226
211
let mut msvcbuild = Command :: new ( build_dir. join ( "src" ) . join ( "msvcbuild.bat" ) ) ;
227
212
msvcbuild. current_dir ( build_dir. join ( "src" ) ) ;
228
- if self . options . lua52compat {
213
+ if self . lua52compat {
229
214
cp_r ( & extras_dir, & build_dir. join ( "src" ) ) ;
230
215
msvcbuild. arg ( "lua52c" ) ;
231
216
}
@@ -238,19 +223,9 @@ impl Build {
238
223
239
224
self . run_command ( msvcbuild, "building LuaJIT" ) ;
240
225
241
- for f in & [ "lauxlib.h" , "lua.h" , "luaconf.h" , "luajit.h" , "lualib.h" ] {
242
- fs:: copy ( build_dir. join ( "src" ) . join ( f) , include_dir. join ( f) ) . unwrap ( ) ;
243
- }
244
- fs:: copy (
245
- build_dir. join ( "src" ) . join ( "lua51.lib" ) ,
246
- lib_dir. join ( "luajit.lib" ) ,
247
- )
248
- . unwrap ( ) ;
249
-
250
226
Artifacts {
251
- lib_dir,
252
- include_dir,
253
- libs : vec ! [ "luajit" . to_string( ) ] ,
227
+ lib_dir : build_dir. join ( "src" ) ,
228
+ libs : vec ! [ "lua51" . to_string( ) ] ,
254
229
}
255
230
}
256
231
@@ -293,10 +268,6 @@ fn cp_r(src: &Path, dst: &Path) {
293
268
}
294
269
295
270
impl Artifacts {
296
- pub fn include_dir ( & self ) -> & Path {
297
- & self . include_dir
298
- }
299
-
300
271
pub fn lib_dir ( & self ) -> & Path {
301
272
& self . lib_dir
302
273
}
@@ -317,7 +288,5 @@ impl Artifacts {
317
288
for lib in self . libs . iter ( ) {
318
289
println ! ( "cargo:rustc-link-lib=static={}" , lib) ;
319
290
}
320
- println ! ( "cargo:include={}" , self . include_dir. display( ) ) ;
321
- println ! ( "cargo:lib={}" , self . lib_dir. display( ) ) ;
322
291
}
323
292
}
0 commit comments