├── .github └── workflows │ └── automatic-release.yml ├── .gitignore ├── Cargo.toml ├── README.md ├── run.php └── src └── lib.rs /.github/workflows/automatic-release.yml: -------------------------------------------------------------------------------- 1 | name: "Automatic Releases" 2 | 3 | on: 4 | milestone: 5 | types: 6 | - "closed" 7 | 8 | jobs: 9 | release: 10 | name: "Automatic release" 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: "Checkout" 15 | uses: "actions/checkout@v2" 16 | 17 | - name: "Release" 18 | uses: "laminas/automatic-releases@1.0.1" 19 | with: 20 | command-name: "laminas:automatic-releases:release" 21 | env: 22 | "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} 23 | "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} 24 | "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} 25 | "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-adder" 3 | version = "0.1.0" 4 | authors = ["James Titcumb "] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib"] 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [dependencies] 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust library as a PHP FFI test 2 | 3 | ## Prerequisites 4 | 5 | * [Rust+Cargo](https://rustup.rs/) 6 | * [PHP](https://www.php.net/manual/en/install.php) 7 | 8 | ## Usage 9 | 10 | Build the library: 11 | 12 | ```bash 13 | $ cargo build 14 | ``` 15 | 16 | Run the PHP file: 17 | 18 | ```bash 19 | php run.php 20 | ``` 21 | -------------------------------------------------------------------------------- /run.php: -------------------------------------------------------------------------------- 1 | add_two_numbers(3, 4) . "\n"; 11 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #[no_mangle] 2 | pub extern "C" fn add_two_numbers(a: i32, b: i32) -> i32 { 3 | return a + b; 4 | } 5 | 6 | #[cfg(test)] 7 | mod tests { 8 | use crate::add_two_numbers; 9 | 10 | #[test] 11 | fn it_works() { 12 | assert_eq!(add_two_numbers(2, 2), 4); 13 | } 14 | } 15 | --------------------------------------------------------------------------------