Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows - add a DEBUG build with debugging symbols #350

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 41 additions & 8 deletions windows_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a> Provider<'a> {
fn get_php_lib_name(&self) -> Result<String> {
Ok(self
.devel
.php_lib()
.php_lib(self.info.debug()?)
.file_stem()
.context("Failed to get PHP library name")?
.to_string_lossy()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -233,13 +233,46 @@ 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");
if php_nts.exists() {
php_nts
} else {
self.0.join("lib").join("php8ts.lib")
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()
);
}

let candidates = if is_debug {
["php8_debug.lib", "php8ts_debug.lib"]
} else {
["php8.lib", "php8ts.lib"]
};

candidates
.iter()
.map(|lib| php_lib_path.join(lib))
.find(|path| path.exists())
.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()
)
}
))
}

/// Returns a list of include paths to pass to the compiler.
Expand Down
Loading