Skip to content

Commit ac1cd59

Browse files
committed
Add debug option
1 parent b47c8de commit ac1cd59

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Build {
99
target: Option<String>,
1010
host: Option<String>,
1111
lua52compat: bool,
12+
debug: Option<bool>,
1213
}
1314

1415
/// Represents the artifacts produced by the build process.
@@ -25,6 +26,7 @@ impl Default for Build {
2526
target: env::var("TARGET").ok(),
2627
host: env::var("HOST").ok(),
2728
lua52compat: false,
29+
debug: None,
2830
}
2931
}
3032
}
@@ -66,6 +68,15 @@ impl Build {
6668
self
6769
}
6870

71+
/// Sets whether to build LuaJIT in debug mode.
72+
///
73+
/// This is optional and will default to the value of `cfg!(debug_assertions)`.
74+
/// If set to `true`, it also enables Lua API checks.
75+
pub fn debug(&mut self, debug: bool) -> &mut Build {
76+
self.debug = Some(debug);
77+
self
78+
}
79+
6980
fn cmd_make(&self) -> Command {
7081
match &self.host.as_ref().expect("HOST is not set")[..] {
7182
"x86_64-unknown-dragonfly" => Command::new("gmake"),
@@ -108,7 +119,6 @@ impl Build {
108119

109120
// Copy release version file
110121
let relver = build_dir.join(".relver");
111-
#[rustfmt::skip]
112122
fs::copy(manifest_dir.join("luajit_relver.txt"), &relver).unwrap();
113123

114124
// Fix permissions for certain build situations
@@ -209,7 +219,10 @@ impl Build {
209219
if self.lua52compat {
210220
xcflags.push("-DLUAJIT_ENABLE_LUA52COMPAT");
211221
}
212-
if cfg!(debug_assertions) {
222+
223+
let debug = self.debug.unwrap_or(cfg!(debug_assertions));
224+
if debug {
225+
make.env("CCDEBUG", "-g");
213226
xcflags.push("-DLUA_USE_ASSERT");
214227
xcflags.push("-DLUA_USE_APICHECK");
215228
}

0 commit comments

Comments
 (0)