Skip to content

Client-side interactive terminal for WASM #374

Open
@peterjoel

Description

@peterjoel

It would be cool to be able to write Rust code for a WASM target and then execute it immediately within the web browser. A simple terminal could be made which supports calling methods and viewing the output.

Some background from Lukas Kalbertodt:
https://chat.stackoverflow.com/transcript/message/43471308#43471308

Regarding WASM. I think the way to go is certainly wasm32-unknown-unknown. And I think wasm-bindgen is also the way to go. As you already said, a super minimal terminal is already enough. You certainly wouldn't let the wasm thing access everything on the playground. So the only thing you (as the environment) need to provide is a print(&str) function.
The user can (and is reminded to do so) add a #[wasm_bindgen] extern { fn print(&str); } to their code.
Since we're talking about wasm32-unknown-unknown, the crate is compiled as library anyway. So the playground can decide how the main function would look like. So you could require that there is a global fn main(input: String) or something like that. You would call that function with something the user typed in a text box. Just as minimal example.
So it would require some integration with wasm-bindgen, some good diagnostic for telling the user about how the main() should look and that they should add this extern { print } block. Some JS code to load the wasm file from the server. But apart from that, I think this should absolutely be possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething new the playground could dohelp wantedNot immediately going to be prioritized — ask for mentoring instructions!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions