Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure the namespace of the imports functions #25

Closed
YaronWittenstein opened this issue Jun 4, 2019 · 3 comments · Fixed by #29
Closed

Configure the namespace of the imports functions #25

YaronWittenstein opened this issue Jun 4, 2019 · 3 comments · Fixed by #29
Assignees
Labels
📦 component-extension About the Go extension 🎉 enhancement New feature or request

Comments

@YaronWittenstein
Copy link

Currently, the NewImports() hard-codes the import namespace as env.

If we compile a Rust program to WASM file, then the Rust compiler also hardcodes the
import namespace as env too (so the current wasmer go binding the Rust wasm output files play well together)

However, if we patch a wasm file import namespace to something else (different than env), then we won't be able to use it via the golang wasmer binding

Proposed solution

Instead of

imports, _ := wasm.NewImports().Append("sum", sum, C.sum)

Have this API:

imports, _ := wasm.NewImports().Append("my_namespace",  "sum", sum, C.sum)

Thank you! @Hywan :)

@YaronWittenstein YaronWittenstein added the 🎉 enhancement New feature or request label Jun 4, 2019
@YaronWittenstein YaronWittenstein changed the title Configure the namespace of the imported function Configure the namespace of the imports functions Jun 4, 2019
@Hywan Hywan self-assigned this Jun 4, 2019
@Hywan Hywan added the 📦 component-runtime About the Wasm runtime label Jun 4, 2019
@Hywan
Copy link
Contributor

Hywan commented Jun 4, 2019

Thanks for the proposal!

What do you think about this API:

wasm.NewImports().
    Namespace("env").
        Append("sum", sum, C.sum).
        Append("f", f, C.f).
    Namespace("wasi").
        Append("log", log, C.log)

Would you like it? It's more like a tree. Append uses the last defined Namespace.

@YaronWittenstein
Copy link
Author

YaronWittenstein commented Jun 4, 2019

@Hywan that's even better!
It makes more sense since usually, all the imports will be for 1-2 namespaces while the number of functions will be much bigger)

I guess the default namespace will be env

@Hywan
Copy link
Contributor

Hywan commented Jun 4, 2019

Correct, env will be the default namespace.

@Hywan Hywan added 📦 component-extension About the Go extension and removed 📦 component-runtime About the Wasm runtime labels Jun 4, 2019
bors bot added a commit that referenced this issue Jun 4, 2019
29: feat(import) Add `Imports.Namespace` to set the current import namespace r=Hywan a=Hywan

Fix #25.

Basically, this patch allows to define imported function in any
namepace. The `Imports.Namespace` sets the current namespce for the
next defined imported functions:

```go
wasm.NewImports().Namespace("ns").Append("f", f, C.f)
```

By default, the namespace is `env`, so both statements are identical:

```go
wasm.NewImports().Namespace("env").Append(…)
wasm.NewImports().Append(…)
```

To register imported functions in different namespaces, one writes:

```go
wasm.NewImports().Namespace("ns1").Append(…).Append(…).Namespace("ns2").Append(…).Append(…)…
```

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors bors bot closed this as completed in #29 Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-extension About the Go extension 🎉 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants