Skip to content

Commit ce7e928

Browse files
committed
% refactoring logic for pub fn php_lib(&self, is_debug: bool) -> PathBuf
1 parent 630b2ed commit ce7e928

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

windows_build.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,35 +235,40 @@ impl DevelPack {
235235
/// Returns the path of the PHP library containing symbols for linking.
236236
pub fn php_lib(&self, is_debug: bool) -> PathBuf {
237237

238-
let lib_name = match is_debug {
239-
true => "php8ts_debug.lib",
240-
false => "php8.lib",
241-
};
238+
let php_lib_path = std::env::var("PHP_LIB")
239+
.map(PathBuf::from)
240+
.unwrap_or_else(|_| self.0.join("lib"));
242241

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-
}
242+
if !php_lib_path.exists() {
243+
panic!("Error: Specified PHP library path '{}' does not exist.", php_lib_path.display());
244+
}
258245

259-
self.0.join("lib").join(lib_name)
246+
let candidates = if is_debug {
247+
["php8_debug.lib", "php8ts_debug.lib"]
248+
} else {
249+
["php8.lib", "php8ts.lib"]
260250
};
261251

262-
if php_nts.exists() {
263-
php_nts
264-
} else {
265-
self.0.join("lib").join(lib_name)
266-
}
252+
candidates
253+
.iter()
254+
.map(|lib| php_lib_path.join(lib))
255+
.find(|path| path.exists())
256+
.unwrap_or_else(||
257+
panic!(
258+
"{}",
259+
if is_debug {
260+
format!(
261+
r#"Error: No suitable PHP library found in '{}'.
262+
To build the application in DEBUG mode on Windows,
263+
you must have a PHP SDK built with the DEBUG option enabled
264+
and specify the PHP_LIB to the folder containing the lib files.
265+
For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#,
266+
php_lib_path.display()
267+
)
268+
} else {
269+
format!("Error: No suitable PHP library found in '{}'.", php_lib_path.display())
270+
}
271+
))
267272
}
268273

269274
/// Returns a list of include paths to pass to the compiler.

0 commit comments

Comments
 (0)