Skip to content
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 crates/build-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ pub use int_casts::IntTypeCastCallbacks;
/// Module for the `ExplicitIntTypesCallbacks` callbacks.
mod int_types;
pub use int_types::ExplicitIntTypesCallbacks;

/// Module for the `PhpConfigRunner` utility.
mod php_config_runner;
pub use php_config_runner::PhpConfigRunner;
68 changes: 68 additions & 0 deletions crates/build-tools/src/php_config_runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::ffi::{OsStr, OsString};
use std::process::Command;

/// Utility for running `php-config` commands.
#[derive(Debug)]
pub struct PhpConfigRunner {
/// Actual Command object.
inner: Command,
/// Arguments added to the command, for use in debugging.
args: Vec<OsString>,
}

impl PhpConfigRunner {
/// Create a new command runner.
#[must_use]
pub fn new() -> Self {
Self {
inner: Command::new("php-config"),
args: vec![],
}
}

/// Add an argument.
pub fn arg<S>(&mut self, arg: S) -> &mut Self
where
S: AsRef<OsStr>,
{
self.args.push(arg.as_ref().to_os_string());
let _: &mut Command = self.inner.arg(arg);
self
}

/// Run the command and return the output, which must be UTF-8.
///
/// # Panics
///
/// Panics if the command fails or returns output that is not valid UTF-8.
#[expect(clippy::panic, reason = "Panic is at build time")]
pub fn run(&mut self) -> String {
let output = self.inner.output().unwrap_or_else(|err| {
panic!(
"php-config {} should succeed, got {err}",
self.args
.iter()
.map(|arg| arg.display().to_string())
.collect::<Vec<_>>()
.join(" ")
)
});
let stdout_full = std::str::from_utf8(&output.stdout).unwrap_or_else(|err| {
panic!(
"php-config {} should result in UTF-8, got {err}",
self.args
.iter()
.map(|arg| arg.display().to_string())
.collect::<Vec<_>>()
.join(" ")
)
});
stdout_full.trim().to_owned()
}
}

impl Default for PhpConfigRunner {
fn default() -> Self {
Self::new()
}
}
4 changes: 2 additions & 2 deletions crates/sys/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ pub const ENABLE_CHROOT_FUNC: u32 = 1;
pub const GWINSZ_IN_SYS_IOCTL: u32 = 1;
pub const MAJOR_IN_SYSMACROS: u32 = 1;
pub const PCRE2_CODE_UNIT_WIDTH: u32 = 8;
pub const PHP_BUILD_SYSTEM : & [u8 ; 106] = b"Linux 77050b0d8e26 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux\0" ;
pub const PHP_BUILD_SYSTEM : & [u8 ; 106] = b"Linux b5e4910a2d64 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux\0" ;
pub const PHP_CAN_SUPPORT_PROC_OPEN: u32 = 1;
pub const PHP_OS: &[u8; 6] = b"Linux\0";
pub const PHP_SIGCHILD: u32 = 0;
pub const PHP_UNAME : & [u8 ; 106] = b"Linux 77050b0d8e26 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux\0" ;
pub const PHP_UNAME : & [u8 ; 106] = b"Linux b5e4910a2d64 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux\0" ;
pub const PHP_USE_PHP_CRYPT_R: u32 = 1;
pub const PHP_WRITE_STDOUT: u32 = 1;
pub const SIZEOF_INT: u32 = 4;
Expand Down
19 changes: 3 additions & 16 deletions crates/sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bindgen::EnumVariation;

use rsphp_build_tools::{
AnonymousTypeNames, BuildIdCallbacks, CommentProcessor, ExplicitIntTypesCallbacks,
IntTypeCastCallbacks, ZendHeaderIterator,
IntTypeCastCallbacks, PhpConfigRunner, ZendHeaderIterator,
};

fn main() {
Expand All @@ -17,21 +17,8 @@ fn main() {

println!("cargo:rerun-if-changed=build.rs");

let include_dir_output = std::process::Command::new("php-config")
.arg("--include-dir")
.output()
.expect("php-config --include-dir should succeed");
let include_dir_full = std::str::from_utf8(&include_dir_output.stdout)
.expect("php-config --include-dir should result in UTF8");
let include_dir = include_dir_full.trim();

let includes_output = std::process::Command::new("php-config")
.arg("--includes")
.output()
.expect("php-config --includes should succeed");
let includes_full = std::str::from_utf8(&includes_output.stdout)
.expect("php-config --includes should result in UTF8");
let includes = includes_full.trim();
let include_dir = PhpConfigRunner::new().arg("--include-dir").run();
let includes = PhpConfigRunner::new().arg("--includes").run();

let mut builder = bindgen::Builder::default();

Expand Down
Loading