@@ -7,30 +7,29 @@ pub struct Build {
77 out_dir : Option < PathBuf > ,
88 target : Option < String > ,
99 host : Option < String > ,
10- options : Options ,
10+ lua52compat : bool ,
1111}
1212
1313pub struct Artifacts {
14- include_dir : PathBuf ,
1514 lib_dir : PathBuf ,
1615 libs : Vec < String > ,
1716}
1817
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 {
2720 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) ,
2922 target : env:: var ( "TARGET" ) . ok ( ) ,
3023 host : env:: var ( "HOST" ) . ok ( ) ,
31- options : Options :: default ( ) ,
24+ lua52compat : false ,
3225 }
3326 }
27+ }
28+
29+ impl Build {
30+ pub fn new ( ) -> Build {
31+ Build :: default ( )
32+ }
3433
3534 pub fn out_dir < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Build {
3635 self . out_dir = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
@@ -48,7 +47,7 @@ impl Build {
4847 }
4948
5049 pub fn lua52compat ( & mut self , enabled : bool ) -> & mut Build {
51- self . options . lua52compat = enabled;
50+ self . lua52compat = enabled;
5251 self
5352 }
5453
@@ -75,22 +74,18 @@ impl Build {
7574 let host = & self . host . as_ref ( ) . expect ( "HOST not set" ) [ ..] ;
7675 let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR not set" ) ;
7776 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 ( ) ;
8982 }
83+ fs:: create_dir_all ( & build_dir)
84+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
9085 cp_r ( & source_dir, & build_dir) ;
9186
9287 let mut cc = cc:: Build :: new ( ) ;
93- cc. target ( target ) . host ( host ) . warnings ( false ) . opt_level ( 2 ) ;
88+ cc. warnings ( false ) ;
9489 let compiler = cc. get_compiler ( ) ;
9590 let compiler_path = compiler. path ( ) . to_str ( ) . unwrap ( ) ;
9691
@@ -179,27 +174,21 @@ impl Build {
179174 }
180175
181176 let mut xcflags = vec ! [ "-fPIC" ] ;
182- if self . options . lua52compat {
177+ if self . lua52compat {
183178 xcflags. push ( "-DLUAJIT_ENABLE_LUA52COMPAT" ) ;
184179 }
180+ if cfg ! ( debug_assertions) {
181+ xcflags. push ( "-DLUA_USE_ASSERT" ) ;
182+ xcflags. push ( "-DLUA_USE_APICHECK" ) ;
183+ }
185184
186185 make. env ( "BUILDMODE" , "static" ) ;
187186 make. env ( "XCFLAGS" , xcflags. join ( " " ) ) ;
188187 self . run_command ( make, "building LuaJIT" ) ;
189188
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-
199189 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( ) ] ,
203192 }
204193 }
205194
@@ -209,23 +198,19 @@ impl Build {
209198 let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
210199 let source_dir = manifest_dir. join ( "luajit2" ) ;
211200 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 ( ) ;
223206 }
207+ fs:: create_dir_all ( & build_dir)
208+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
224209 cp_r ( & source_dir, & build_dir) ;
225210
226211 let mut msvcbuild = Command :: new ( build_dir. join ( "src" ) . join ( "msvcbuild.bat" ) ) ;
227212 msvcbuild. current_dir ( build_dir. join ( "src" ) ) ;
228- if self . options . lua52compat {
213+ if self . lua52compat {
229214 cp_r ( & extras_dir, & build_dir. join ( "src" ) ) ;
230215 msvcbuild. arg ( "lua52c" ) ;
231216 }
@@ -238,19 +223,9 @@ impl Build {
238223
239224 self . run_command ( msvcbuild, "building LuaJIT" ) ;
240225
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-
250226 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( ) ] ,
254229 }
255230 }
256231
@@ -293,10 +268,6 @@ fn cp_r(src: &Path, dst: &Path) {
293268}
294269
295270impl Artifacts {
296- pub fn include_dir ( & self ) -> & Path {
297- & self . include_dir
298- }
299-
300271 pub fn lib_dir ( & self ) -> & Path {
301272 & self . lib_dir
302273 }
@@ -317,7 +288,5 @@ impl Artifacts {
317288 for lib in self . libs . iter ( ) {
318289 println ! ( "cargo:rustc-link-lib=static={}" , lib) ;
319290 }
320- println ! ( "cargo:include={}" , self . include_dir. display( ) ) ;
321- println ! ( "cargo:lib={}" , self . lib_dir. display( ) ) ;
322291 }
323292}
0 commit comments