wasmerio / wasmer-php

🐘🕸️ WebAssembly runtime for PHP
https://wasmerio.github.io/wasmer-php/wasm/
MIT License
1.01k stars 42 forks source link

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

Closed beatscode closed 5 years ago

beatscode commented 5 years ago

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
Hywan commented 5 years ago

It is possible to load a Wasm module representing a Go program, yes.

What code generates your error?

beatscode commented 5 years ago

I ran composer to import "php-wasm/php-wasm": "^0.5.0"

when I try to run

$instance = new Wasm\Instance(__DIR__ . '/wasm.wasm');
    var_dump(
        $instance->multiply(5, 37)
    );

I get the error described above.

The go code is the following

package main

func main(){

}

func multiply(x,y int) int {
    return x * y;
}

I used tinygo to build maybe that is the issue? /usr/local/tinygo build -o wasm.wasm -target wasm ./main.go

Hywan commented 5 years ago

Did you include the vendor/autoload.php?

beatscode commented 5 years ago

My mistake, didn't compile extension properly