From 3869d575ae16cfd08978f74f25915d0f7c0ed70d Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:17:30 +0200 Subject: [PATCH 1/5] + Add PHP_LIB for DEBUG version of RUST DLL Extension module --- windows_build.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/windows_build.rs b/windows_build.rs index e946b55ce..aaefac289 100644 --- a/windows_build.rs +++ b/windows_build.rs @@ -23,7 +23,7 @@ impl<'a> Provider<'a> { fn get_php_lib_name(&self) -> Result { Ok(self .devel - .php_lib() + .php_lib(self.info.debug()?) .file_stem() .context("Failed to get PHP library name")? .to_string_lossy() @@ -85,7 +85,7 @@ impl<'a> PHPProvider<'a> for Provider<'a> { let php_lib_name = self.get_php_lib_name()?; let php_lib_search = self .devel - .php_lib() + .php_lib(self.info.debug()?) .parent() .context("Failed to get PHP library parent folder")? .to_string_lossy() @@ -233,12 +233,36 @@ impl DevelPack { } /// Returns the path of the PHP library containing symbols for linking. - pub fn php_lib(&self) -> PathBuf { - let php_nts = self.0.join("lib").join("php8.lib"); + pub fn php_lib(&self, is_debug: bool) -> PathBuf { + + let lib_name = match is_debug { + true => "php8ts_debug.lib", + false => "php8.lib", + }; + + let php_nts = if let Ok(php_lib_path) = std::env::var("PHP_LIB") { + let custom_path = PathBuf::from(php_lib_path); + if custom_path.exists() { + custom_path.join(lib_name) + } else { + eprintln!("Warning: PHP_LIB is set to {}, but the file does not exist", custom_path.display()); + self.0.join("lib").join(lib_name) + } + } else { + if is_debug { + panic!(r#"To build the application in DEBUG mode on Windows, +you must have a PHP SDK builded with the DEBUG option enabled +and specify the PHP_LIB to the folder containing the lib files. +For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#); + } + + self.0.join("lib").join(lib_name) + }; + if php_nts.exists() { php_nts } else { - self.0.join("lib").join("php8ts.lib") + self.0.join("lib").join(lib_name) } } From 240200943b966ac2126a0cced6cabccdb5e0d0cf Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:24:47 +0200 Subject: [PATCH 2/5] % refactoring logic for pub fn php_lib(&self, is_debug: bool) -> PathBuf --- windows_build.rs | 55 ++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/windows_build.rs b/windows_build.rs index aaefac289..03bf53f5d 100644 --- a/windows_build.rs +++ b/windows_build.rs @@ -235,35 +235,40 @@ impl DevelPack { /// Returns the path of the PHP library containing symbols for linking. pub fn php_lib(&self, is_debug: bool) -> PathBuf { - let lib_name = match is_debug { - true => "php8ts_debug.lib", - false => "php8.lib", - }; + let php_lib_path = std::env::var("PHP_LIB") + .map(PathBuf::from) + .unwrap_or_else(|_| self.0.join("lib")); - let php_nts = if let Ok(php_lib_path) = std::env::var("PHP_LIB") { - let custom_path = PathBuf::from(php_lib_path); - if custom_path.exists() { - custom_path.join(lib_name) - } else { - eprintln!("Warning: PHP_LIB is set to {}, but the file does not exist", custom_path.display()); - self.0.join("lib").join(lib_name) - } - } else { - if is_debug { - panic!(r#"To build the application in DEBUG mode on Windows, -you must have a PHP SDK builded with the DEBUG option enabled -and specify the PHP_LIB to the folder containing the lib files. -For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#); - } + if !php_lib_path.exists() { + panic!("Error: Specified PHP library path '{}' does not exist.", php_lib_path.display()); + } - self.0.join("lib").join(lib_name) + let candidates = if is_debug { + ["php8_debug.lib", "php8ts_debug.lib"] + } else { + ["php8.lib", "php8ts.lib"] }; - if php_nts.exists() { - php_nts - } else { - self.0.join("lib").join(lib_name) - } + candidates + .iter() + .map(|lib| php_lib_path.join(lib)) + .find(|path| path.exists()) + .unwrap_or_else(|| + panic!( + "{}", + if is_debug { + format!( + r#"Error: No suitable PHP library found in '{}'. +To build the application in DEBUG mode on Windows, +you must have a PHP SDK built with the DEBUG option enabled +and specify the PHP_LIB to the folder containing the lib files. +For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#, + php_lib_path.display() + ) + } else { + format!("Error: No suitable PHP library found in '{}'.", php_lib_path.display()) + } + )) } /// Returns a list of include paths to pass to the compiler. From 9080ecaa2e93c0c0350a6fab510eb73831b7d7ea Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:30:18 +0200 Subject: [PATCH 3/5] + update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index edc274aa3..5055c99ba 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,10 @@ best resource at the moment. This can be viewed at [docs.rs]. bundled with Microsoft Visual Studio. - `cargo-php`'s stub generation feature does not work on Windows. Rewriting this functionality to be cross-platform is on the roadmap. +- To build the application in `DEBUG` mode on Windows, + you must have a `PHP SDK` built with the `DEBUG` option enabled + and specify the `PHP_LIB` to the folder containing the lib files. + For example: set `PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS`. [vectorcall]: https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-170 From 24ffac338be7175430f34cfb7e94d569cc01974c Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:54:26 +0200 Subject: [PATCH 4/5] * use expect for better code style --- windows_build.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/windows_build.rs b/windows_build.rs index 03bf53f5d..51e7819ee 100644 --- a/windows_build.rs +++ b/windows_build.rs @@ -253,22 +253,21 @@ impl DevelPack { .iter() .map(|lib| php_lib_path.join(lib)) .find(|path| path.exists()) - .unwrap_or_else(|| - panic!( - "{}", - if is_debug { - format!( - r#"Error: No suitable PHP library found in '{}'. + .expect(&format!( + "{}", + if is_debug { + format!( + r#"Error: No suitable PHP library found in '{}'. To build the application in DEBUG mode on Windows, you must have a PHP SDK built with the DEBUG option enabled and specify the PHP_LIB to the folder containing the lib files. For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS."#, - php_lib_path.display() - ) - } else { - format!("Error: No suitable PHP library found in '{}'.", php_lib_path.display()) - } - )) + php_lib_path.display() + ) + } else { + format!("Error: No suitable PHP library found in '{}'.", php_lib_path.display()) + } + )) } /// Returns a list of include paths to pass to the compiler. From e221600437fb5abb99b954b2ec48dedd7a467046 Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:17:15 +0200 Subject: [PATCH 5/5] * apply cargo fmt --- windows_build.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/windows_build.rs b/windows_build.rs index 51e7819ee..607cdcc34 100644 --- a/windows_build.rs +++ b/windows_build.rs @@ -234,13 +234,15 @@ impl DevelPack { /// Returns the path of the PHP library containing symbols for linking. pub fn php_lib(&self, is_debug: bool) -> PathBuf { - let php_lib_path = std::env::var("PHP_LIB") .map(PathBuf::from) .unwrap_or_else(|_| self.0.join("lib")); if !php_lib_path.exists() { - panic!("Error: Specified PHP library path '{}' does not exist.", php_lib_path.display()); + panic!( + "Error: Specified PHP library path '{}' does not exist.", + php_lib_path.display() + ); } let candidates = if is_debug { @@ -265,7 +267,10 @@ For example: set PHP_LIB=C:\php-sdk\php-dev\vc16\x64\php-8.3.13-src\x64\Debug_TS php_lib_path.display() ) } else { - format!("Error: No suitable PHP library found in '{}'.", php_lib_path.display()) + format!( + "Error: No suitable PHP library found in '{}'.", + php_lib_path.display() + ) } )) }