@@ -2,6 +2,7 @@ use std::env;
2
2
use std:: fs;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
5
+ /// Represents the version of Lua to build.
5
6
#[ derive( Debug , PartialEq , Eq ) ]
6
7
pub enum Version {
7
8
Lua51 ,
@@ -11,6 +12,7 @@ pub enum Version {
11
12
}
12
13
pub use self :: Version :: * ;
13
14
15
+ /// Represents the configuration for building Lua artifacts.
14
16
pub struct Build {
15
17
out_dir : Option < PathBuf > ,
16
18
target : Option < String > ,
@@ -19,6 +21,7 @@ pub struct Build {
19
21
debug : Option < bool > ,
20
22
}
21
23
24
+ /// Represents the artifacts produced by the build process.
22
25
#[ derive( Clone , Debug ) ]
23
26
pub struct Artifacts {
24
27
include_dir : PathBuf ,
@@ -39,35 +42,55 @@ impl Default for Build {
39
42
}
40
43
41
44
impl Build {
45
+ /// Creates a new `Build` instance with default settings.
42
46
pub fn new ( ) -> Build {
43
47
Build :: default ( )
44
48
}
45
49
50
+ /// Sets the output directory for the build artifacts.
51
+ ///
52
+ /// This is required if called outside of a build script.
46
53
pub fn out_dir < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Build {
47
54
self . out_dir = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
48
55
self
49
56
}
50
57
58
+ /// Sets the target architecture for the build.
59
+ ///
60
+ /// This is required if called outside of a build script.
51
61
pub fn target ( & mut self , target : & str ) -> & mut Build {
52
62
self . target = Some ( target. to_string ( ) ) ;
53
63
self
54
64
}
55
65
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.
56
70
pub fn host ( & mut self , host : & str ) -> & mut Build {
57
71
self . host = Some ( host. to_string ( ) ) ;
58
72
self
59
73
}
60
74
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.
61
79
pub fn opt_level ( & mut self , opt_level : & str ) -> & mut Build {
62
80
self . opt_level = Some ( opt_level. to_string ( ) ) ;
63
81
self
64
82
}
65
83
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.
66
88
pub fn debug ( & mut self , debug : bool ) -> & mut Build {
67
89
self . debug = Some ( debug) ;
68
90
self
69
91
}
70
92
93
+ /// Builds the Lua artifacts for the specified version.
71
94
pub fn build ( & self , version : Version ) -> Artifacts {
72
95
let target = & self . target . as_ref ( ) . expect ( "TARGET is not set" ) [ ..] ;
73
96
let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR is not set" ) ;
@@ -213,18 +236,25 @@ impl Version {
213
236
}
214
237
215
238
impl Artifacts {
239
+ /// Returns the directory containing the Lua headers.
216
240
pub fn include_dir ( & self ) -> & Path {
217
241
& self . include_dir
218
242
}
219
243
244
+ /// Returns the directory containing the Lua libraries.
220
245
pub fn lib_dir ( & self ) -> & Path {
221
246
& self . lib_dir
222
247
}
223
248
249
+ /// Returns the names of the Lua libraries built.
224
250
pub fn libs ( & self ) -> & [ String ] {
225
251
& self . libs
226
252
}
227
253
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.
228
258
pub fn print_cargo_metadata ( & self ) {
229
259
println ! ( "cargo:rustc-link-search=native={}" , self . lib_dir. display( ) ) ;
230
260
for lib in self . libs . iter ( ) {
0 commit comments