@@ -2,6 +2,7 @@ use std::env;
22use std:: fs;
33use std:: path:: { Path , PathBuf } ;
44
5+ /// Represents the version of Lua to build.
56#[ derive( Debug , PartialEq , Eq ) ]
67pub enum Version {
78 Lua51 ,
@@ -11,6 +12,7 @@ pub enum Version {
1112}
1213pub use self :: Version :: * ;
1314
15+ /// Represents the configuration for building Lua artifacts.
1416pub struct Build {
1517 out_dir : Option < PathBuf > ,
1618 target : Option < String > ,
@@ -19,6 +21,7 @@ pub struct Build {
1921 debug : Option < bool > ,
2022}
2123
24+ /// Represents the artifacts produced by the build process.
2225#[ derive( Clone , Debug ) ]
2326pub struct Artifacts {
2427 include_dir : PathBuf ,
@@ -39,35 +42,55 @@ impl Default for Build {
3942}
4043
4144impl Build {
45+ /// Creates a new `Build` instance with default settings.
4246 pub fn new ( ) -> Build {
4347 Build :: default ( )
4448 }
4549
50+ /// Sets the output directory for the build artifacts.
51+ ///
52+ /// This is required if called outside of a build script.
4653 pub fn out_dir < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Build {
4754 self . out_dir = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
4855 self
4956 }
5057
58+ /// Sets the target architecture for the build.
59+ ///
60+ /// This is required if called outside of a build script.
5161 pub fn target ( & mut self , target : & str ) -> & mut Build {
5262 self . target = Some ( target. to_string ( ) ) ;
5363 self
5464 }
5565
66+ /// Sets the host architecture for the build.
67+ ///
68+ /// This is optional and will default to the environment variable `HOST` if not set.
69+ /// If called outside of a build script, it will default to the target architecture.
5670 pub fn host ( & mut self , host : & str ) -> & mut Build {
5771 self . host = Some ( host. to_string ( ) ) ;
5872 self
5973 }
6074
75+ /// Sets the optimization level for the build.
76+ ///
77+ /// This is optional and will default to the environment variable `OPT_LEVEL` if not set.
78+ /// If called outside of a build script, it will default to `0` in debug mode and `2` otherwise.
6179 pub fn opt_level ( & mut self , opt_level : & str ) -> & mut Build {
6280 self . opt_level = Some ( opt_level. to_string ( ) ) ;
6381 self
6482 }
6583
84+ /// Sets whether to build in debug mode.
85+ ///
86+ /// This is optional and will default to the value of `cfg!(debug_assertions)`.
87+ /// If set to `true`, it also enables Lua API checks.
6688 pub fn debug ( & mut self , debug : bool ) -> & mut Build {
6789 self . debug = Some ( debug) ;
6890 self
6991 }
7092
93+ /// Builds the Lua artifacts for the specified version.
7194 pub fn build ( & self , version : Version ) -> Artifacts {
7295 let target = & self . target . as_ref ( ) . expect ( "TARGET is not set" ) [ ..] ;
7396 let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR is not set" ) ;
@@ -213,18 +236,25 @@ impl Version {
213236}
214237
215238impl Artifacts {
239+ /// Returns the directory containing the Lua headers.
216240 pub fn include_dir ( & self ) -> & Path {
217241 & self . include_dir
218242 }
219243
244+ /// Returns the directory containing the Lua libraries.
220245 pub fn lib_dir ( & self ) -> & Path {
221246 & self . lib_dir
222247 }
223248
249+ /// Returns the names of the Lua libraries built.
224250 pub fn libs ( & self ) -> & [ String ] {
225251 & self . libs
226252 }
227253
254+ /// Prints the necessary Cargo metadata for linking the Lua libraries.
255+ ///
256+ /// This method is typically called in a build script to inform Cargo
257+ /// about the location of the Lua libraries and how to link them.
228258 pub fn print_cargo_metadata ( & self ) {
229259 println ! ( "cargo:rustc-link-search=native={}" , self . lib_dir. display( ) ) ;
230260 for lib in self . libs . iter ( ) {
0 commit comments