rust-lang / rust-lang/rust-playground

Client-side interactive terminal for WASM

Open
#374 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
1.4k
Forks
267
Avg merge
3h 2m
Merged PRs (30d)
6

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed wasm32-unknown-unknown target, wasm-bindgen integration, and browser-side loading flow described in the issue. Done means a minimal browser terminal can run the user's Rust WASM code, accept input, and display output through the provided print function, with diagnostics for the required main function and extern declaration.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust, wasm
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.