Skip to content

Commit

Permalink
feat(embed): add embed features, add test example which run php insid…
Browse files Browse the repository at this point in the history
…e it
  • Loading branch information
joelwurtz committed Oct 19, 2023
1 parent 15bed3b commit f9e4f7a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ zip = "0.6"

[features]
closure = []
embed = []

[workspace]
members = [
Expand Down
4 changes: 3 additions & 1 deletion allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,7 @@ bind! {
tsrm_get_ls_cache,
executor_globals_offset,
zend_atomic_bool_store,
zend_interrupt_function
zend_interrupt_function,
php_embed_init,
php_embed_shutdown
}
29 changes: 29 additions & 0 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,32 @@ impl<'a> FromZval<'a> for &'a str {
zval.str()
}
}

#[cfg(test)]
#[cfg(feature = "embed")]
mod tests {
use crate::ffi::{php_embed_init, php_embed_shutdown};
use crate::types::Zval;
use crate::zend::Function;
use std::ptr::null_mut;

#[test]
fn test_string() {
unsafe {
php_embed_init(0, null_mut());
}

let func = Function::try_from_function("chr").expect("Failed to find eval function");
let mut input = Zval::new();
input.set_long(65);
let result = func
.try_call(vec![&input])
.expect("Failed to call eval function");

assert_eq!(result.string().unwrap(), "A");

unsafe {
php_embed_shutdown();
}
}
}
1 change: 1 addition & 0 deletions src/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "zend_inheritance.h"
#include "zend_interfaces.h"
#include "zend_ini.h"
#include "sapi/embed/php_embed.h"

zend_string *ext_php_rs_zend_string_init(const char *str, size_t len, bool persistent);
void ext_php_rs_zend_string_release(zend_string *zs);
Expand Down
7 changes: 7 additions & 0 deletions unix_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ impl<'a> PHPProvider<'a> for Provider {
fn get_defines(&self) -> Result<Vec<(&'static str, &'static str)>> {
Ok(vec![])
}

fn print_extra_link_args(&self) -> Result<()> {
#[cfg(feature = "embed")]
println!("cargo:rustc-link-lib=php");

Ok(())
}
}

0 comments on commit f9e4f7a

Please sign in to comment.