Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ircmaxell/FFIMe
A FFI Wrapper library and header parser!
https://github.com/ircmaxell/FFIMe
Last synced: 2 months ago
JSON representation
A FFI Wrapper library and header parser!
- Host: GitHub
- URL: https://github.com/ircmaxell/FFIMe
- Owner: ircmaxell
- License: mit
- Created: 2019-02-18T10:35:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-02T20:37:54.000Z (about 1 year ago)
- Last Synced: 2024-09-24T11:49:45.937Z (4 months ago)
- Language: PHP
- Size: 389 KB
- Stars: 137
- Watchers: 11
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FFIMe
This is a wrapper library for PHP's FFI extension.
You provide it with a shared object, and one or more header files, and it automatically generates the C structures and function signatures for you (just like doing it in C would).
It then provides wrapper classes for all C structures and functions to provide a fully typed experience.## Usage:
Currently there are two modes of operation, an "inline" mode:
```php
$libc = (new FFIMe\FFIMe(FFIMe\FFIMe::LIBC))
->include("stdio.h")
->build();$libc->printf("test\n");
```And a code generating mode:
```php
(new FFIMe\FFIMe(FFIMe\FFIMe::LIBC))
->include("stdio.h")
->include("other.h")
->codeGen('full\\classname', 'path/to/file.php');require 'path/to/file.php';
$libc = full\classname::ffi();
$libc->printf("test\n");
```The code generating mode is designed to be used in production, where you'd code generate during a build step and ship with your library.
This should now work for the majority of header files. Looking at some of the code, specifically the compiler, there is a bit of hard coding necessary. So I don't expect every file to work out of the box. If you find a header file that doesn't work, just open a bug and we'll take a look.
Check out the [examples](examples/);
## Slimming it down
Generating FFI for large projects may result in codefiles counting tens or hundreds of thousands of lines, though only a few hundred or thousand are actually needed. This may result in a non-trivial overhead, which can be removed after development.
```php
$ffi = (new FFIMe\FFIMe(FFIMe\FFIMe::LIBC))
->include("stdio.h");
$ffi->codeGenWithInstrumentation('full\\classname', 'path/to/file.php');// Run some code providing 100% coverage of all code using FFI
(new PHPUnit\TextUI\Command)->run([$argv[0], "test"], false);$ffi->codeGen('full\\classname', 'path/to/file.php');
```