diff --git a/php-to-rust/Cargo.toml b/php-to-rust/Cargo.toml new file mode 100644 index 0000000..1ffedf0 --- /dev/null +++ b/php-to-rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "php-to-rust" +version = "0.1.0" +authors = ["Nicolas Far "] + +[lib] +name = "double_input" +crate-type = ["dylib"] diff --git a/php-to-rust/Makefile b/php-to-rust/Makefile new file mode 100644 index 0000000..294df52 --- /dev/null +++ b/php-to-rust/Makefile @@ -0,0 +1,14 @@ +ifeq ($(shell uname),Darwin) + EXT := dylib +else + EXT := so +endif + +all: target/debug/libdouble_input.$(EXT) + php src/ffi.php + +target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml + cargo build + +clean: + rm -rf target diff --git a/php-to-rust/README.md b/php-to-rust/README.md new file mode 100644 index 0000000..2ac9a99 --- /dev/null +++ b/php-to-rust/README.md @@ -0,0 +1,5 @@ +PHP 7.4 is needed + +At time of writing, that means [compiling from source](https://github.com/php/php-src#building-php-source-code). + +Make sure to pass --with-ffi as a parameter to ./configure \ No newline at end of file diff --git a/php-to-rust/src/ffi.php b/php-to-rust/src/ffi.php new file mode 100644 index 0000000..65c56fe --- /dev/null +++ b/php-to-rust/src/ffi.php @@ -0,0 +1,9 @@ +double_input(3)); +?> diff --git a/php-to-rust/src/lib.rs b/php-to-rust/src/lib.rs new file mode 100644 index 0000000..2819ff1 --- /dev/null +++ b/php-to-rust/src/lib.rs @@ -0,0 +1,5 @@ +#[no_mangle] +pub extern fn double_input(input: i32) -> i32 { + input * 2 +} +