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

Add a method to Linker and flag to wasmtime-cli to trap unknown import funcs #4312

Merged
merged 2 commits into from
Jun 27, 2022

Conversation

pchickey
Copy link
Contributor

Sometimes users have a Command module which imports functions unknown to
the wasmtime-cli, but does not call them at runtime. This PR provides a
convenience method on Linker to define all unknown import functions in
a given Module as a trivial implementation which traps, and hooks this
up to a new cli flag --trap-unknown-imports.

…t funcs

Sometimes users have a Command module which imports functions unknown to
the wasmtime-cli, but does not call them at runtime. This PR provides a
convenience method on Linker to define all unknown import functions in
a given Module as a trivial implementation which traps, and hooks this
up to a new cli flag --trap-unknown-imports.
@pchickey pchickey requested a review from alexcrichton June 23, 2022 23:45
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jun 23, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton
Copy link
Member

Seems reasonable to me! Could the implementation of this though live in the wasmtime-cli crate rather than the Linker type itself? It feels kinda CLI-specific for now and we can always move it over later if others find it useful.

@jameysharp
Copy link
Contributor

I was just thinking it'd be nice to have exactly this functionality available on the linker. I think it's useful for building custom test environments that exercise things like C@E SDKs, where there may be a lot of imports that can't be statically shown to be unused but which aren't actually called dynamically. We don't currently plan to build such environments so this isn't a strong argument in favor of exposing this feature on the linker, but my guess is it would be useful to other people too.

@pepyakin
Copy link
Contributor

As a data point, in Substrate, we implement the same functionality. Link 1 Link 2

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

That all sounds reasonable to me! In that case let's leave it on Linker.

@alexcrichton alexcrichton merged commit 84a43d8 into main Jun 27, 2022
@alexcrichton alexcrichton deleted the pch/trap_unknown_imports branch June 27, 2022 13:55
afonso360 pushed a commit to afonso360/wasmtime that referenced this pull request Jun 30, 2022
…t funcs (bytecodealliance#4312)

* Add a method to Linker and flag to wasmtime-cli to trap unknown import funcs

Sometimes users have a Command module which imports functions unknown to
the wasmtime-cli, but does not call them at runtime. This PR provides a
convenience method on Linker to define all unknown import functions in
a given Module as a trivial implementation which traps, and hooks this
up to a new cli flag --trap-unknown-imports.

* add cfg guards - func_new requires compiler (naturally)
langyo added a commit to langyo/gloo that referenced this pull request Dec 6, 2023
langyo added a commit to langyo/yew that referenced this pull request Dec 6, 2023
ranile pushed a commit to rustwasm/gloo that referenced this pull request Dec 6, 2023
* feat: Support WASI target.

* fix: More friendly error message for wasi target.

* fix: Use target_os instead of feature.

* feat: Add an example for gloo-history on WASI.

* fix: Avoid to use web-sys when target os is WASI.

* fix: Exclude WASI example to avoid web-sys.

* ci: Use static download instead of install bash.

* ci: Use CLI's flag instead of exclude example.
bytecodealliance/wasmtime#4312
langyo added a commit to langyo/gloo that referenced this pull request Dec 10, 2023
ranile added a commit to yewstack/yew that referenced this pull request Oct 21, 2024
* Try to add wasi feature to avoid browser's ABI.

* Add async render for single-threaded env.

* Temporarily enable my own patch branch.
It would be modified later
after the corresponding library branches are merged.

* add example for WASI SSR.

* Ready to run WASI on wasmtime.

* complete the example

* fix fmt

* fix fmt

* I made a mistake..sry

* add yew-router suites for demo

* fix typo

* Make the async render stream function public

* Use target_os instead of feature.

* Renew gloo-history's patch.

* Exclude WASI example to avoid web-sys.

* Try to add CI for WASI example.

* Fix CI.

* Fix CI that requires compiler 1.67 or newer.

* Use CLI's flag instead of exclude example.
bytecodealliance/wasmtime#4312

* Remove patchs.

* Use LocalServerRenderer instead of ServerRenderer.
yewstack/tokise#11 (comment)

* Remove unused exports.

* Add description about `LocalServerRenderer`.

* fix fmt

* fix fmt

* Update Cargo.lock

* Bump rust compiler's version to 1.67...

* Exclude WASI on yew-router browser interfaces.

* fix fmt

* Wait for gloo's PR dealed.

* Rollback to rust compiler 1.64.
cc rustwasm/gloo#423 (comment)

* Fix lock file.

* Downgrade `toml_datetime` version.

* Fix enum for `gloo-history`.

* Well, it seems there is no way to avoid the MSRV upgrade....

* fix: Replace feature = "wasi" to target_os = "wasi".

* Remove tips for rust version.

* Bump `gloo` to 0.11.

* Try to test yew-macro on compiler 1.67.

* Try to use compiler 1.68 instead.

* Try to use compiler 1.69 instead......

* Revert MSRV back

* Pin the oldest Cargo.lock.

* Downgrade deps for MSRV.

* Bump benchmark tool's tokio to 1.35

* Try to write WASI CI.

* Rollback the quotes

* Combine CI files...

* Rollback the use that gloo-history has fixed it.

* fix

* Bump gloo-history version.

* Block raw html update tests on WASI.

* Rollback indexmap's version.

* fix CI

* fix CI

* Update some SSR test suites that replace ServerRender instead of LocalServerRender.

* Remove yew-router's cfg macro

* Fix fmt

* Try to fix CI

* Update examples/wasi_ssr_module/README.md

Co-authored-by: Elina <imelina@elina.website>

* Revert back some unnecessary changes.

* Clippy

* fmt

* Fix CI.

* Fix CI.

* Try to fix clippy.

* Fix `ToString` trait.

* Remove pin version of WASI CI test.

* Pin the newer version.

* Fix typo.

* Bump `wasm-bindgen`.

* Fix SSR example.

* Fix typo.

* Try to support non-browser environments.

* Update wasm-bindgen-test to 0.3.43

refer to rustwasm/wasm-bindgen#4083

* fix doc test running on nightly

* Update website/docs/advanced-topics/server-side-rendering.md

Co-authored-by: WorldSEnder <WorldSEnder@users.noreply.github.com>

* Update WASI CI.

* Remove WASI test for rustc 1.76.

* Try to let `wasmtime` CLI can be executed.

* Limit the function `decode_base64` that it shouldn't runnable in non-browser environment.

* Remove WASI example test for rustc 1.76.

* Revert changes.

* Fix CI

* Fix Cargo.lock

* Remove unused deps

* Undo the formatting changes.

* Undo the formatting changes.

---------

Co-authored-by: Elina <imelina@elina.website>
Co-authored-by: Martin Molzer <WorldSEnder@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants