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

feat(runtime-c-api) Ability to generate ImportObject for a specific WASI version #1030

Merged
merged 16 commits into from
Dec 6, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Dec 2, 2019

❗️⚠️ Contains #1028, must be merged before this one.

This patch introduces 2 new functions:

  • wasmer_wasi_generate_import_object_for_version and
  • wasmer_wasi_get_version.

It mimics the current API provided by wasmer_wasi, nothing fancy
here. It's just a regular port to C/C++.

Because wasmer_wasi::get_wasi_version returns an option, and in
order to simplify the C/C++ API, wasmer_wasi_get_version can return
Version::Unknown in case of an error. It's up to the user to check
the version is valid (i.e. not unknown).

To see only the changes provided by this PR (excluding #1028), check Hywan/wasmer@fix-wasi-get-version...feat-runtime-c-api-wasi-version.

@Hywan Hywan added 🎉 enhancement New feature! 📦 lib-c-api About wasmer-c-api 🧪 tests I love tests labels Dec 2, 2019
Hywan added a commit to Hywan/wasmer that referenced this pull request Dec 2, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Dec 2, 2019

bors try

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, though see my feedback on #1028 ; I think we should probably add a new method if we want to do fuzzy matching on module's import signatures

lib/runtime-c-api/src/import/wasi.rs Outdated Show resolved Hide resolved
lib/runtime-c-api/src/import/wasi.rs Outdated Show resolved Hide resolved
bors bot added a commit that referenced this pull request Dec 3, 2019
@bors
Copy link
Contributor

bors bot commented Dec 3, 2019

try

Build succeeded

Hywan added a commit to Hywan/wasmer that referenced this pull request Dec 4, 2019
@Hywan Hywan force-pushed the feat-runtime-c-api-wasi-version branch 2 times, most recently from 639c81a to b9679eb Compare December 4, 2019 13:42
Hywan added a commit to Hywan/go-ext-wasm that referenced this pull request Dec 4, 2019
Hywan added 14 commits December 4, 2019 15:28
… WASI version.

This patch introduces 2 new functions:

* `wasmer_wasi_generate_import_object_for_version` and
* `wasmer_wasi_get_version`.

It mimics the current API provided by `wasmer_wasi`, nothing fancy
here. It's just a regular port to C/C++.

Because `wasmer_wasi::get_wasi_version` returns an option, and in
order to simplify the C/C++ API, `wasmer_wasi_get_version` can return
`Version::Unknown` in case of an error. It's up to the user to check
the version is valid (i.e. not unknown).
This patch updates `test-wasi-import-object` to test the new
`wasmer_wasi_get_version` &
`wasmer_wasi_generate_import_object_for_version` functions, and the
new `Version` type.
When the version has type `Version`, we expect the user to give a
valid `Version` variant. Since the `Version` is basically a `uint8_t`,
the user is able to pass everything she wants, which can create an
undefined behavior on the Rust side.

To avoid such situation, the version has now type `c_uchar` (`unsigned
char` or `uint8_t` on C side —on most platforms). Then the `From`
trait is implemented on `Version`. In case the value is unbound,
`Version::Unknown` is returned.
0 matches to `Unknown`, 1 matches to `Snapshot0` and 2 matches to
`Snapshot1`.
@Hywan
Copy link
Contributor Author

Hywan commented Dec 6, 2019

bors r+

bors bot added a commit that referenced this pull request Dec 6, 2019
1030: feat(runtime-c-api) Ability to generate `ImportObject` for a specific WASI version r=Hywan a=Hywan

❗️⚠️ Contains #1028, must be merged before this one.

This patch introduces 2 new functions:

* `wasmer_wasi_generate_import_object_for_version` and
* `wasmer_wasi_get_version`.

It mimics the current API provided by `wasmer_wasi`, nothing fancy
here. It's just a regular port to C/C++.

Because `wasmer_wasi::get_wasi_version` returns an option, and in
order to simplify the C/C++ API, `wasmer_wasi_get_version` can return
`Version::Unknown` in case of an error. It's up to the user to check
the version is valid (i.e. not unknown).

To see only the changes provided by this PR (excluding #1028), check Hywan/wasmer@fix-wasi-get-version...feat-runtime-c-api-wasi-version.

Co-authored-by: Ivan Enderlin <[email protected]>
@bors
Copy link
Contributor

bors bot commented Dec 6, 2019

Build succeeded

@bors bors bot merged commit 45e4081 into wasmerio:master Dec 6, 2019
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 7, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <[email protected]>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 8, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <[email protected]>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 15, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! 📦 lib-c-api About wasmer-c-api 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants