Skip to content
🐘🕸️ PHP extension to run WebAssembly binaries.
Branch: master
Clone or download
bors and dependabot-bot Merge #63
63: chore(deps): bump wasmer-runtime-c-api from 0.4.1 to 0.4.2 r=Hywan a=dependabot[bot]

Bumps [wasmer-runtime-c-api](https://github.com/wasmerio/wasmer) from 0.4.1 to 0.4.2.
<details>
<summary>Release notes</summary>

*Sourced from [wasmer-runtime-c-api's releases](https://github.com/wasmerio/wasmer/releases).*

> ## 0.4.2
> This version of Wasmer ships with multiple WASI improvements, fixes on the C-API integration and the first iteration of our refactor of different backends (singlepass and LLVM).
> This version also ships with a kernel loader that is able to run WebAssembly on the kernel, more info [here](https://medium.com/wasmer/running-webassembly-on-the-kernel-8e04761f1d8e).
> 
> Install the latest version of wasmer+wapm with:
> ```shell
> curl https://get.wasmer.io -sSfL | sh
> ```
> 
> # Changelog
> - [#416](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/416) Remote code loading framework
> - [#449](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/449) Fix bugs: opening host files in filestat and opening with write permissions unconditionally in path_open
> - [#442](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir
> - [#440](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/440) Fix type mismatch between `wasmer_instance_call` and `wasmer_export_func_*_arity` functions in the runtime C API.
> - [#269](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/269) Add better runtime docs
> - [#432](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/432) Fix returned value of `wasmer_last_error_message` in the runtime C API
> - [#429](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/429) Get wasi::path_filestat_get working for some programs; misc. minor WASI FS improvements
> - [#413](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/413) Update LLVM backend to use new parser codegen traits
</details>
<details>
<summary>Changelog</summary>

*Sourced from [wasmer-runtime-c-api's changelog](https://github.com/wasmerio/wasmer/blob/master/CHANGELOG.md).*

> ## 0.4.2 - 2019-05-16
> 
> - [#416](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/416) Remote code loading framework
> - [#449](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/449) Fix bugs: opening host files in filestat and opening with write permissions unconditionally in path_open
> - [#442](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir
> - [#440](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/440) Fix type mismatch between `wasmer_instance_call` and `wasmer_export_func_*_arity` functions in the runtime C API.
> - [#269](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/269) Add better runtime docs
> - [#432](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/432) Fix returned value of `wasmer_last_error_message` in the runtime C API
> - [#429](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/429) Get wasi::path_filestat_get working for some programs; misc. minor WASI FS improvements
> - [#413](https://github-redirect.dependabot.com/wasmerio/wasmer/pull/413) Update LLVM backend to use new parser codegen traits
</details>
<details>
<summary>Commits</summary>

- [`4ddffb8`](wasmerio/wasmer@4ddffb8) Update libraries versions to 0.4.2
- [`14089fc`](wasmerio/wasmer@14089fc) Fixes fetching latest wapm
- [`7f41d57`](wasmerio/wasmer@7f41d57) Updated version to 0.4.2
- [`4e5ac24`](wasmerio/wasmer@4e5ac24) Merge [#416](https://github-redirect.dependabot.com/wasmerio/wasmer/issues/416)
- [`100039a`](wasmerio/wasmer@100039a) Merge remote-tracking branch 'origin/master' into feature/remote-code-load
- [`a177954`](wasmerio/wasmer@a177954) Rename `wasi-networking` to `echo-server`.
- [`b289929`](wasmerio/wasmer@b289929) Rename `wasmer-kernel-net` to `kernel-net`.
- [`88124d9`](wasmerio/wasmer@88124d9) Merge [#449](https://github-redirect.dependabot.com/wasmerio/wasmer/issues/449)
- [`83deae8`](wasmerio/wasmer@83deae8) update changelog; clean up
- [`b275273`](wasmerio/wasmer@b275273) avoid opening files when not needed in WASI, check for write permissions
- Additional commits viewable in [compare view](wasmerio/wasmer@0.4.1...0.4.2)
</details>
<br />

[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=wasmer-runtime-c-api&package-manager=cargo&previous-version=0.4.1&new-version=0.4.2)](https://dependabot.com/compatibility-score.html?dependency-name=wasmer-runtime-c-api&package-manager=cargo&previous-version=0.4.1&new-version=0.4.2)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Automerge options (never/patch/minor, and dev/runtime dependencies)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)

Finally, you can contact us by mentioning @dependabot.

</details>

Co-authored-by: dependabot[bot] <support@dependabot.com>
Latest commit f51bd1f May 22, 2019

README.md

Wasmer logo

Join the Wasmer Community Read our API documentation Packagist License

The PHP extension to run WebAssembly

The goal of the project is to be able to run WebAssembly binaries from PHP directly. So much fun coming!

What is WebAssembly?

Quoting the WebAssembly site:

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.

About speed:

WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.

About safety:

WebAssembly describes a memory-safe, sandboxed execution environment […].

Goals

This extension has some goals in minds. Let's list some of them:

Write PHP extensions

Taking the example of an image manipulation library, like face detection, one can use an existing Rust or C++ library, then compile it to a WebAssembly binary, and use it directly in PHP through the php-ext-wasm extension.

Writing a C extension for PHP with the Zend API is no longer necessary.

Cross-platform distribution and packaging (feat. Composer)

Because WebAssembly is a portable target, i.e. binaries are platform agnostics, once a library has been compiled to a WebAssembly binary, it is immediately distributable on all platforms where PHP runs. There is no compilation steps required. And to be clear, compiling a library to a WebAssembly binary does not required any PHP headers.

To push the logic further, a library compiled as a WebAssembly binary can be packaged with Composer (the PHP dependency manager), along with some PHP code to ease the manipulation of the compiled library.

Distributing a new version of a WebAssembly binary simply reduces to distributing a new file. Composer can also add constraints over the available extensions with their versions (see ext-name). All packaging scenarios are handled.

As fast as possible

We are working on being as fast as native code (see this blog post to learn more). So far, the extension provides a faster execution than PHP itself. With the nbody benchmark, the php-ext-wasm is 9.5 times faster than pure PHP:

subject mean mode best rstdev
wasm_extension 2,009.335μs 1,991.778μs 1,968.595μs 2.17%
pure_php 19,714.738μs 19,143.083μs 18,853.399μs 3.58%

Safety first

WebAssembly brings safety guarantees, notably due to its memory model and its sandboxed execution environment. If Rust is used as the source of a WebAssembly binary, then more safety is brought in the game. In any case, without real numbers or studies, we imagine that it is safer to use a WebAssembly binary extension rather than writing C code.

A WebAssembly binary has no access to the PHP environment (so no access to its memory or functions). It is executed in a sandbox. A WebAssembly binary is totally blind regarding the host/the system where it runs: Whether it runs in a Web browser, a server, or a PHP process, this is the same.

Example

There is a toy program in examples/simple.rs, written in Rust (or any other language that compiles to Wasm):

#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
    x + y
}

This program compiles to Wasm, with just compile-wasm examples/simple. We end up with a examples/simple.wasm binary file.

Then, we can execute it in PHP (!) with the examples/simple.php file:

$instance = new Wasm\Instance(__DIR__ . '/simple.wasm');

var_dump(
    $instance->sum(5, 37) // 42!
);

And then, finally, enjoy by running:

$ php -d extension=wasm examples/simple.php
int(42)

Usage

This repository contains basically two things:

  1. The php-ext-wasm extension, and
  2. The Wasm library.

The php-ext-wasm extension provides a raw API around WebAssembly. The Wasm library is a layer on top of php-ext-wasm to provide more safety and a more user-friendly API.

See the API documentations with examples.

To compile the entire project, run the following commands:

$ just rust
$ just php
$ php -d extension=wasm examples/simple.php

(Yes, you need just).

Testing

Once the extension is compiled and installed (just run just rust && just php), run the following commands:

$ composer install
$ composer test

License

The entire project is under the BSD-3-Clause license. Please read the LICENSE file.

You can’t perform that action at this time.