Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib"]

[dependencies]
cargo-php = "0.1.7"
ext-php-rs = "0.10.1"
ext-php-rs = {version = "0.10.1", features = ["closure"] }
wasmer = { version = "4.1.0", default-features = true, features = ["sys"] }
wasmer-compiler = "4.1.0"

Expand Down
2 changes: 1 addition & 1 deletion ext-wasm.stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __set(string $accessor, mixed $value): void {}
class InstanceBuilder {
public static function fromWat(string $wat): \Wasm\InstanceBuilder {}

public function import(array $imports): void {}
public function import(Imports $imports): void {}

public function build(): \Wasm\WasmInstance {}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/ImportsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ public function test_it_imports_simple_globals() {
self::assertSame([32], $instance->read_g());
}


public function test_it_can_call_external_function() {
$result = (object)['current' => false];

$imports = Imports::create();
$imports->define('env', 'greet', Type\Global::immutable(
function () use ($result) {
$result->current = true;
}
));

$builder = $this->createBuilderFromWat(
<<<'EOWAT'
(module
(import "env" "greet" (func $greet))
(func
call $greet
)
(start 1) ;; run the first function automatically
)
EOWAT
);


$builder->import($imports);
$instance = $builder->build();

self::assertTrue($result->current);
}

private function createBuilderFromWat(?string $wat = null): InstanceBuilder
{
return InstanceBuilder::fromWat($wat ?? <<<'EOWAT'
Expand Down