mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 10:44:09 +02:00
Writing php extensions in rust made easy
- Rust 99.5%
- C 0.5%
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> |
||
|---|---|---|
| examples/helloworld | ||
| ivory | ||
| tests | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
Ivory
Writing php extensions in rust made easy
Usage
use ivory::{ivory_export, ivory_module};
use ivory::externs::printf;
/// Basic methods
#[ivory_export]
fn hello_world() {
printf("Hello world, Rust!");
}
/// Automatically casts function arguments for php
#[ivory_export]
fn hello_other(other: String) {
printf(format!("Hello {}", other));
}
/// And casts return types back to php
#[ivory_export]
fn add_one(input: i64) -> i64 {
input + 1
}
/// Optional arguments
#[ivory_export]
fn hello(input: Option<String>) {
printf(format!("Hello {}", other.unwrap_or("Rust".to_string())));
}
ivory_module!({
name: "demo",
version: "0.0.1",
info: &[("demo extension", "enabled")]
});