wasmerio / wasmer-php

πŸ˜πŸ•ΈοΈ WebAssembly runtime for PHP
https://wasmerio.github.io/wasmer-php/wasm/
MIT License
1k stars 42 forks source link
php php-extension rust wasm wasmer webassembly
Wasmer logo

Wasmer PHP

Tests Status Nightly Status License

Website β€’ Docs β€’ Slack Channel


A complete and mature WebAssembly runtime for PHP based on Wasmer.

Features

Install

To install the library, follow the classical:

git clone https://github.com/wasmerio/wasmer-php
cd wasmer-php/ext
phpize
./configure --enable-wasmer
make
make test
make install

Note: Wasmer doesn't work on Windows yet.

Examples

Procedural API ```php Hello World!' . PHP_EOL; return null; } $functype = wasm_functype_new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType()); $func = wasm_func_new($store, $functype, 'hello_callback'); wasm_functype_delete($functype); $extern = wasm_func_as_extern($func); $externs = new Wasm\Vec\Extern([$extern]); $instance = wasm_instance_new($store, $module, $externs); wasm_func_delete($func); $exports = wasm_instance_exports($instance); $run = wasm_extern_as_func($exports[0]); wasm_module_delete($module); wasm_instance_delete($instance); $results = wasm_func_call($run, new Wasm\Vec\Val()); wasm_store_delete($store); wasm_engine_delete($engine); ```
Object-oriented API ```php Hello World!'.PHP_EOL; return null; } $functype = Wasm\Functype::new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType()); $func = Wasm\Module\Func::new($store, $functype, 'hello_callback'); $extern = $func->asExtern(); $externs = new Wasm\Vec\Extern([$extern->inner()]); $instance = Wasm\Module\Instance::new($store, $module, $externs); $exports = $instance->exports(); $run = $exports[0]->asFunc(); $args = new Wasm\Vec\Val(); $results = $run($args); ```

This example covers the most basic Wasm use case: we take a Wasm module (in its text representation form), create an instance from it, get an exported function and run it.

You can go through more advanced examples in the dedicated directories:

Supported platforms and features

Platforms

Platform Architecture Status
Linux amd64 βœ…
Linux aarch64 ❌
Windows amd64 ❌
Darwin amd64 βœ…
Darwin aarch64 ❌
PHP Status
8.0 βœ…
7.4 ❌
7.3 ❌

Features

Compilers and engines

Compiler Status
Cranelift βœ…
LLVM ❌
Singlepass ❌
Engine Status
Native βœ…
JIT βœ…
Object File ❌

Runtime

Object Status
config βœ…
engine βœ…
store βœ…

Types

Type Status
valtype βœ…
functype βœ…
globaltype βœ…
tabletype βœ…
memorytype βœ…
externtype βœ…
importtype βœ…
exporttype βœ…

Objects

Object Status
val βœ…
frame βœ…
trap βœ…
foreign βœ…
module βœ…
func βœ…
global βœ…
table πŸ§‘β€πŸ’»
memory βœ…
extern βœ…
instance βœ…

Misc

Feature Status
WAT βœ…
WASI ❌
Cross Compilation ❌

License

The entire project is under the MIT License. Please read the LICENSE file.