ext-php-rs/unix_build.rs

59 lines
1.8 KiB
Rust
Raw Normal View History

Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
use std::{path::PathBuf, process::Command};
use anyhow::{bail, Context, Result};
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
use crate::{find_executable, path_from_env, PHPInfo, PHPProvider};
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
pub struct Provider {}
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
impl Provider {
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
/// Runs `php-config` with one argument, returning the stdout.
fn php_config(&self, arg: &str) -> Result<String> {
let cmd = Command::new(self.find_bin()?)
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
.arg(arg)
.output()
.context("Failed to run `php-config`")?;
let stdout = String::from_utf8_lossy(&cmd.stdout);
if !cmd.status.success() {
let stderr = String::from_utf8_lossy(&cmd.stderr);
bail!("Failed to run `php-config`: {} {}", stdout, stderr);
}
Ok(stdout.to_string())
}
fn find_bin(&self) -> Result<PathBuf> {
// If path is given via env, it takes priority.
if let Some(path) = path_from_env("PHP_CONFIG") {
if !path.try_exists()? {
// If path was explicitly given and it can't be found, this is a hard error
bail!("php-config executable not found at {:?}", path);
}
return Ok(path);
}
find_executable("php-config").with_context(|| {
"Could not find `php-config` executable. \
Please ensure `php-config` is in your PATH or the \
`PHP_CONFIG` environment variable is set."
})
}
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
}
impl<'a> PHPProvider<'a> for Provider {
fn new(_: &'a PHPInfo) -> Result<Self> {
Ok(Self {})
Windows support (#128) * Preliminary Windows support * Start work on cross-platform build script * Fix compilation on macOS * Updated README, tidied up build script * Check linker version before starting compilation It doesn't seem like it's possible to change the linker from within the build script, however, we can retrieve the linker in use and give the user a suggestion if the linker will not work. * Switch to using Github repository for bindgen * Split Windows and Unix implementations into two files * Fix building on Windows * Remove `reqwest` and `zip` as dependencies on Unix * Fix guide tests on Windows * Started work on Windows CI * runs -> run * Use preinstalled LLVM on Windows * Debugging for Windows CI * Switch to upstream `rust-bindgen` master branch * Switch to `rust-lld` for Windows linking * Don't compile `cargo-php` on Windows * Switch to using skeptic for tests * cargo-php: Disable stub generation, fix ext install/remove The plan is to replace the stub generation by generating them with PHP code. This is cross-platform and means we don't need to worry about ABI. We also don't need to embed information into the library. * cargo-php: Fix on unix OS * Fix clippy lint * Updated README * Re-add CI for Unix + PHP 8.0 * Fix building on thread-safe PHP * Tidy up build scripts * Use dynamic lookup on Linux, test with TS Windows * Define `ZTS` when compiling PHP ZTS * Combine Windows and Unix CI, fix linking for Win32TS * Fix exclusions in build CI * rust-toolchain -> rust * Set LLVM version * Only build docs.rs on Ubuntu PHP 8.1 * Fix build on Linux thread-safe * Update guide example
2022-03-18 04:36:51 +01:00
}
fn get_includes(&self) -> Result<Vec<PathBuf>> {
Ok(self
.php_config("--includes")?
.split(' ')
.map(|s| s.trim_start_matches("-I"))
.map(PathBuf::from)
.collect())
}
fn get_defines(&self) -> Result<Vec<(&'static str, &'static str)>> {
Ok(vec![])
}
}