@@ -3,13 +3,15 @@ use std::fs;
33use std:: path:: { Path , PathBuf } ;
44use std:: process:: Command ;
55
6+ /// Represents the configuration for building LuaJIT artifacts.
67pub struct Build {
78 out_dir : Option < PathBuf > ,
89 target : Option < String > ,
910 host : Option < String > ,
1011 lua52compat : bool ,
1112}
1213
14+ /// Represents the artifacts produced by the build process.
1315pub struct Artifacts {
1416 lib_dir : PathBuf ,
1517 libs : Vec < String > ,
@@ -27,25 +29,37 @@ impl Default for Build {
2729}
2830
2931impl Build {
32+ /// Creates a new `Build` instance with default settings.
3033 pub fn new ( ) -> Build {
3134 Build :: default ( )
3235 }
3336
37+ /// Sets the output directory for the build artifacts.
38+ ///
39+ /// This is required if called outside of a build script.
3440 pub fn out_dir < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Build {
3541 self . out_dir = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
3642 self
3743 }
3844
45+ /// Sets the target architecture for the build.
46+ ///
47+ /// This is required if called outside of a build script.
3948 pub fn target ( & mut self , target : & str ) -> & mut Build {
4049 self . target = Some ( target. to_string ( ) ) ;
4150 self
4251 }
4352
53+ /// Sets the host architecture for the build.
54+ ///
55+ /// This is optional and will default to the environment variable `HOST` if not set.
56+ /// If called outside of a build script, it will default to the target architecture.
4457 pub fn host ( & mut self , host : & str ) -> & mut Build {
4558 self . host = Some ( host. to_string ( ) ) ;
4659 self
4760 }
4861
62+ /// Enables or disables Lua 5.2 limited compatibility mode.
4963 pub fn lua52compat ( & mut self , enabled : bool ) -> & mut Build {
5064 self . lua52compat = enabled;
5165 self
@@ -59,6 +73,7 @@ impl Build {
5973 }
6074 }
6175
76+ /// Builds the LuaJIT artifacts.
6277 pub fn build ( & mut self ) -> Artifacts {
6378 let target = & self . target . as_ref ( ) . expect ( "TARGET is not set" ) [ ..] ;
6479
@@ -279,14 +294,20 @@ fn cp_r(src: &Path, dst: &Path) {
279294}
280295
281296impl Artifacts {
297+ /// Returns the directory containing the LuaJIT libraries.
282298 pub fn lib_dir ( & self ) -> & Path {
283299 & self . lib_dir
284300 }
285301
302+ /// Returns the names of the LuaJIT libraries built.
286303 pub fn libs ( & self ) -> & [ String ] {
287304 & self . libs
288305 }
289306
307+ /// Prints the necessary Cargo metadata for linking the LuaJIT libraries.
308+ ///
309+ /// This method is typically called in a build script to inform Cargo
310+ /// about the location of the LuaJIT libraries and how to link them.
290311 pub fn print_cargo_metadata ( & self ) {
291312 println ! ( "cargo:rerun-if-env-changed=HOST_CC" ) ;
292313 println ! ( "cargo:rerun-if-env-changed=STATIC_CC" ) ;
0 commit comments