mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 18:54:07 +02:00
sys: Use includes from php-config --include-dir
If PHP headers are already available, it feels kinda redundant to clone the PHP sources and rebuild them again just to generate bindings. So if php-config is available in $PATH, we don't clone + compile anymore but use the include directory printed via "php-config --include-dir". Unfortunately CLang doesn't yet support asm goto, so we now include php_config.h very early and undef HAVE_ASM_GOTO thereafter. The #ifndef wrapper in php_config.h will prevent a second inclusion, so we don't get HAVE_ASM_GOTO defined again. Signed-off-by: aszlig <aszlig@nix.build>
This commit is contained in:
parent
f20c2b5fd3
commit
773a341cc2
2 changed files with 85 additions and 70 deletions
|
|
@ -53,8 +53,76 @@ fn exists(path: &str) -> bool {
|
|||
Path::new(target(path).as_str()).exists()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn compile_php(php_version: &str, link_static: bool) -> () {
|
||||
println_stderr!("Setting up PHP {}", php_version);
|
||||
run_command_or_fail("/".to_string(), "mkdir", &["-p", &target("")]);
|
||||
run_command_or_fail(
|
||||
target(""),
|
||||
"git",
|
||||
&[
|
||||
"clone",
|
||||
"https://github.com/php/php-src",
|
||||
format!("--branch={}", php_version).as_str(),
|
||||
],
|
||||
);
|
||||
run_command_or_fail(
|
||||
target("php-src"),
|
||||
"sed",
|
||||
&[
|
||||
"-e",
|
||||
"s/void zend_signal_startup/ZEND_API void zend_signal_startup/g",
|
||||
"-ibk",
|
||||
"Zend/zend_signal.c",
|
||||
"Zend/zend_signal.h",
|
||||
],
|
||||
);
|
||||
run_command_or_fail(target("php-src"), "./genfiles", &[]);
|
||||
run_command_or_fail(target("php-src"), "./buildconf", &["--force"]);
|
||||
|
||||
let embed_type = if link_static { "static" } else { "shared" };
|
||||
|
||||
#[cfg(all(target_os = "linux"))]
|
||||
let config = &[
|
||||
"--enable-debug",
|
||||
&format!("--enable-embed={}", embed_type),
|
||||
"--disable-cli",
|
||||
"--disable-cgi",
|
||||
"--enable-maintainer-zts",
|
||||
// "--without-iconv",
|
||||
"--disable-libxml",
|
||||
"--disable-dom",
|
||||
"--disable-xml",
|
||||
"--disable-simplexml",
|
||||
"--disable-xmlwriter",
|
||||
"--disable-xmlreader",
|
||||
// "--without-pear",
|
||||
// "--with-libdir=lib64",
|
||||
// "--with-pic",
|
||||
];
|
||||
#[cfg(all(target_os = "macos"))]
|
||||
let config = &[
|
||||
"--enable-debug",
|
||||
&format!("--enable-embed={}", embed_type),
|
||||
"--disable-cli",
|
||||
"--disable-cgi",
|
||||
"--enable-maintainer-zts",
|
||||
"--without-iconv",
|
||||
"--disable-libxml",
|
||||
"--disable-dom",
|
||||
"--disable-xml",
|
||||
"--disable-simplexml",
|
||||
"--disable-xmlwriter",
|
||||
"--disable-xmlreader",
|
||||
// "--without-pear",
|
||||
// "--with-libdir=lib64",
|
||||
// "--with-pic",
|
||||
];
|
||||
run_command_or_fail(target("php-src"), "./configure", config);
|
||||
let cpus = format!("{}", num_cpus::get());
|
||||
run_command_or_fail(target("php-src"), "make", &["-j", cpus.as_str()]);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(all(target_os = "linux"))]
|
||||
let default_link_static = false;
|
||||
#[cfg(all(target_os = "macos"))]
|
||||
|
|
@ -71,75 +139,18 @@ fn main() {
|
|||
.map(|_| true)
|
||||
.unwrap_or(default_link_static && !link_dynamic);
|
||||
|
||||
if !exists("php-src/LICENSE") {
|
||||
println_stderr!("Setting up PHP {}", php_version);
|
||||
run_command_or_fail("/".to_string(), "mkdir", &["-p", &target("")]);
|
||||
run_command_or_fail(
|
||||
target(""),
|
||||
"git",
|
||||
&[
|
||||
"clone",
|
||||
"https://github.com/php/php-src",
|
||||
format!("--branch={}", php_version).as_str(),
|
||||
],
|
||||
);
|
||||
run_command_or_fail(
|
||||
target("php-src"),
|
||||
"sed",
|
||||
&[
|
||||
"-e",
|
||||
"s/void zend_signal_startup/ZEND_API void zend_signal_startup/g",
|
||||
"-ibk",
|
||||
"Zend/zend_signal.c",
|
||||
"Zend/zend_signal.h",
|
||||
],
|
||||
);
|
||||
run_command_or_fail(target("php-src"), "./genfiles", &[]);
|
||||
run_command_or_fail(target("php-src"), "./buildconf", &["--force"]);
|
||||
let maybe_include_dir = Command::new("php-config")
|
||||
.args(&["--include-dir"])
|
||||
.output()
|
||||
.map(|o| String::from_utf8(o.stdout).unwrap().trim_end().to_string())
|
||||
.ok();
|
||||
|
||||
let embed_type = if link_static { "static" } else { "shared" };
|
||||
|
||||
#[cfg(all(target_os = "linux"))]
|
||||
let config = &[
|
||||
"--enable-debug",
|
||||
&format!("--enable-embed={}", embed_type),
|
||||
"--disable-cli",
|
||||
"--disable-cgi",
|
||||
"--enable-maintainer-zts",
|
||||
// "--without-iconv",
|
||||
"--disable-libxml",
|
||||
"--disable-dom",
|
||||
"--disable-xml",
|
||||
"--disable-simplexml",
|
||||
"--disable-xmlwriter",
|
||||
"--disable-xmlreader",
|
||||
// "--without-pear",
|
||||
// "--with-libdir=lib64",
|
||||
// "--with-pic",
|
||||
];
|
||||
#[cfg(all(target_os = "macos"))]
|
||||
let config = &[
|
||||
"--enable-debug",
|
||||
&format!("--enable-embed={}", embed_type),
|
||||
"--disable-cli",
|
||||
"--disable-cgi",
|
||||
"--enable-maintainer-zts",
|
||||
"--without-iconv",
|
||||
"--disable-libxml",
|
||||
"--disable-dom",
|
||||
"--disable-xml",
|
||||
"--disable-simplexml",
|
||||
"--disable-xmlwriter",
|
||||
"--disable-xmlreader",
|
||||
// "--without-pear",
|
||||
// "--with-libdir=lib64",
|
||||
// "--with-pic",
|
||||
];
|
||||
run_command_or_fail(target("php-src"), "./configure", config);
|
||||
run_command_or_fail(target("php-src"), "make", &["-j", cpus.as_str()]);
|
||||
}
|
||||
|
||||
let include_dir = target("php-src");
|
||||
let include_dir = maybe_include_dir.unwrap_or_else(|| {
|
||||
if !exists("php-src/LICENSE") {
|
||||
compile_php(php_version, link_static);
|
||||
}
|
||||
target("php-src")
|
||||
});
|
||||
|
||||
let includes = ["/", "/TSRM", "/Zend", "/main"]
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#ifndef PHP_RS_WRAPPER_H
|
||||
#define PHP_RS_WRAPPER_H
|
||||
/* CLang doesn't support asm goto yet, so let's force-disable it. */
|
||||
#include <main/php_config.h>
|
||||
#undef HAVE_ASM_GOTO
|
||||
|
||||
#include <Zend/zend.h>
|
||||
#include <Zend/zend_compile.h>
|
||||
#include <main/php.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue