Giter Club home page Giter Club logo

wasmer-php's Introduction

Wasmer logo

Wasmer PHP

Tests Status Nightly Status License


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

Features

  • Easy to use: The wasmer API mimics the standard WebAssembly C API,
  • Fast: wasmer executes the WebAssembly modules as fast as possible, close to native speed,
  • Safe: All calls to WebAssembly will be fast, but more importantly, completely safe and sandboxed.

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 

declare(strict_types=1);

$engine = wasm_engine_new();
$store = wasm_store_new($engine);
$wasm = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'hello.wasm');
$module = wasm_module_new($store, $wasm);

function hello_callback() {
    echo 'Calling back...' . PHP_EOL;
    echo '> 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

declare(strict_types=1);

use Wasm;

require_once __DIR__.'/../vendor/autoload.php';

$engine = Wasm\Engine::new();
$store = Wasm\Store::new($engine);

$wasm = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'hello.wasm');

$module = Wasm\Module::new($store, $wasm);

function hello_callback()
{
    echo 'Calling back...'.PHP_EOL;
    echo '> 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.

wasmer-php's People

Contributors

bors[bot] avatar casey avatar chinoto avatar dependabot-preview[bot] avatar dependabot-support avatar erjanmx avatar hywan avatar jubianchi avatar syrusakbary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasmer-php's Issues

collect2: error: ld returned 1 exit status

                                  ^
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/api/types/limits.c -o src/api/types/limits.lo 
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/api/types/limits.c  -fPIC -DPIC -o src/api/types/.libs/limits.o
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/api/types/memorytype.c -o src/api/types/memorytype.lo 
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/api/types/memorytype.c  -fPIC -DPIC -o src/api/types/.libs/memorytype.o
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/api/types/tabletype.c -o src/api/types/tabletype.lo 
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/api/types/tabletype.c  -fPIC -DPIC -o src/api/types/.libs/tabletype.o
/longteng/soft/wasmer-php/ext/src/api/types/tabletype.c: In function ‘zif_wasm_tabletype_element’:
/longteng/soft/wasmer-php/ext/src/api/types/tabletype.c:49:28: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     valtype->inner.valtype = wasm_tabletype_element(WASMER_RES_P_INNER(tabletype_val, tabletype));
                            ^
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/api/types/valkind.c -o src/api/types/valkind.lo 
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/api/types/valkind.c  -fPIC -DPIC -o src/api/types/.libs/valkind.o
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/api/types/valtype.c -o src/api/types/valtype.lo 
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/api/types/valtype.c  -fPIC -DPIC -o src/api/types/.libs/valtype.o
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=compile cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -c /longteng/soft/wasmer-php/ext/src/wasm.c -o src/wasm.lo 
mkdir src/.libs
 cc -I. -I/longteng/soft/wasmer-php/ext -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /longteng/soft/wasmer-php/ext/src/wasm.c  -fPIC -DPIC -o src/.libs/wasm.o
/bin/sh /longteng/soft/wasmer-php/ext/libtool --mode=link cc -shared -I/longteng/soft/wasmer-php/ext/include -I/longteng/soft/wasmer-php/ext/main -I/longteng/soft/wasmer-php/ext -I/www/server/php/80/include/php -I/www/server/php/80/include/php/main -I/www/server/php/80/include/php/TSRM -I/www/server/php/80/include/php/Zend -I/www/server/php/80/include/php/ext -I/www/server/php/80/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /longteng/soft/wasmer-php/ext/modules  src/api/config.lo src/api/engine.lo src/api/store.lo src/api/wasmer.lo src/api/wat.lo src/api/objects/extern.lo src/api/objects/foreign.lo src/api/objects/func.lo src/api/objects/frame.lo src/api/objects/global.lo src/api/objects/instance.lo src/api/objects/memory.lo src/api/objects/module.lo src/api/objects/table.lo src/api/objects/trap.lo src/api/objects/val.lo src/api/types/exporttype.lo src/api/types/externtype.lo src/api/types/functype.lo src/api/types/globaltype.lo src/api/types/importtype.lo src/api/types/limits.lo src/api/types/memorytype.lo src/api/types/tabletype.lo src/api/types/valkind.lo src/api/types/valtype.lo src/wasm.lo -Wl,-rpath,/longteng/soft/wasmer-php/ext/lib -L/longteng/soft/wasmer-php/ext/lib -lwasmer
mkdir .libs
cc -shared  src/api/.libs/config.o src/api/.libs/engine.o src/api/.libs/store.o src/api/.libs/wasmer.o src/api/.libs/wat.o src/api/objects/.libs/extern.o src/api/objects/.libs/foreign.o src/api/objects/.libs/func.o src/api/objects/.libs/frame.o src/api/objects/.libs/global.o src/api/objects/.libs/instance.o src/api/objects/.libs/memory.o src/api/objects/.libs/module.o src/api/objects/.libs/table.o src/api/objects/.libs/trap.o src/api/objects/.libs/val.o src/api/types/.libs/exporttype.o src/api/types/.libs/externtype.o src/api/types/.libs/functype.o src/api/types/.libs/globaltype.o src/api/types/.libs/importtype.o src/api/types/.libs/limits.o src/api/types/.libs/memorytype.o src/api/types/.libs/tabletype.o src/api/types/.libs/valkind.o src/api/types/.libs/valtype.o src/.libs/wasm.o  -L/longteng/soft/wasmer-php/ext/lib -lwasmer  -Wl,-rpath -Wl,/longteng/soft/wasmer-php/ext/lib -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/usr/bin/ld: cannot find -lwasmer
collect2: error: ld returned 1 exit status
make: *** [Makefile:303: wasm.la] Error 1
[root@iZ94t3ix68kZ ext]# uname -r
4.18.0-193.14.2.el8_2.x86_64
[root@iZ94t3ix68kZ ext]# uname -a
Linux iZ94t3ix68kZ 4.18.0-193.14.2.el8_2.x86_64 #1 SMP Sun Jul 26 03:54:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@iZ94t3ix68kZ ext]#  lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 8.2.2004 (Core) 
Release:	8.2.2004
Codename:	Core
[root@iZ94t3ix68kZ ext]# 

How to set parameter type to i64 in imported functions

Hi,
i try to implement missing function where expected signature is:
expected signature: [I32, I64, I32, I32] -> [I32]

my code:

$imports = [
    'wasi_unstable' => [
	'fd_seek' => function(int $file, int $offset, int $whence, int $newoffset): int {
	    return 0;
	},
   ]
]

$instance = new Wasm\Instance(__DIR__ . '/demo.wasm', $imports);

when i try to run i get this error:
Incorrect import signature, namespace: wasi_unstable, name: fd_seek, expected signature: [I32, I64, I32, I32] -> [I32], found signature: [I32, I32, I32, I32] -> [I32]

How to set parameter type to i64 in imported functions?

WASI support

WASI support

Hello 👋 , quick question :)

According to this article - https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/ one is able to just run WASM binary that was compiled with WASI support (it's possible that I mix terms, sorry)

I've found somewhere on Twitter, that PHP is not yet supported by https://github.com/CraneStation/wasmtime.

But what if I'm gonna use this extension, which uses Wasmer, which has support for WASI, it's gonna work right 🙏?

Thanks for your time.

Windows build

Has anyone succeeded in building it for Windows? I have VC++ 2017 and what I did was:

  • Downloaded the SDK tools for PHP 7.1
  • Ran phpize.bat in the src folder to generate configure.bat
  • Ran configure.bat
  • Ran nmake, but got I lot of compilation errors like:
...\src\wasm.cc(124): warning C4003: not enough arguments for function-like macro invocation 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX'
...\src\wasm.cc(124): error C2059: syntax error: ','
...\src\wasm.cc(124): error C2143: syntax error: missing ';' before '}'
...\src\wasm.cc(124): error C2059: syntax error: '}'
...\src\wasm.cc(125): error C2059: syntax error: '}'
...\src\wasm.cc(125): error C2143: syntax error: missing ';'

I tried adding /std:c++14 to the cl.exe args, but to no avail. Any tips would be appreciated :)

Will it be possible to serialize state and limit execution time?

Summary

Will this extension support non-blocking operation and state serialization?

Additional details

It can in many cases be helpful to run code for a certain number of instructions, or milliseconds before execution is preemptively halted.

This can be useful for example in event loop environments such as swoole or ReactPHP.

To support this, it would be necessary that wasm methods could return a special "WasmHalted" object. This object could represent that execution was halted due to timeout, waiting for IO, or it could represent a request for opening a resource such as a file.

$delayed = $instance->sum(1, 2);

$delayed->run(1000); // 1000 instructions
$s = serialize($delayed);

$delayed = $instance->resume(unserialize($s)) ;

while(!$delayed->done()) {
    $delayed->run(1000):
} 
$delayed->result(); // done

I would love if this object could be serialized and resumed. Sure, the serialized object can become quite large, if the wasm binary uses a lot of memory but that would be my problem.

Supported types

Hey,

Thanks for your awesome work. :-)

Where can I find the supported types between PHP and WASM?
For example, I want to see if a wasm function can return a PHP associative array or not.

libwasmer.so: file not recognized: File format not recognized

Summary

When I build the ext, it gives me some error info:

creating libtool
appending configuration tag "CXX" to libtool
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC...
checking if g++ static flag  works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... unsupported
configure: creating ./config.status
config.status: creating config.h
/bin/sh /just/php-ext-wasm/src/libtool --mode=compile g++  -I. -I/just/php-ext-wasm/src -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11   -c /just/php-ext-wasm/src/wasm.cc -o wasm.lo
mkdir .libs
 g++ -I. -I/just/php-ext-wasm/src -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -c /just/php-ext-wasm/src/wasm.cc  -DPIC -o .libs/wasm.o
/bin/sh /just/php-ext-wasm/src/libtool --mode=link cc -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /just/php-ext-wasm/src/modules  wasm.lo -Wl,-rpath,/just/php-ext-wasm/src/. -L/just/php-ext-wasm/src/. -lwasmer
cc -shared  .libs/wasm.o  -L/just/php-ext-wasm/src/. -lwasmer  -Wl,-rpath -Wl,/just/php-ext-wasm/src/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/just/php-ext-wasm/src/./libwasmer.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [wasm.la] Error 1
error: Recipe `build` failed with exit code 2
  • And when I try just build-runtime, the info is following:
[root@2a21bde6fff5 src]# just build-runtime
    Finished release [optimized] target(s) in 0.21s
ln: failed to create symbolic link 'wasmer/libwasmer_runtime_c_api.so': No such file or directory
error: Recipe `build-runtime` failed with exit code 1
  • I create a wasmer dir, it works:
[root@2a21bde6fff5 php-ext-wasm]# just build-runtime
    Finished release [optimized] target(s) in 0.09s
  • Then run just build the error info is:
creating libtool
appending configuration tag "CXX" to libtool
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC...
checking if g++ static flag  works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... unsupported
configure: creating ./config.status
config.status: creating config.h
/bin/sh /just/php-ext-wasm/src/libtool --mode=compile g++  -I. -I/just/php-ext-wasm/src -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11 -fPIC   -c /just/php-ext-wasm/src/wasm.cc -o wasm.lo
mkdir .libs
 g++ -I. -I/just/php-ext-wasm/src -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -fPIC -c /just/php-ext-wasm/src/wasm.cc  -DPIC -o .libs/wasm.o
/bin/sh /just/php-ext-wasm/src/libtool --mode=link cc -DPHP_ATOM_INC -I/just/php-ext-wasm/src/include -I/just/php-ext-wasm/src/main -I/just/php-ext-wasm/src -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /just/php-ext-wasm/src/modules  wasm.lo -Wl,-rpath,/just/php-ext-wasm/src/. -L/just/php-ext-wasm/src/. -lwasmer
cc -shared  .libs/wasm.o  -L/just/php-ext-wasm/src/. -lwasmer  -Wl,-rpath -Wl,/just/php-ext-wasm/src/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/just/php-ext-wasm/src/./libwasmer.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [wasm.la] Error 1
error: Recipe `build` failed with exit code 2

Additional details

  • PHP 7.3
  • CentOS 7
  • cargo 1.42.0 (86334295e 2020-01-31)

Build fails on Ubuntu 18.04

When compiling last commit (6147c98) under Ubuntu 18.04 i got this error:

