@@ -13,6 +13,7 @@ pub struct Build {
1313
1414/// Represents the artifacts produced by the build process.
1515pub struct Artifacts {
16+ include_dir : PathBuf ,
1617 lib_dir : PathBuf ,
1718 libs : Vec < String > ,
1819}
@@ -91,13 +92,18 @@ impl Build {
9192 let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
9293 let source_dir = manifest_dir. join ( "luajit2" ) ;
9394 let build_dir = out_dir. join ( "luajit-build" ) ;
95+ let lib_dir = out_dir. join ( "lib" ) ;
96+ let include_dir = out_dir. join ( "include" ) ;
9497
9598 // Cleanup
96- if build_dir. exists ( ) {
97- fs:: remove_dir_all ( & build_dir) . unwrap ( ) ;
99+ for dir in [ & build_dir, & lib_dir, & include_dir] {
100+ if dir. exists ( ) {
101+ fs:: remove_dir_all ( dir)
102+ . unwrap_or_else ( |e| panic ! ( "cannot remove {}: {e}" , dir. display( ) ) ) ;
103+ }
104+ fs:: create_dir_all ( dir)
105+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {e}" , dir. display( ) ) ) ;
98106 }
99- fs:: create_dir_all ( & build_dir)
100- . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
101107 cp_r ( & source_dir, & build_dir) ;
102108
103109 // Copy release version file
@@ -212,10 +218,7 @@ impl Build {
212218 make. env ( "XCFLAGS" , xcflags. join ( " " ) ) ;
213219 self . run_command ( make, "building LuaJIT" ) ;
214220
215- Artifacts {
216- lib_dir : build_dir. join ( "src" ) ,
217- libs : vec ! [ "luajit" . to_string( ) ] ,
218- }
221+ Artifacts :: make ( & build_dir, & include_dir, & lib_dir, false )
219222 }
220223
221224 fn build_msvc ( & mut self ) -> Artifacts {
@@ -224,13 +227,18 @@ impl Build {
224227 let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
225228 let source_dir = manifest_dir. join ( "luajit2" ) ;
226229 let build_dir = out_dir. join ( "luajit-build" ) ;
230+ let lib_dir = out_dir. join ( "lib" ) ;
231+ let include_dir = out_dir. join ( "include" ) ;
227232
228233 // Cleanup
229- if build_dir. exists ( ) {
230- fs:: remove_dir_all ( & build_dir) . unwrap ( ) ;
234+ for dir in [ & build_dir, & lib_dir, & include_dir] {
235+ if dir. exists ( ) {
236+ fs:: remove_dir_all ( dir)
237+ . unwrap_or_else ( |e| panic ! ( "cannot remove {}: {e}" , dir. display( ) ) ) ;
238+ }
239+ fs:: create_dir_all ( dir)
240+ . unwrap_or_else ( |e| panic ! ( "cannot create {}: {e}" , dir. display( ) ) ) ;
231241 }
232- fs:: create_dir_all ( & build_dir)
233- . unwrap_or_else ( |e| panic ! ( "cannot create {}: {}" , build_dir. display( ) , e) ) ;
234242 cp_r ( & source_dir, & build_dir) ;
235243
236244 // Copy release version file
@@ -251,10 +259,7 @@ impl Build {
251259
252260 self . run_command ( msvcbuild, "building LuaJIT" ) ;
253261
254- Artifacts {
255- lib_dir : build_dir. join ( "src" ) ,
256- libs : vec ! [ "lua51" . to_string( ) ] ,
257- }
262+ Artifacts :: make ( & build_dir, & include_dir, & lib_dir, true )
258263 }
259264
260265 fn run_command ( & self , mut command : Command , desc : & str ) {
@@ -294,6 +299,11 @@ fn cp_r(src: &Path, dst: &Path) {
294299}
295300
296301impl Artifacts {
302+ /// Returns the directory containing the LuaJIT headers.
303+ pub fn include_dir ( & self ) -> & Path {
304+ & self . include_dir
305+ }
306+
297307 /// Returns the directory containing the LuaJIT libraries.
298308 pub fn lib_dir ( & self ) -> & Path {
299309 & self . lib_dir
@@ -321,4 +331,22 @@ impl Artifacts {
321331 println ! ( "cargo:rustc-link-lib=static={lib}" ) ;
322332 }
323333 }
334+
335+ fn make ( build_dir : & Path , include_dir : & Path , lib_dir : & Path , is_msvc : bool ) -> Self {
336+ for f in & [ "lauxlib.h" , "lua.h" , "luaconf.h" , "luajit.h" , "lualib.h" ] {
337+ fs:: copy ( build_dir. join ( "src" ) . join ( f) , include_dir. join ( f) ) . unwrap ( ) ;
338+ }
339+
340+ let lib_name = if !is_msvc { "luajit" } else { "lua51" } ;
341+ let lib_file = if !is_msvc { "libluajit.a" } else { "lua51.lib" } ;
342+ if build_dir. join ( "src" ) . join ( lib_file) . exists ( ) {
343+ fs:: copy ( build_dir. join ( "src" ) . join ( lib_file) , lib_dir. join ( lib_file) ) . unwrap ( ) ;
344+ }
345+
346+ Artifacts {
347+ lib_dir : lib_dir. to_path_buf ( ) ,
348+ include_dir : include_dir. to_path_buf ( ) ,
349+ libs : vec ! [ lib_name. to_string( ) ] ,
350+ }
351+ }
324352}
0 commit comments