Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

playground crate, basic WASM/TS setup #14

Merged
merged 42 commits into from
Oct 7, 2021
Merged

playground crate, basic WASM/TS setup #14

merged 42 commits into from
Oct 7, 2021

Conversation

achimcc
Copy link
Contributor

@achimcc achimcc commented Sep 21, 2021

Introduction

The ink Playground runs Rust Analyzer in the Browser. To do this, we need to compile certain Rust Analyzer Crates to WebAssembly to make them available in the Browser. This PR adds a new Crate playground to the repo which intends to serve this feature in future iterations. We provide with this PR the basic required tools and components for the desired setup, together with the corresponding testing frameworks and CI configurations.

Usage

To test this PR, you need to install wasm-pack together with the required nightly toolchain, cd into the crate directory and run yarn start:

curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

rustup component add rust-src --toolchain nightly-2021-07-29-x86_64-unknown-linux-gnu

cd crates/playground

yarn start

Used components/packages

On the Rust side of the playground crate:

  • wasm-pack for creating a hybrid rust/typescript application

  • wasm-bindgen to allow JavaScript bindings for the Rust/WASM fucntions

  • rayon for multithreading

  • wasm-bindgen-rayon allows to access the multithreading functionalieties from within the browser

On the TypeScript side:

  • wasm-pack-plugin takes care of executing wasm-pack build commands when running yarn build. It also provides watch script functionalities when running yarn start end, when editing the rust source-code, it then re-compiles it to WebAssembly

  • comlink reduces the complexity in handling WebWorkers, especially the WebWorkers which are providing the Rust Analyzer functionalities

Code structure

There are two directories containing source-code in this crate:

  • src contains the Rust code which gets compiled to WebAssembly

  • js contains the JS/TS code which serves the Frontend app. It references the pkg directory to which the Rust code from the src directory gets compiled to p[rovide the WebAssembly Webworkers through the Comlink plugin.

Currently the App does one call to a Webworker which invokes the evaluation of a WebAssembly function greet(), which is provided by the compiled Rust code. It is only added to test the interaction between the different WASM/TS tools of this crate.

The package provides unit testing with jest and React testing library and unit testing of the Wasm part by wasm-pack test. It contains the WebAssembly tests in the tests dir, while the tests executed by jest are located under js/__tests__. We configured yarn in a way such that running yarn test is running both the WebAssembly and the jest tests.

We configured the CI in a way such that it runs all the provided tests in this crate and installs the required tooling and toolchain first.

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

The project name is "ink!" (with the exclamation mark). Could you replace other occurrences of the name without ! as well? For example in the repo readme.

crates/playground/js/Welcome.tsx Outdated Show resolved Hide resolved
crates/playground/js/__tests__/Welcome.test.tsx Outdated Show resolved Hide resolved
crates/playground/js/index.html Outdated Show resolved Hide resolved
crates/playground/package.json Outdated Show resolved Hide resolved
crates/playground/tests/web.rs Outdated Show resolved Hide resolved
crates/playground/js/Wasm.tsx Outdated Show resolved Hide resolved
Co-authored-by: Michael Müller <michi@parity.io>
achimcc and others added 5 commits September 25, 2021 09:47
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Copy link
Contributor

@thought2 thought2 left a comment

Choose a reason for hiding this comment

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

lgtm! just the small things that I comment we should discuss...

crates/change_json/LICENSE Show resolved Hide resolved
crates/playground/.travis.yml Outdated Show resolved Hide resolved
crates/playground/README.md Outdated Show resolved Hide resolved
crates/playground/js/Wasm.tsx Outdated Show resolved Hide resolved
crates/playground/js/Wasm.tsx Outdated Show resolved Hide resolved
crates/playground/js/Wasm.tsx Outdated Show resolved Hide resolved
crates/playground/setupTests.ts Outdated Show resolved Hide resolved
crates/playground/tsconfig.bak Outdated Show resolved Hide resolved
.github/workflows/wasm_ts.yml Show resolved Hide resolved
@thought2 thought2 requested review from cmichi and removed request for cmichi October 7, 2021 07:25
@achimcc achimcc merged commit d2520d8 into main Oct 7, 2021
@achimcc achimcc deleted the wasm branch October 7, 2021 07:26
nmauersberg added a commit to nmauersberg/ink-playground that referenced this pull request Oct 7, 2021
Was not applied because of changed paths
@achimcc achimcc linked an issue Oct 7, 2021 that may be closed by this pull request
7 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initiate a new wasm Project
3 participants