@@ -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,13 +233,46 @@ 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" ) ;
238- if php_nts. exists ( ) {
239- php_nts
240- } else {
241- self . 0 . join ( "lib" ) . join ( "php8ts.lib" )
236+ pub fn php_lib ( & self , is_debug : bool ) -> PathBuf {
237+ let php_lib_path = std:: env:: var ( "PHP_LIB" )
238+ . map ( PathBuf :: from)
239+ . unwrap_or_else ( |_| self . 0 . join ( "lib" ) ) ;
240+
241+ if !php_lib_path. exists ( ) {
242+ panic ! (
243+ "Error: Specified PHP library path '{}' does not exist." ,
244+ php_lib_path. display( )
245+ ) ;
242246 }
247+
248+ let candidates = if is_debug {
249+ [ "php8_debug.lib" , "php8ts_debug.lib" ]
250+ } else {
251+ [ "php8.lib" , "php8ts.lib" ]
252+ } ;
253+
254+ candidates
255+ . iter ( )
256+ . map ( |lib| php_lib_path. join ( lib) )
257+ . find ( |path| path. exists ( ) )
258+ . expect ( & format ! (
259+ "{}" ,
260+ if is_debug {
261+ format!(
262+ r#"Error: No suitable PHP library found in '{}'.
263+ To build the application in DEBUG mode on Windows,
264+ you must have a PHP SDK built with the DEBUG option enabled
265+ and specify the PHP_LIB to the folder containing the lib files.
266+ For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."# ,
267+ php_lib_path. display( )
268+ )
269+ } else {
270+ format!(
271+ "Error: No suitable PHP library found in '{}'." ,
272+ php_lib_path. display( )
273+ )
274+ }
275+ ) )
243276 }
244277
245278 /// Returns a list of include paths to pass to the compiler.
0 commit comments