Skip to content

Commit 630b2ed

Browse files
committed
+ Add PHP_LIB for DEBUG version of RUST DLL Extension module
1 parent 64fbb41 commit 630b2ed

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

windows_build.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'a> Provider<'a> {
2323
fn get_php_lib_name(&self) -> Result<String> {
2424
Ok(self
2525
.devel
26-
.php_lib()
26+
.php_lib(self.info.debug()?)
2727
.file_stem()
2828
.context("Failed to get PHP library name")?
2929
.to_string_lossy()
@@ -85,7 +85,7 @@ impl<'a> PHPProvider<'a> for Provider<'a> {
8585
let php_lib_name = self.get_php_lib_name()?;
8686
let php_lib_search = self
8787
.devel
88-
.php_lib()
88+
.php_lib(self.info.debug()?)
8989
.parent()
9090
.context("Failed to get PHP library parent folder")?
9191
.to_string_lossy()
@@ -233,12 +233,36 @@ impl DevelPack {
233233
}
234234

235235
/// Returns the path of the PHP library containing symbols for linking.
236-
pub fn php_lib(&self) -> PathBuf {
237-
let php_nts = self.0.join("lib").join("php8.lib");
236+
pub fn php_lib(&self, is_debug: bool) -> PathBuf {
237+
238+
let lib_name = match is_debug {
239+
true => "php8ts_debug.lib",
240+
false => "php8.lib",
241+
};
242+
243+
let php_nts = if let Ok(php_lib_path) = std::env::var("PHP_LIB") {
244+
let custom_path = PathBuf::from(php_lib_path);
245+
if custom_path.exists() {
246+
custom_path.join(lib_name)
247+
} else {
248+
eprintln!("Warning: PHP_LIB is set to {}, but the file does not exist", custom_path.display());
249+
self.0.join("lib").join(lib_name)
250+
}
251+
} else {
252+
if is_debug {
253+
panic!(r#"To build the application in DEBUG mode on Windows,
254+
you must have a PHP SDK builded with the DEBUG option enabled
255+
and specify the PHP_LIB to the folder containing the lib files.
256+
For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#);
257+
}
258+
259+
self.0.join("lib").join(lib_name)
260+
};
261+
238262
if php_nts.exists() {
239263
php_nts
240264
} else {
241-
self.0.join("lib").join("php8ts.lib")
265+
self.0.join("lib").join(lib_name)
242266
}
243267
}
244268

0 commit comments

Comments
 (0)