In file included from /home/piotr/build/php-ext-wasm/src/wasm.cc:19:0:
/home/piotr/build/php-ext-wasm/src/wasm.hh:229:5: error: ‘wasmer_trampoline_buffer_t’ does not name a type; did you mean ‘wasmer_import_func_t’?
     wasmer_trampoline_buffer_t *trampoline_buffer;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~
     wasmer_import_func_t
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zim_WasmArrayBuffer___construct(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:108:113: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Buffer length must be positive; given %lld.", byte_length);
                                                                                                                 ^
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zim_WasmArrayBuffer_grow(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:174:119: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Number of pages must be positive; given %lld.", number_of_pages);
                                                                                                                       ^
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘bool initialize_wasm_imports(HashTable*, std::__cxx11::list<wasm_imported_function*>**, wasmer_import_t**, uint32_t*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:966:33: error: ‘struct wasm_imported_function’ has no member named ‘trampoline_buffer’
             trampoline_context->trampoline_buffer = NULL;
                                 ^~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:969:13: error: ‘wasmer_trampoline_buffer_builder_t’ was not declared in this scope
             wasmer_trampoline_buffer_builder_t *trampoline_builder = wasmer_trampoline_buffer_builder_new();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:969:13: note: suggested alternative: ‘wasmer_import_object_iter_t’
             wasmer_trampoline_buffer_builder_t *trampoline_builder = wasmer_trampoline_buffer_builder_new();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             wasmer_import_object_iter_t
/home/piotr/build/php-ext-wasm/src/wasm.cc:969:49: error: ‘trampoline_builder’ was not declared in this scope
             wasmer_trampoline_buffer_builder_t *trampoline_builder = wasmer_trampoline_buffer_builder_new();
                                                 ^~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:969:49: note: suggested alternative: ‘trampoline_context’
             wasmer_trampoline_buffer_builder_t *trampoline_builder = wasmer_trampoline_buffer_builder_new();
                                                 ^~~~~~~~~~~~~~~~~~
                                                 trampoline_context
/home/piotr/build/php-ext-wasm/src/wasm.cc:969:70: error: ‘wasmer_trampoline_buffer_builder_new’ was not declared in this scope
             wasmer_trampoline_buffer_builder_t *trampoline_builder = wasmer_trampoline_buffer_builder_new();
                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:972:18: error: ‘wasmer_trampoline_callable_t’ was not declared in this scope
                 (wasmer_trampoline_callable_t *) imported_function_trampoline,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:972:18: note: suggested alternative: ‘trampoline_context’
                 (wasmer_trampoline_callable_t *) imported_function_trampoline,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  trampoline_context
/home/piotr/build/php-ext-wasm/src/wasm.cc:972:48: error: expected primary-expression before ‘)’ token
                 (wasmer_trampoline_callable_t *) imported_function_trampoline,
                                                ^
/home/piotr/build/php-ext-wasm/src/wasm.cc:970:46: error: ‘wasmer_trampoline_buffer_builder_add_callinfo_trampoline’ was not declared in this scope
             unsigned long trampoline_index = wasmer_trampoline_buffer_builder_add_callinfo_trampoline(
                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:978:13: error: ‘wasmer_trampoline_buffer_t’ was not declared in this scope
             wasmer_trampoline_buffer_t *trampoline = wasmer_trampoline_buffer_builder_build(trampoline_builder);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:978:13: note: suggested alternative: ‘wasmer_import_func_t’
             wasmer_trampoline_buffer_t *trampoline = wasmer_trampoline_buffer_builder_build(trampoline_builder);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
             wasmer_import_func_t
/home/piotr/build/php-ext-wasm/src/wasm.cc:978:41: error: ‘trampoline’ was not declared in this scope
             wasmer_trampoline_buffer_t *trampoline = wasmer_trampoline_buffer_builder_build(trampoline_builder);
                                         ^~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:978:41: note: suggested alternative: ‘tmpfile’
             wasmer_trampoline_buffer_t *trampoline = wasmer_trampoline_buffer_builder_build(trampoline_builder);
                                         ^~~~~~~~~~
                                         tmpfile
/home/piotr/build/php-ext-wasm/src/wasm.cc:978:54: error: ‘wasmer_trampoline_buffer_builder_build’ was not declared in this scope
             wasmer_trampoline_buffer_t *trampoline = wasmer_trampoline_buffer_builder_build(trampoline_builder);
                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:979:33: error: ‘struct wasm_imported_function’ has no member named ‘trampoline_buffer’
             trampoline_context->trampoline_buffer = trampoline;
                                 ^~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:982:19: error: ‘wasmer_trampoline_callable_t’ does not name a type; did you mean ‘trampoline_context’?
             const wasmer_trampoline_callable_t *trampoline_callable = wasmer_trampoline_buffer_get_trampoline(trampoline, trampoline_index);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   trampoline_context
/home/piotr/build/php-ext-wasm/src/wasm.cc:986:36: error: ‘trampoline_callable’ was not declared in this scope
                 (void (*)(void *)) trampoline_callable,
                                    ^~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:986:36: note: suggested alternative: ‘trampoline_context’
                 (void (*)(void *)) trampoline_callable,
                                    ^~~~~~~~~~~~~~~~~~~
                                    trampoline_context
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void wasm_instance_destructor(zend_resource*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:1166:65: error: ‘struct wasm_imported_function’ has no member named ‘trampoline_buffer’
             wasmer_trampoline_buffer_destroy(imported_function->trampoline_buffer);
                                                                 ^~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:1166:13: error: ‘wasmer_trampoline_buffer_destroy’ was not declared in this scope
             wasmer_trampoline_buffer_destroy(imported_function->trampoline_buffer);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/piotr/build/php-ext-wasm/src/wasm.cc:1166:13: note: suggested alternative: ‘wasmer_import_func_destroy’
             wasmer_trampoline_buffer_destroy(imported_function->trampoline_buffer);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             wasmer_import_func_destroy
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray___construct(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:2029:105: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Offset must be non-negative; given %lld.", offset);
                                                                                                         ^
/home/piotr/build/php-ext-wasm/src/wasm.cc:2041:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/piotr/build/php-ext-wasm/src/wasm.cc:2047:105: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 2, "Length must be non-negative; given %lld.", length);
                                                                                                         ^
/home/piotr/build/php-ext-wasm/src/wasm.cc:2099:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
             );
             ^
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_get(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:2202:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_set(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:2285:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/piotr/build/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_unset(zend_execute_data*, zval*)’:
/home/piotr/build/php-ext-wasm/src/wasm.cc:2406:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
Makefile:194: recipe for target 'wasm.lo' failed
make: *** [wasm.lo] Error 1
error: Recipe `build` failed with exit code 2

Previous commit builds ok (0154a56)

Would I be able to use golang to produce the wasm file?

Summary

Is it possible to use this project to load a wasm file generated from golang?

Additional details

I tried but got

Message:
Use of undefined constant WASM_TYPE_F64 - assumed 'WASM_TYPE_F64' (this will throw an Error in a future version of PHP)
Location:
/var/www/leonardo/vendor/php-wasm/php-wasm/lib/Prelude.php on line 10

Implement a cache to not compile the Wasm module everytime

The idea is basically to add a cache, so that we don't have to validate & compile etc. the whole module everytime. It will improve grately the execution speed.

There is no API in wasmer-runtime-c-api yet. I need to work on that. Maybe we will implement that outside the wasmer-runtime-c-api crate.

In the mac environment php8.x Unable to load dynamic library 'wasm'

error message:

Warning: PHP Startup: Unable to load dynamic library 'wasm' (tried: /usr/local/lib/php/pecl/20210902/wasm (dlopen(/usr/local/lib/php/pecl/20210902/wasm, 0x0009): tried: '/usr/local/lib/php/pecl/20210902/wasm' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/php/pecl/20210902/wasm' (no such file), '/usr/local/lib/php/pecl/20210902/wasm' (no such file)), /usr/local/lib/php/pecl/20210902/wasm.so (dlopen(/usr/local/lib/php/pecl/20210902/wasm.so, 0x0009): symbol not found in flat namespace '_wasm_exporttype_copy')) in Unknown on line 0

I tried to remove the wasm_exporttype_copy method and reinstall, the error still exists

environment:

  • mac-13.3.1
  • php-8.0
  • php-8.1

Cargo dependencies of an example

Summary

Hello 👋
I would like to compile an example with serde crate.

Additional details

I've tried following:

  1. Add
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

into Cargo.toml
2. Run cargo build
3. Run just compile-wasm examples/greet

Modified verison of greet.rs

use std::ffi::{CStr, CString};
use std::mem;
use std::borrow::Cow;
use std::os::raw::{c_char, c_void};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Subject<'a> {
    subject: Cow<'a, str>,
}

#[no_mangle]
pub extern fn allocate(size: usize) -> *mut c_void {
    let mut buffer = Vec::with_capacity(size);
    let pointer = buffer.as_mut_ptr();
    mem::forget(buffer);

    pointer as *mut c_void
}

#[no_mangle]
pub extern fn deallocate(pointer: *mut c_void, capacity: usize) {
    unsafe {
        let _ = Vec::from_raw_parts(pointer, 0, capacity);
    }
}

#[no_mangle]
pub extern fn greet(subject: *mut c_char) -> *mut c_char {
    let subject = unsafe { CStr::from_ptr(subject).to_string_lossy() };
    let point = Subject { subject };

    let serialized = serde_json::to_string(&point).unwrap();
    println!("serialized = {}", serialized);
    unsafe { CString::from_vec_unchecked(serialized.as_bytes().to_vec()) }.into_raw()
}

But I've got only errors:

error[E0432]: unresolved import `serde`
 --> examples/greet.rs:5:5
  |
5 | use serde::{Serialize, Deserialize};
  |     ^^^^^ maybe a missing `extern crate serde;`?

error: cannot determine resolution for the derive macro `Deserialize`
 --> examples/greet.rs:7:21
  |
7 | #[derive(Serialize, Deserialize, Debug)]
  |                     ^^^^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the derive macro `Serialize`
 --> examples/greet.rs:7:10
  |
7 | #[derive(Serialize, Deserialize, Debug)]
  |          ^^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error[E0433]: failed to resolve: use of undeclared type or module `serde_json`
  --> examples/greet.rs:33:22
   |
33 |     let serialized = serde_json::to_string(&point).unwrap();
   |                      ^^^^^^^^^^ use of undeclared type or module `serde_json`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
error: Recipe `compile-wasm` failed with exit code 1

But I've found a solution, but I do not like it.

  1. Create Cargo.toml in examples folder
[package]
publish = false
name = "php-wasm-greet"
version = "1.0.0"
edition = "2018"

[lib]
path = "greet.rs"
crate-type = ["cdylib"]

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
  1. Create new just recipe
compile-and-run-example FILE='greet':
	#!/usr/bin/env bash
	set -euo pipefail
	cd examples
	cargo +nightly build --target wasm32-unknown-unknown
	cp target/wasm32-unknown-unknown/debug/php_wasm_{{FILE}}.wasm {{FILE}}.wasm
	php -d extension=wasm {{FILE}}.php
  1. Run just compile-and-run-example greet

There is surely better way. Could you give me an advice?

:pray Thanks in advance!

Could you tell what version of gcc is required?

Hi,
I got several compilation errors. I wonder if you recommend any version of gcc:

/bin/bash /home/david/GitHub/wasmer-php/ext/libtool --mode=compile cc  -I. -I/home/david/GitHub/wasmer-php/ext -DPHP_ATOM_INC -I/home/david/GitHub/wasmer-php/ext/include -I/home/david/GitHub/wasmer-php/ext/main -I/home/david/GitHub/wasmer-php/ext -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/david/GitHub/wasmer-php/ext/src/api/config.c -o src/api/config.lo 
mkdir src/api/.libs
 cc -I. -I/home/david/GitHub/wasmer-php/ext -DPHP_ATOM_INC -I/home/david/GitHub/wasmer-php/ext/include -I/home/david/GitHub/wasmer-php/ext/main -I/home/david/GitHub/wasmer-php/ext -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/david/GitHub/wasmer-php/ext/src/api/config.c  -fPIC -DPIC -o src/api/.libs/config.o
In file included from /home/david/GitHub/wasmer-php/ext/src/api/config.c:5:
/home/david/GitHub/wasmer-php/ext/src/api/config.c: In function ‘zif_wasm_config_delete’:
/home/david/GitHub/wasmer-php/ext/src/api/./macros.h:42:9: warning: implicit declaration of function ‘RETURN_THROWS’; did you mean ‘RETURN_TRUE’? [-Wimplicit-function-declaration]
   42 |         RETURN_THROWS();\
      |         ^~~~~~~~~~~~~
/home/david/GitHub/wasmer-php/ext/src/api/./macros.h:184:1: note: in expansion of macro ‘WASMER_DELETE_RESOURCE’
  184 | WASMER_DELETE_RESOURCE(name)\
      | ^~~~~~~~~~~~~~~~~~~~~~
/home/david/GitHub/wasmer-php/ext/src/api/config.c:8:1: note: in expansion of macro ‘WASMER_DECLARE_OWN’
    8 | WASMER_DECLARE_OWN(config)
      | ^~~~~~~~~~~~~~~~~~
/home/david/GitHub/wasmer-php/ext/src/api/config.c: In function ‘zif_wasm_config_set_compiler’:
/home/david/GitHub/wasmer-php/ext/src/api/config.c:28:13: warning: implicit declaration of function ‘Z_PARAM_NUMBER’ [-Wimplicit-function-declaration]
   28 |             Z_PARAM_NUMBER(compiler_val)
      |             ^~~~~~~~~~~~~~
/home/david/GitHub/wasmer-php/ext/src/api/config.c:28:41: error: expected ‘;’ before ‘}’ token
   28 |             Z_PARAM_NUMBER(compiler_val)
      |                                         ^
      |                                         ;
/home/david/GitHub/wasmer-php/ext/src/api/config.c: In function ‘zif_wasm_config_set_engine’:
/home/david/GitHub/wasmer-php/ext/src/api/config.c:45:39: error: expected ‘;’ before ‘}’ token
   45 |             Z_PARAM_NUMBER(engine_val)
      |                                       ^
      |                                       ;
make: *** [Makefile:229: src/api/config.lo] Error 1

Here is my version of gcc:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) 

Release on PECL?

Once this is no longer experimental (starting to look good with #4 being done!!), should this be put on PECL for easy installation?

centos7 collect2: error: ld returned 1 exit status

centos 7
php7.3

creating libtool
appending configuration tag "CXX" to libtool
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... 
checking if g++ static flag  works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... unsupported
configure: creating ./config.status
config.status: creating config.h
/bin/sh /xiaolu/root/php-ext-wasm/extension/libtool --mode=compile g++  -I. -I/xiaolu/root/php-ext-wasm/extension -DPHP_ATOM_INC -I/xiaolu/root/php-ext-wasm/extension/include -I/xiaolu/root/php-ext-wasm/extension/main -I/xiaolu/root/php-ext-wasm/extension -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11   -c /xiaolu/root/php-ext-wasm/extension/wasm.cc -o wasm.lo 
mkdir .libs
 g++ -I. -I/xiaolu/root/php-ext-wasm/extension -DPHP_ATOM_INC -I/xiaolu/root/php-ext-wasm/extension/include -I/xiaolu/root/php-ext-wasm/extension/main -I/xiaolu/root/php-ext-wasm/extension -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -c /xiaolu/root/php-ext-wasm/extension/wasm.cc  -DPIC -o .libs/wasm.o
/bin/sh /xiaolu/root/php-ext-wasm/extension/libtool --mode=link cc -DPHP_ATOM_INC -I/xiaolu/root/php-ext-wasm/extension/include -I/xiaolu/root/php-ext-wasm/extension/main -I/xiaolu/root/php-ext-wasm/extension -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /xiaolu/root/php-ext-wasm/extension/modules  wasm.lo -Wl,-rpath,/xiaolu/root/php-ext-wasm/extension/. -L/xiaolu/root/php-ext-wasm/extension/. -lwasmer_runtime_c_api
cc -shared  .libs/wasm.o  -L/xiaolu/root/php-ext-wasm/extension/. -lwasmer_runtime_c_api  -Wl,-rpath -Wl,/xiaolu/root/php-ext-wasm/extension/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/usr/bin/ld: .libs/wasm.o: relocation R_X86_64_32S against symbol `wasm_array_buffer_class_entry_handlers' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [wasm.la] 错误 1
error: Recipe `php` failed with exit code 2

just build with php 7.3

after running just build I recieve the following. Does php-ext-wasm not support 7.3?

Running ubuntu 19.04

just build                                                                                                                       master
Cleaning..
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /home/alex/.linuxbrew/Cellar/php/7.3.11
checking for PHP includes... -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/main -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/TSRM -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/Zend -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext/date/lib
checking for PHP extension directory... /home/alex/.linuxbrew/Cellar/php/7.3.11/pecl/20180731
checking for PHP installed headers prefix... /home/alex/.linuxbrew/Cellar/php/7.3.11/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable wasm support... yes, shared
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... 
checking if g++ static flag  works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... unsupported
configure: creating ./config.status
config.status: creating config.h
/bin/bash /home/alex/projects/php-ext-wasm/src/libtool --mode=compile g++  -I. -I/home/alex/projects/php-ext-wasm/src -DPHP_ATOM_INC -I/home/alex/projects/php-ext-wasm/src/include -I/home/alex/projects/php-ext-wasm/src/main -I/home/alex/projects/php-ext-wasm/src -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/main -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/TSRM -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/Zend -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11   -c /home/alex/projects/php-ext-wasm/src/wasm.cc -o wasm.lo 
mkdir .libs
 g++ -I. -I/home/alex/projects/php-ext-wasm/src -DPHP_ATOM_INC -I/home/alex/projects/php-ext-wasm/src/include -I/home/alex/projects/php-ext-wasm/src/main -I/home/alex/projects/php-ext-wasm/src -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/main -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/TSRM -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/Zend -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -c /home/alex/projects/php-ext-wasm/src/wasm.cc  -DPIC -o .libs/wasm.o
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zim_WasmArrayBuffer___construct(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:108:55: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Buffer length must be positive; given %lld.", byte_length);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zim_WasmArrayBuffer_grow(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:174:55: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Number of pages must be positive; given %lld.", number_of_pages);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray___construct(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:2029:55: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Offset must be non-negative; given %lld.", offset);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2038:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
             "Offset must be smaller than the array buffer length; given %lld, buffer length is %zu.",
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             offset,
             ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2047:55: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 2, "Length must be non-negative; given %lld.", length);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2096:17: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
                 "Length must not be greater than the buffer length; given %lld, maximum length is %zu.",
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                 length,
                 ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_get(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:2199:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
             "Offset is outside the view range [0; %zu]; given %lld.",
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2201:13:
             offset
             ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_set(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:2282:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
             "Offset is outside the view range [0; %zu]; given %lld.",
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2284:13:
             offset
             ~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_unset(zend_execute_data*, zval*)’:
/home/alex/projects/php-ext-wasm/src/wasm.cc:2403:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long’ {aka ‘long int’} [-Wformat=]
             "Offset is outside the view range [0; %zu]; given %lld.",
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alex/projects/php-ext-wasm/src/wasm.cc:2405:13:
             offset
             ~~~~~~
/bin/bash /home/alex/projects/php-ext-wasm/src/libtool --mode=link cc -DPHP_ATOM_INC -I/home/alex/projects/php-ext-wasm/src/include -I/home/alex/projects/php-ext-wasm/src/main -I/home/alex/projects/php-ext-wasm/src -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/main -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/TSRM -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/Zend -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext -I/home/alex/.linuxbrew/Cellar/php/7.3.11/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/alex/projects/php-ext-wasm/src/modules  wasm.lo -Wl,-rpath,/home/alex/projects/php-ext-wasm/src/. -L/home/alex/projects/php-ext-wasm/src/. -lwasmer_runtime_c_api
cc -shared  .libs/wasm.o  -L/home/alex/projects/php-ext-wasm/src/. -lwasmer_runtime_c_api  -Wl,-rpath -Wl,/home/alex/projects/php-ext-wasm/src/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/usr/bin/ld: .libs/wasm.o: relocation R_X86_64_PC32 against symbol `wasm_array_buffer_class_entry_handlers' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [Makefile:199: wasm.la] Error 1
error: Recipe `build` failed with exit code 2

Cannot address by function name

I'm having some trouble with trying to make a sensible interface to actually using this library, but I may just be missing something obvious (or, alternatively, have completely missed a key paradigm :P)

Looking at your example copy of your exports-function.php example, we see that although we have an exported function of "sum", it only ever gets referenced by $exports->offsetGet(0), not by Sum.

Compiling the most barebones addition rust program, I end up with something like this:

(module
  (type $t0 (func (param i32) (result i32)))
  (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
    (i32.add
      (local.get $p0)
      (i32.const 1)))
  (memory $memory (export "memory") 16)
  (global $__data_end (export "__data_end") i32 (i32.const 1048576))
  (global $__heap_base (export "__heap_base") i32 (i32.const 1048576)))

The only way I can find to reference that function is like so: $addOne = (new Wasm\Extern($exports->offsetGet(1)))->asFunc();

There doesn't seem to be an getByName or similar.

I can iterate through the exports and filter it down to the exports that are only functions, but I haven't had any success at finding any method that will then translate that function to what it's name is.

Thank you!

Waht is the mini PHP version requirement?

Summary

I am trying to build the PHP extension of PHP version:

PHP 7.1.16-1+b1 (cli) (built: May 12 2018 08:31:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.16-1+b1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

on Linux.

But some build errors occur:

/tmp/php-ext-wasm-0.5.0/src/wasm.cc:123:132: error: macro "ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX" requires 6 arguments, but only 5 given
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasmarraybuffer_get_byte_length, ZEND_RETURN_VALUE, ARITY(0), IS_LONG, NOT_NULLABLE)

/tmp/php-ext-wasm-0.5.0/src/wasm.cc:123:1: error: ‘ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX’ does not name a type
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasmarraybuffer_get_byte_length, ZEND_RETURN_VALUE, ARITY(0), IS_LONG, NOT_NULLABLE

Go wasm not supported ?

Summary

I compiled a simple wasm instance with go, but it has exceptions.

Fatal error: Uncaught RuntimeException: An error happened while compiling or instantiating the module `/Users/mac-mini/go/src/demo/9/go_main.wasm`:
    8 link errors: (1 of 8) Import not found, namespace: go, name: debug (2 of 8) Import not found, namespace: go, name: runtime.wasmExit (3 of 8) Import not found, namespace: go, name: runtime.wasmWrite (4 of 8) Import not found, namespace: go, name: runtime.nanotime (5 of 8) Import not found, namespace: go, name: runtime.walltime (6 of 8) Import not found, namespace: go, name: runtime.scheduleCallback (7 of 8) Import not found, namespace: go, name: runtime.clearScheduledCallback (8 of 8) Import not found, namespace: go, name: runtime.getRandomData in /private/tmp/php-ext-wasm/lib/Instance.php:84
Stack trace:
#0 /private/tmp/php-ext-wasm/examples/test.php(7): Wasm\Instance->__construct('/Users/mac-mini...')
#1 {main}
  thrown in /private/tmp/php-ext-wasm/lib/Instance.php on line 84

Additional details

Go source code :

package main

func main() {

}

func test() {

}

Compile command : GOOS=js GOARCH=wasm go build -o go_main.wasm 8.go

Building from source or pecl fails on PHP 7.2 to 7.4

Describe the bug

Both pecl install and building from source fails with the same issue on both Linux and Mac

Steps to reproduce

  • php7.4-dev ( Install PHP of your choice (brew install php, apt-get install php7.4-dev, or compile)
  • pecl install wasm

Expected behavior

Extension builds

Actual behavior

A clear and concise description of what actually happened.

If applicable, add screenshots to help explain your problem.

Additional context

Relevant line from the output below:

/bin/bash /tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/libtool --mode=compile   -I. -I/tmp/pear/temp/wasm/src -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/include -I/tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/main -I/tmp/pear/temp/wasm/src -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H     -c /tmp/pear/temp/wasm/src/wasm.cc -o wasm.lo
libtool: unrecognized option `-I.'
Try `libtool --help' for more information.
Makefile:192: recipe for target 'wasm.lo' failed
make: *** [wasm.lo] Error 1

libtool version is 2.4.6_2 on mac and 2.4.6-0.1 on Linux.

Sample output from a Linux build but I get the same errors on mac.

pecl install wasm

downloading wasm-0.5.0.tgz ...
Starting to download wasm-0.5.0.tgz (2,633,292 bytes)
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................done: 2,633,292 bytes
23 source files, building
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
building in /tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0
running: /tmp/pear/temp/wasm/src/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20190902
checking for PHP installed headers prefix... /usr/include/php/20190902
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable wasm support... yes, shared
checking for a sed that does not truncate output... /bin/sed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/bash /tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/libtool --mode=compile   -I. -I/tmp/pear/temp/wasm/src -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/include -I/tmp/pear/temp/pear-build-rootrldyec/wasm-0.5.0/main -I/tmp/pear/temp/wasm/src -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H     -c /tmp/pear/temp/wasm/src/wasm.cc -o wasm.lo
libtool: unrecognized option `-I.'
Try `libtool --help' for more information.
Makefile:192: recipe for target 'wasm.lo' failed
make: *** [wasm.lo] Error 1
ERROR: `make' failed

How to use with wasm-pack?

I have a small test project and use wasm-pack --target web to expose it to the browser. Is it possible ot use wasm-pack instead of just compile-wasm to generate a wasm that this PHP extension can read?

Pass string to wasm function

Hi, I think the project looks really great. How would you pass a string to a function defined in wasm. The memory example shows how you could return a string from a function. I would assume that we could also create a Uint8Array and pass this containing the string bytes to the wasm function? In this case we could probably create in this lib some helper functions i.e. to convert a string to Uint8Array. Also Iam curious whether it would be possible to pass more complex data structures like assoc array (struct) to a wasm function?

Support PHP 7.2

Summary

What's the PHP version?

  • Hello~ My PHP version is PHP 7.2.18 in CentOS 7.2. I haven't found it in the doc.
  • When I build it, it replies to some error.

Additional details

  • The error info like this:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zim_WasmArrayBuffer_getByteLength(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:139:32: error: ‘ZEND_PARSE_PARAMETERS_NONE’ was not declared in this scope
     ZEND_PARSE_PARAMETERS_NONE();
                                ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zif_wasm_compile(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:505:13: error: ‘zend_register_persistent_resource_ex’ was not declared in this scope
             );
             ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zif_wasm_module_clean_up_persistent_resources(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:571:32: error: ‘ZEND_PARSE_PARAMETERS_NONE’ was not declared in this scope
     ZEND_PARSE_PARAMETERS_NONE();
                                ^
In file included from /www/server/php/72/include/php/Zend/zend.h:29:0,
                 from /www/server/php/72/include/php/main/php.h:35,
                 from /data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.hh:23,
                 from /data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:19:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: At global scope:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1062:100: error: ‘_IS_NUMBER’ was not declared in this scope
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasm_invoke_function, ZEND_RETURN_VALUE, ARITY(3), _IS_NUMBER, NULLABLE)
                                                                                                    ^
/www/server/php/72/include/php/Zend/zend_types.h:143:5: note: in definition of macro ‘ZEND_TYPE_ENCODE’
  (((code) << Z_L(1)) | ((allow_null) ? Z_L(0x1) : Z_L(0x0)))
     ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1062:1: note: in expansion of macro ‘ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX’
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasm_invoke_function, ZEND_RETURN_VALUE, ARITY(3), _IS_NUMBER, NULLABLE)
 ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zif_wasm_get_last_error(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1475:32: error: ‘ZEND_PARSE_PARAMETERS_NONE’ was not declared in this scope
     ZEND_PARSE_PARAMETERS_NONE();
                                ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zif_WasmTypedArray_get_offset(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1724:32: error: ‘ZEND_PARSE_PARAMETERS_NONE’ was not declared in this scope
     ZEND_PARSE_PARAMETERS_NONE();
                                ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘void zif_WasmTypedArray_get_length(zend_execute_data*, zval*)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1751:32: error: ‘ZEND_PARSE_PARAMETERS_NONE’ was not declared in this scope
     ZEND_PARSE_PARAMETERS_NONE();
                                ^
In file included from /www/server/php/72/include/php/Zend/zend.h:29:0,
                 from /www/server/php/72/include/php/main/php.h:35,
                 from /data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.hh:23,
                 from /data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:19:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: At global scope:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1762:105: error: ‘_IS_NUMBER’ was not declared in this scope
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasmtypedarray_offset_get, ZEND_RETURN_VALUE, ARITY(1), _IS_NUMBER, NOT_NULLABLE)
                                                                                                         ^
/www/server/php/72/include/php/Zend/zend_types.h:143:5: note: in definition of macro ‘ZEND_TYPE_ENCODE’
  (((code) << Z_L(1)) | ((allow_null) ? Z_L(0x1) : Z_L(0x0)))
     ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:1762:1: note: in expansion of macro ‘ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX’
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_wasmtypedarray_offset_get, ZEND_RETURN_VALUE, ARITY(1), _IS_NUMBER, NOT_NULLABLE)
 ^
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc: In function ‘int zm_startup_wasm(int, int)’:
/data/alpha/rust/php-ext-wasm-0.5.0/src/wasm.cc:2104:65: error: ‘ZEND_ACC_IMMUTABLE’ was not declared in this scope
     wasm_array_buffer_class_entry->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_IMMUTABLE;
                                                                 ^
make: *** [wasm.lo] Error 1
error: Recipe `build` failed with exit code 2

just build with Docker image php-7.2-fpm

just build

/bin/bash /tmp/pear/temp/php-ext-wasm/src/libtool --mode=compile g++  -I. -I/tmp/pear/temp/php-ext-wasm/src -DPHP_ATOM_INC -I/tmp/pear/temp/php-ext-wasm/src/include -I/tmp/pear/temp/php-ext-wasm/src/main -I/tmp/pear/temp/php-ext-wasm/src -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11   -c /tmp/pear/temp/php-ext-wasm/src/wasm.cc -o wasm.lo
mkdir .libs
 g++ -I. -I/tmp/pear/temp/php-ext-wasm/src -DPHP_ATOM_INC -I/tmp/pear/temp/php-ext-wasm/src/include -I/tmp/pear/temp/php-ext-wasm/src/main -I/tmp/pear/temp/php-ext-wasm/src -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -c /tmp/pear/temp/php-ext-wasm/src/wasm.cc  -DPIC -o .libs/wasm.o
/bin/bash /tmp/pear/temp/php-ext-wasm/src/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/php-ext-wasm/src/include -I/tmp/pear/temp/php-ext-wasm/src/main -I/tmp/pear/temp/php-ext-wasm/src -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/php-ext-wasm/src/modules  wasm.lo -Wl,-rpath,/tmp/pear/temp/php-ext-wasm/src/. -L/tmp/pear/temp/php-ext-wasm/src/. -lwasmer_runtime_c_api
cc -shared  .libs/wasm.o  -L/tmp/pear/temp/php-ext-wasm/src/. -lwasmer_runtime_c_api  -Wl,-rpath -Wl,/tmp/pear/temp/php-ext-wasm/src/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/usr/bin/ld: .libs/wasm.o: relocation R_X86_64_PC32 against undefined symbol `executor_globals' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [Makefile:199: wasm.la] Error 1
error: Recipe `build` failed with exit code 2

pecl install wasm

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/bash /tmp/pear/temp/pear-build-defaultuser79G7f4/wasm-0.5.0/libtool --mode=compile   -I. -I/tmp/pear/temp/wasm/src -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuser79G7f4/wasm-0.5.0/include -I/tmp/pear/temp/pear-build-defaultuser79G7f4/wasm-0.5.0/main -I/tmp/pear/temp/wasm/src -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H     -c /tmp/pear/temp/wasm/src/wasm.cc -o wasm.lo
libtool: unrecognized option `-I.'
Try `libtool --help' for more information.
make: *** [Makefile:194: wasm.lo] Error 1
ERROR: `make' failed

I don't know what went wrong
Providing a Dockerfile might be a better option

Compile failed in different situation

Hi, thanks for this great library, I saw multiple changes and try to build on my computer. But got different errors:

  1. `./configure --enable-wasmer'
--enable-wasmer options not found

After checkout configure file, does it be --enable-wasm?

  1. make succeed, but the make test didn't work:
FAIL WAT: wat2wasm [tests/api/wat/02-wat2wasm.phpt] 
FAIL WAT: wat2wasm (error) [tests/api/wat/02-wat2wasm_error.phpt] 
FAIL Wasmer PHP - Exceptions [tests/exceptions.phpt] 
FAIL Wasmer PHP [tests/extension.phpt] 
=====================================================================
TIME END 2022-03-12 08:38:44

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   33
---------------------------------------------------------------------

Number of tests :  186               175
Tests skipped   :   11 (  5.9%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :  175 ( 94.1%) (100.0%)
Tests passed    :    0 (  0.0%) (  0.0%)
---------------------------------------------------------------------
Time taken      :   10 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Config API functions [tests/api/config/00-functions.phpt]
Config API functions arguments information [tests/api/config/01-arginfo.phpt]
Config API: wasm_config_delete [tests/api/config/02-wasm_config_delete.phpt]
Config API: wasm_config_new [tests/api/config/02-wasm_config_new.phpt]
Config API: wasm_config_set_compiler [tests/api/config/02-wasm_config_set_compiler.phpt]
Config API: wasm_config_set_engine [tests/api/config/02-wasm_config_set_engine.phpt]
Engine API functions [tests/api/engine/00-functions.phpt]
Engine API functions arguments information [tests/api/engine/01-arginfo.phpt]
Engine API: wasm_engine_delete [tests/api/engine/02-wasm_engine_delete.phpt]
Engine API: wasm_engine_new [tests/api/engine/02-wasm_engine_new.phpt]
Engine API: wasm_engine_new_with_config [tests/api/engine/02-wasm_engine_new_with_config.phpt]
Engine API: wasm_engine_new_with_config (LLVM) [tests/api/engine/02-wasm_engine_new_with_config_compiler_LLVM.phpt]
Engine API: wasm_engine_new_with_config (Cranelift) [tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift.phpt]
Engine API: wasm_engine_new_with_config (Cranelift, JIT) [tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift_JIT.phpt]
Engine API: wasm_engine_new_with_config (Cranelift, Native) [tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift_native.phpt]
Engine API: wasm_engine_new_with_config (Cranelift, Object File) [tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift_object_file.phpt]
Engine API: wasm_engine_new_with_config (Singlepass) [tests/api/engine/02-wasm_engine_new_with_config_compiler_singlepass.phpt]
Engine API: wasm_engine_new_with_config (JIT) [tests/api/engine/02-wasm_engine_new_with_config_engine_JIT.phpt]
Engine API: wasm_engine_new_with_config (Native) [tests/api/engine/02-wasm_engine_new_with_config_engine_native.phpt]
Engine API: wasm_engine_new_with_config (Object File) [tests/api/engine/02-wasm_engine_new_with_config_engine_object_file.phpt]
Extern API functions [tests/api/objects/extern/00-functions.phpt]
Extern API functions arguments information [tests/api/objects/extern/01-arginfo.phpt]
Extern API: wasm_extern_as_func [tests/api/objects/extern/02-wasm_extern_as_func.phpt]
Extern API: wasm_extern_as_global [tests/api/objects/extern/02-wasm_extern_as_global.phpt]
Extern API: wasm_extern_delete [tests/api/objects/extern/02-wasm_extern_delete.phpt]
Extern API: wasm_extern_kind [tests/api/objects/extern/02-wasm_extern_kind.phpt]
Extern API: wasm_extern_type [tests/api/objects/extern/02-wasm_extern_type.phpt]
Extern API: Wasm\Vec\Extern (clone) [tests/api/objects/extern/02-wasm_vec_extern___clone.phpt]
Extern API: Wasm\Vec\Extern::construct() [tests/api/objects/extern/02-wasm_vec_extern___construct.phpt]
Extern API: Wasm\Vec\Extern::offsetExists() [tests/api/objects/extern/02-wasm_vec_extern_offsetExists.phpt]
Extern API: Wasm\Vec\Extern::offsetGet() [tests/api/objects/extern/02-wasm_vec_extern_offsetGet.phpt]
Extern API: Wasm\Vec\Extern::offsetSet() [tests/api/objects/extern/02-wasm_vec_extern_offsetSet.phpt]
Func API functions [tests/api/objects/func/00-functions.phpt]
Func API functions arguments information [tests/api/objects/func/01-arginfo.phpt]
Func API: wasm_func_as_extern [tests/api/objects/func/02-wasm_func_as_extern.phpt]
Func API: wasm_func_call (guest) [tests/api/objects/func/02-wasm_func_call_guest.phpt]
Func API: wasm_func_call (trap) [tests/api/objects/func/02-wasm_func_call_with_trap.phpt]
Func API: wasm_func_delete [tests/api/objects/func/02-wasm_func_delete.phpt]
Func API: wasm_func_new [tests/api/objects/func/02-wasm_func_new.phpt]
Func API: wasm_func_type [tests/api/objects/func/02-wasm_func_type.phpt]
Global API: wasm_global_as_extern [tests/api/objects/global/02-wasm_global_as_extern.phpt]
Global API: wasm_global_copy [tests/api/objects/global/02-wasm_global_copy.phpt]
Global API: wasm_global_delete [tests/api/objects/global/02-wasm_global_delete.phpt]
Global API: wasm_global_get (guest) [tests/api/objects/global/02-wasm_global_get_guest.phpt]
Global API: wasm_global_get (host) [tests/api/objects/global/02-wasm_global_get_host.phpt]
Global API: wasm_global_new [tests/api/objects/global/02-wasm_global_new.phpt]
Global API: wasm_global_same [tests/api/objects/global/02-wasm_global_same.phpt]
Global API: wasm_global_set (guest) [tests/api/objects/global/02-wasm_global_set_guest.phpt]
Global API: wasm_global_set (host) [tests/api/objects/global/02-wasm_global_set_host.phpt]
Global API: wasm_global_type [tests/api/objects/global/02-wasm_global_type.phpt]
Instance API: wasm_instance_delete [tests/api/objects/instance/02-wasm_instance_delete.phpt]
Instance API: wasm_instance_exports [tests/api/objects/instance/02-wasm_instance_exports.phpt]
Instance API: wasm_instance_new [tests/api/objects/instance/02-wasm_instance_new.phpt]
Instance API: wasm_instance_new (trap) [tests/api/objects/instance/02-wasm_instance_new_with_trap.phpt]
Memory API functions [tests/api/objects/memory/00-functions.phpt]
Memory API: wasm_memory_as_extern [tests/api/objects/memory/02-wasm_memory_as_extern.phpt]
Memory API: wasm_memory_data [tests/api/objects/memory/02-wasm_memory_data.phpt]
Memory API: wasm_memory_data_size [tests/api/objects/memory/02-wasm_memory_data_size.phpt]
Memory API: wasm_memory_delete [tests/api/objects/memory/02-wasm_memory_delete.phpt]
Memory API: wasm_memory_grow [tests/api/objects/memory/02-wasm_memory_grow.phpt]
Memory API: wasm_memory_new [tests/api/objects/memory/02-wasm_memory_new.phpt]
Memory API: wasm_memory_same [tests/api/objects/memory/02-wasm_memory_same.phpt]
Memory API: wasm_memory_size [tests/api/objects/memory/02-wasm_memory_size.phpt]
Memory API: wasm_memory_type [tests/api/objects/memory/02-wasm_memory_type.phpt]
Module API functions [tests/api/objects/module/00-functions.phpt]
Module API functions arguments information [tests/api/objects/module/01-arginfo.phpt]
Module API: wasm_module_delete [tests/api/objects/module/02-wasm_module_delete.phpt]
Module API: wasm_module_exports [tests/api/objects/module/02-wasm_module_exports.phpt]
Module API: wasm_module_imports [tests/api/objects/module/02-wasm_module_imports.phpt]
Module API: wasm_module_name [tests/api/objects/module/02-wasm_module_name.phpt]
Module API: wasm_module_new [tests/api/objects/module/02-wasm_module_new.phpt]
Module API: wasm_module_new (Cranelift, JIT) [tests/api/objects/module/02-wasm_module_new_cranelift_JIT.phpt]
Module API: wasm_module_new (Cranelift, Object File) [tests/api/objects/module/02-wasm_module_new_cranelift_object_file.phpt]
Module API: wasm_module_serialize and wasm_module_deserialize [tests/api/objects/module/02-wasm_module_ser_deser.phpt]
Module API: wasm_module_set_name [tests/api/objects/module/02-wasm_module_set_name.phpt]
Module API: wasm_module_validate [tests/api/objects/module/02-wasm_module_validate.phpt]
Trap API functions [tests/api/objects/trap/00-functions.phpt]
Trap API functions arguments information [tests/api/objects/trap/01-arginfo.phpt]
Trap API: wasm_trap_delete [tests/api/objects/trap/02-wasm_trap_delete.phpt]
Trap API: wasm_trap_message [tests/api/objects/trap/02-wasm_trap_message.phpt]
Trap API: wasm_trap_new [tests/api/objects/trap/02-wasm_trap_new.phpt]
Trap API: wasm_trap_origin [tests/api/objects/trap/02-wasm_trap_origin.phpt]
Trap API: wasm_trap_trace [tests/api/objects/trap/02-wasm_trap_trace.phpt]
Val API functions [tests/api/objects/val/00-functions.phpt]
Val API functions arguments information [tests/api/objects/val/01-arginfo.phpt]
Val API: wasm_val_i*/wasm_val_f* [tests/api/objects/val/02-wasm_val.phpt]
Val API: wasm_val_delete [tests/api/objects/val/02-wasm_val_delete.phpt]
Val API: wasm_val_kind [tests/api/objects/val/02-wasm_val_kind.phpt]
Val API [tests/api/objects/val/02-wasm_val_value.phpt]
Val API: Wasm\Vec\Val::construct() [tests/api/objects/val/02-wasm_vec_val___construct.phpt]
Val API: Wasm\Vec\Val::offsetGet() [tests/api/objects/val/02-wasm_vec_val_offsetGet.phpt]
Val API: Wasm\Vec\Val::offsetSet() [tests/api/objects/val/02-wasm_vec_val_offsetSet.phpt]
Store API functions [tests/api/store/00-functions.phpt]
Store API functions arguments information [tests/api/store/01-arginfo.phpt]
Store API: wasm_store_delete [tests/api/store/02-wasm_store_delete.phpt]
Store API: wasm_store_new [tests/api/store/02-wasm_store_new.phpt]
ExportType API functions [tests/api/types/exporttype/00-functions.phpt]
ExportType API functions arguments information [tests/api/types/exporttype/01-arginfo.phpt]
ExportType API: wasm_exporttype_module [tests/api/types/exporttype/02-wasm_exporttype_name.phpt]
ExportType API: wasm_exporttype_new [tests/api/types/exporttype/02-wasm_exporttype_new.phpt]
ExportType API: wasm_exporttype_new [tests/api/types/exporttype/02-wasm_exporttype_type.phpt]
ExternType API functions [tests/api/types/externtype/00-functions.phpt]
ExternType API functions arguments information [tests/api/types/externtype/01-arginfo.phpt]
ExternType API: wasm_externtype_delete [tests/api/types/externtype/02-wasm_externtype_delete.phpt]
FuncType API functions [tests/api/types/functype/00-functions.phpt]
FuncType API functions arguments information [tests/api/types/functype/01-arginfo.phpt]
FuncType API: wasm_functype_copy [tests/api/types/functype/02-wasm_functype_copy.phpt]
FuncType API: wasm_functype_delete [tests/api/types/functype/02-wasm_functype_delete.phpt]
FuncType API: wasm_functype_new [tests/api/types/functype/02-wasm_functype_new.phpt]
FuncType API: wasm_functype_params [tests/api/types/functype/02-wasm_functype_params.phpt]
FuncType API: wasm_functype_results [tests/api/types/functype/02-wasm_functype_results.phpt]
FuncType API: Wasm\Vec\FuncType::construct() [tests/api/types/functype/02-wasm_vec_functype___construct.phpt]
FuncType API: Wasm\Vec\FuncType::offsetGet() [tests/api/types/functype/02-wasm_vec_functype_offsetGet.phpt]
FuncType API: Wasm\Vec\FuncType::offsetSet() [tests/api/types/functype/02-wasm_vec_functype_offsetSet.phpt]
GlobalType API functions [tests/api/types/globaltype/00-functions.phpt]
GlobalType API functions arguments information [tests/api/types/globaltype/01-arginfo.phpt]
GlobalType API: wasm_globaltype_as_externtype [tests/api/types/globaltype/02-wasm_globaltype_as_externtype.phpt]
GlobalType API: wasm_globaltype_content [tests/api/types/globaltype/02-wasm_globaltype_content.phpt]
GlobalType API: wasm_globaltype_delete [tests/api/types/globaltype/02-wasm_globaltype_delete.phpt]
GlobalType API: wasm_globaltype_mutability [tests/api/types/globaltype/02-wasm_globaltype_mutability.phpt]
GlobalType API: wasm_globaltype_new [tests/api/types/globaltype/02-wasm_globaltype_new.phpt]
GlobalType API: Wasm\Vec\GlobalType::construct() [tests/api/types/globaltype/02-wasm_vec_globaltype___construct.phpt]
GlobalType API: Wasm\Vec\GlobalType::offsetGet() [tests/api/types/globaltype/02-wasm_vec_globaltype_offsetGet.phpt]
GlobalType API: Wasm\Vec\GlobalType::offsetSet() [tests/api/types/globaltype/02-wasm_vec_globaltype_offsetSet.phpt]
ImportType API functions [tests/api/types/importtype/00-functions.phpt]
ImportType API functions arguments information [tests/api/types/importtype/01-arginfo.phpt]
ImportType API: wasm_importtype_module [tests/api/types/importtype/02-wasm_importtype_module.phpt]
ImportType API: wasm_importtype_module [tests/api/types/importtype/02-wasm_importtype_name.phpt]
ImportType API: wasm_importtype_new [tests/api/types/importtype/02-wasm_importtype_new.phpt]
ImportType API: wasm_importtype_new [tests/api/types/importtype/02-wasm_importtype_type.phpt]
Limits API functions [tests/api/types/limits/00-functions.phpt]
Limits API functions arguments information [tests/api/types/limits/01-arginfo.phpt]
Limits API: wasm_limits_max [tests/api/types/limits/02-wasm_limits_max.phpt]
Limits API: wasm_limits_min [tests/api/types/limits/02-wasm_limits_min.phpt]
Limits API: wasm_limits_new [tests/api/types/limits/02-wasm_limits_new.phpt]
MemoryType API functions [tests/api/types/memorytype/00-functions.phpt]
MemoryType API functions arguments information [tests/api/types/memorytype/01-arginfo.phpt]
MemoryType API: wasm_memorytype_as_externtype [tests/api/types/memorytype/02-wasm_memorytype_as_externtype.phpt]
MemoryType API: wasm_memorytype_delete [tests/api/types/memorytype/02-wasm_memorytype_delete.phpt]
MemoryType API: wasm_memorytype_limits [tests/api/types/memorytype/02-wasm_memorytype_limits.phpt]
MemoryType API: wasm_memorytype_new [tests/api/types/memorytype/02-wasm_memorytype_new.phpt]
TableType API functions [tests/api/types/tabletype/00-functions.phpt]
TableType API functions arguments information [tests/api/types/tabletype/01-arginfo.phpt]
TableType API: wasm_tabletype_as_externtype [tests/api/types/tabletype/02-wasm_tabletype_as_externtype.phpt]
TableType API: wasm_tabletype_delete [tests/api/types/tabletype/02-wasm_tabletype_delete.phpt]
TableType API: wasm_tabletype_element [tests/api/types/tabletype/02-wasm_tabletype_element.phpt]
TableType API: wasm_tabletype_limits [tests/api/types/tabletype/02-wasm_tabletype_limits.phpt]
TableType API: wasm_tabletype_new [tests/api/types/tabletype/02-wasm_tabletype_new.phpt]
TableType API: Wasm\Vec\TableType::construct() [tests/api/types/tabletype/02-wasm_vec_tabletype___construct.phpt]
TableType API: Wasm\Vec\TableType::offsetGet() [tests/api/types/tabletype/02-wasm_vec_tabletype_offsetGet.phpt]
TableType API: Wasm\Vec\TableType::offsetSet() [tests/api/types/tabletype/02-wasm_vec_tabletype_offsetSet.phpt]
ValKind API functions [tests/api/types/valkind/00-functions.phpt]
ValKind API functions arguments information [tests/api/types/valkind/01-arginfo.phpt]
ValKind API: wasm_valkind_is_num [tests/api/types/valkind/02-wasm_valtype_is_num.phpt]
ValKind API: wasm_valkind_is_ref [tests/api/types/valkind/02-wasm_valtype_is_ref.phpt]
ValType API classes [tests/api/types/valtype/00-classes.phpt]
ValType API functions [tests/api/types/valtype/00-functions.phpt]
ValType API functions arguments information [tests/api/types/valtype/01-arginfo.phpt]
ValType API: wasm_valtype_delete [tests/api/types/valtype/02-wasm_valtype_delete.phpt]
ValType API: wasm_valtype_is_num [tests/api/types/valtype/02-wasm_valtype_is_num.phpt]
ValType API: wasm_valtype_is_ref [tests/api/types/valtype/02-wasm_valtype_is_ref.phpt]
ValType API: wasm_valtype_kind [tests/api/types/valtype/02-wasm_valtype_kind.phpt]
ValType API: wasm_valtype_new [tests/api/types/valtype/02-wasm_valtype_new.phpt]
ValType API: Wasm\Vec\ValType::construct() [tests/api/types/valtype/02-wasm_vec_valtype___construct.phpt]
ValType API: Wasm\Vec\ValType::offsetGet() [tests/api/types/valtype/02-wasm_vec_valtype_offsetGet.phpt]
ValType API: Wasm\Vec\ValType::offsetSet() [tests/api/types/valtype/02-wasm_vec_valtype_offsetSet.phpt]
Wasmer: wasmer_version [tests/api/wasmer/wasmer_version.phpt]
Wasmer: wasmer_version_major [tests/api/wasmer/wasmer_version_major.phpt]
Wasmer: wasmer_version_minor [tests/api/wasmer/wasmer_version_minor.phpt]
Wasmer: wasmer_version_patch [tests/api/wasmer/wasmer_version_patch.phpt]
Wasmer: wasmer_version_pre [tests/api/wasmer/wasmer_version_pre.phpt]
WAT: wat2wasm [tests/api/wat/02-wat2wasm.phpt]
WAT: wat2wasm (error) [tests/api/wat/02-wat2wasm_error.phpt]
Wasmer PHP - Exceptions [tests/exceptions.phpt]
Wasmer PHP [tests/extension.phpt]
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.	You can then email it to [email protected] later.
Do you want to send this report now? [Yns]: n
make: *** [Makefile:132: test] Error 1
  1. After execute make clean, I always got:
cc -shared  src/api/.libs/config.o src/api/.libs/engine.o src/api/.libs/store.o src/api/.libs/wasmer.o src/api/.libs/wat.o src/api/objects/.libs/extern.o src/api/objects/.libs/foreign.o src/api/objects/.libs/func.o src/api/objects/.libs/frame.o src/api/objects/.libs/global.o src/api/objects/.libs/instance.o src/api/objects/.libs/memory.o src/api/objects/.libs/module.o src/api/objects/.libs/table.o src/api/objects/.libs/trap.o src/api/objects/.libs/val.o src/api/types/.libs/exporttype.o src/api/types/.libs/externtype.o src/api/types/.libs/functype.o src/api/types/.libs/globaltype.o src/api/types/.libs/importtype.o src/api/types/.libs/limits.o src/api/types/.libs/memorytype.o src/api/types/.libs/tabletype.o src/api/types/.libs/valkind.o src/api/types/.libs/valtype.o src/.libs/wasm.o  -L/app/wasmer-php/ext/lib -lwasmer  -Wl,-rpath -Wl,/app/wasmer-php/ext/lib -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lwasmer
collect2: error: ld returned 1 exit status
make: *** [Makefile:303: wasm.la] Error 1

Maybe the previous build was failed?

OS: alpine in docker
PHPVersion: 8.0

The compilation worked in the previous 6x commits, looking forward to your help.

Recipe for target 'wasm.la' failed

Thanks for the bug report!

Describe the bug

error: Recipe build failed with exit code 2

Steps to reproduce

just build
Cleaning..
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20190902
checking for PHP installed headers prefix... /usr/include/php/20190902
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable wasm support... yes, shared
checking for a sed that does not truncate output... /bin/sed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... 
checking if g++ static flag  works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... unsupported
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
/bin/bash /home/stefan/code/rust/wasmer-php/src/libtool --mode=compile g++  -I. -I/home/stefan/code/rust/wasmer-php/src -DPHP_ATOM_INC -I/home/stefan/code/rust/wasmer-php/src/include -I/home/stefan/code/rust/wasmer-php/src/main -I/home/stefan/code/rust/wasmer-php/src -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -std=c++11   -c /home/stefan/code/rust/wasmer-php/src/wasm.cc -o wasm.lo 
mkdir .libs
 g++ -I. -I/home/stefan/code/rust/wasmer-php/src -DPHP_ATOM_INC -I/home/stefan/code/rust/wasmer-php/src/include -I/home/stefan/code/rust/wasmer-php/src/main -I/home/stefan/code/rust/wasmer-php/src -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -DHAVE_CONFIG_H -std=c++11 -c /home/stefan/code/rust/wasmer-php/src/wasm.cc  -DPIC -o .libs/wasm.o
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zim_WasmArrayBuffer___construct(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:108:113: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Buffer length must be positive; given %lld.", byte_length);
                                                                                                                 ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zim_WasmArrayBuffer_grow(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:174:119: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Number of pages must be positive; given %lld.", number_of_pages);
                                                                                                                       ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zif_WasmTypedArray___construct(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2029:105: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 0, "Offset must be non-negative; given %lld.", offset);
                                                                                                         ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2041:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2047:105: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
         zend_throw_exception_ex(zend_ce_exception, 2, "Length must be non-negative; given %lld.", length);
                                                                                                         ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2099:13: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘zend_long {aka long int}’ [-Wformat=]
             );
             ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_get(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2202:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_set(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2285:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/home/stefan/code/rust/wasmer-php/src/wasm.cc: In function ‘void zif_WasmTypedArray_offset_unset(zend_execute_data*, zval*)’:
/home/stefan/code/rust/wasmer-php/src/wasm.cc:2406:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 5 has type ‘zend_long {aka long int}’ [-Wformat=]
         );
         ^
/bin/bash /home/stefan/code/rust/wasmer-php/src/libtool --mode=link cc -DPHP_ATOM_INC -I/home/stefan/code/rust/wasmer-php/src/include -I/home/stefan/code/rust/wasmer-php/src/main -I/home/stefan/code/rust/wasmer-php/src -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o wasm.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/stefan/code/rust/wasmer-php/src/modules  wasm.lo -Wl,-rpath,/home/stefan/code/rust/wasmer-php/src/. -L/home/stefan/code/rust/wasmer-php/src/. -lwasmer
cc -shared  .libs/wasm.o  -L/home/stefan/code/rust/wasmer-php/src/. -lwasmer  -Wl,-rpath -Wl,/home/stefan/code/rust/wasmer-php/src/. -Wl,-soname -Wl,wasm.so -o .libs/wasm.so
/home/stefan/code/rust/wasmer-php/src/./libwasmer.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:197: recipe for target 'wasm.la' failed
make: *** [wasm.la] Error 1
error: Recipe `build` failed with exit code 2

Additional info

php -v
PHP 7.4.10 (cli) (built: Sep 9 2020 06:36:14) ( NTS )

If I did some significant work on this repo (touching almost every file), would you merge it?

I would like to rework this repository into something more widely usable in the PHP community. Here are a few things that I've noticed:

  • A PHP extension is required to do anything. This is probably the single biggest thing blocking wide adoption of this library. The vast majority of PHP applications are hosted on shared hosting providers that don't allow installing/loading additional PHP extensions. Even for the ones that are hosted on e.g. a VPS or whatever, installing some random PHP extension is not a common thing.
  • Because the extension exposes the wasmer engine as a resource in PHP, it's impossible to write a pure PHP polyfill that would e.g. use FFI or similar to get the same functionality. It's not possible to create a new resource type directly in PHP and it is also not possible to pretend that an object is an instance of a particular resource type, so even if I write a class that has the same interface as your resource, I still can't pass it in as an argument to the constructor of e.g. \Wasm\Module. There are a couple of libraries that I'm aware of that rely on an extension, but have a pure PHP implementation as a fallback -- even if that's just via FFI. FFI is a relatively new thing to PHP, but I think it's still a viable path for people using PHP 7.4 or higher.
  • Because many of the classes are final, I also can't extend the class and make the changes that I need to make in order to support the above on my own.
  • Details about the wasmer engine need to be known to the developer in order to effectively use this library. I'm not sure that this is actually based on any real technical requirement though -- it should be possible to expose a limited but very straightforward interface to developers that encapsulates those details. As a very simple example, maybe something along the lines of:
// file.wasm exports add and multiply functions and a myval value
$wasm = \Wasm::load('/path/to/my/file.wasm');

echo($wasm->add(1, 2));
echo($wasm->multiple(2, 4));
echo($wasm->myval);

This would more or less be a 2.x version of this library (I'm not sure how you'd do this without a BC break). Maybe it's of interest?

Compilation issue on ppa:ondrej/php

Hi,

I'm very excited about the possibilities for this extension!!! :-)

Describe the bug

Should I build against staging branch? When I built against master it didn't complete.

Steps to reproduce

Followed installation instructions in README for staging branch

Expected behavior

php examples/simple.php didn't run

Actual behavior

/home/michael/php/php-ext-wasm# php examples/simple.php
PHP Warning:  Use of undefined constant WASM_TYPE_I32 - assumed 'WASM_TYPE_I32' (this will throw an Error in a future version of PHP) in /home/michael/php/php-ext-wasm/lib/Prelude.php on line 7
PHP Warning:  Use of undefined constant WASM_TYPE_I64 - assumed 'WASM_TYPE_I64' (this will throw an Error in a future version of PHP) in /home/michael/php/php-ext-wasm/lib/Prelude.php on line 8
PHP Warning:  Use of undefined constant WASM_TYPE_F32 - assumed 'WASM_TYPE_F32' (this will throw an Error in a future version of PHP) in /home/michael/php/php-ext-wasm/lib/Prelude.php on line 9
PHP Warning:  Use of undefined constant WASM_TYPE_F64 - assumed 'WASM_TYPE_F64' (this will throw an Error in a future version of PHP) in /home/michael/php/php-ext-wasm/lib/Prelude.php on line 10
PHP Fatal error:  Uncaught Error: Call to undefined function Wasm\wasm_fetch_bytes() in /home/michael/php/php-ext-wasm/lib/Instance.php:75
Stack trace:
#0 /home/michael/php/php-ext-wasm/examples/simple.php(7): Wasm\Instance->__construct('/home/michael/p...')
#1 {main}
  thrown in /home/michael/php/php-ext-wasm/lib/Instance.php on line 75

Is it possible to write to WebAssembly.Memory in PHP that is exported to and read in JavaScript in parallel?

Summary

Consider

<?php 
  if (isset($_GET["start"])) {
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/octet-stream");
    echo passthru("parec -v --raw -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor");
    exit();
  }

where due to Chromium refusing to capture monitor devices when getUserMedia({audio: true}) is executed at Linux we use
php -S localhost:8000 to stream output of passthru() to Response.body (ReadableStream) from fetch() call.

let controller, signal;
const [start, stop] = document.querySelectorAll('button');
start.onclick = async e => {
  start.disabled = true;
  // set parameters as arrays for potential "infinite" input, output stream
  let { track, port } = await new AudioWorkletStream({
    latencyHint: 1,
    workletOptions: {
      numberOfInputs: 1,
      numberOfOutputs: 2,
      channelCount: 2,
      processorOptions: {
        codec: 'audio/wav',
        offset: 0,
      },
    },
  }).promise;

  console.log(track, port);
  controller = new AbortController();
  signal = controller.signal;
  fetch('http://localhost:8000?start=true', { signal })
    .then(r => r.body)
    .then(readable => {
      const reader = readable.getReader();
      reader
        .read()
        .then(function process({ value, done }) {
          if (done) {
            console.log(done);
            return;
          }
          console.log(value);
          return reader.read().then(process);
        })
        .catch(console.error);
    });
};
stop.onclick = e => {
  controller.abort();
};

Ideally we should be able to write the output from the shell script directly to a WebAssembly Memory instance, grow the shared array buffer if necessary, export that same Memory instance to JavaScript for the purpose of reading the shared memory in parallel to writing to and possible growing the single buffer, in this case, to stream audio in "real-time" using AudioWorklet, and finally flush the buffer once the stream closes.

Is this possible using the code in this repository?

Additional details

See https://github.com/WebAudio/web-audio-api-v2/issues/5#issuecomment-673831406

CentOS 7 compilation error.

It`s unable to compile in centos.

config.status: executing libtool commands
/bin/sh /var/web/rust/php-ext-wasm/extension/libtool --mode=compile   -I. -I/var/web/rust/php-ext-wasm/extension -DPHP_ATOM_INC -I/var/web/rust/php-ext-wasm/extension/include -I/var/web/rust/php-ext-wasm/extension/main -I/var/web/rust/php-ext-wasm/extension -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H     -c /var/web/rust/php-ext-wasm/extension/wasm.cc -o wasm.lo
libtool: compile: unrecognized option `-I.'
libtool: compile: Try `libtool --help' for more information.
make: *** [wasm.lo] Error 1

Capabilities of wasm?

Hi, I have a quick question. Is it possible to implement new language construct for php via wasm, say I want to write a jsx like preprocessor that can return xml like syntax from a method or function body directly in the php file.

Does wasm provides same level capability with php or zend extensions? If I understood correctly, wasm modules can be an be packaged with Composer and does not require additional step like zend extensions, which makes it perfect for distribution. Thanks.

Edit: A WebAssembly binary has no access to the PHP environment (so no access to its memory or functions). It is executed in a sandbox.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.