Skip to content

Commit 2968982

Browse files
committed
Change README portion for compiling wasm
1 parent 877206d commit 2968982

File tree

2 files changed

+40
-4390
lines changed

2 files changed

+40
-4390
lines changed

README.md

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RustPython
2-
A Python-3 (CPython >= 3.5.0) Interpreter written in Rust :snake: :scream: :metal:.
2+
3+
A Python-3 (CPython >= 3.5.0) Interpreter written in Rust :snake: :scream: :metal:.
34

45
[![Build Status](https://travis-ci.org/RustPython/RustPython.svg?branch=master)](https://travis-ci.org/RustPython/RustPython)
56
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
@@ -24,7 +25,6 @@ Or use the interactive shell:
2425
>>>>> 2+2
2526
4
2627

27-
2828
# Goals
2929

3030
- Full Python-3 environment entirely in Rust (not CPython bindings)
@@ -51,13 +51,13 @@ If you wish to update the online documentation. Push directly to the `release` b
5151

5252
- `parser/src`: python lexing, parsing and ast
5353
- `vm/src`: python virtual machine
54-
- `builtins.rs`: Builtin functions
55-
- `compile.rs`: the python compiler from ast to bytecode
56-
- `obj`: python builtin types
54+
- `builtins.rs`: Builtin functions
55+
- `compile.rs`: the python compiler from ast to bytecode
56+
- `obj`: python builtin types
5757
- `src`: using the other subcrates to bring rustpython to life.
5858
- `docs`: documentation (work in progress)
5959
- `py_code_object`: CPython bytecode to rustpython bytecode convertor (work in progress)
60-
- `wasm`: Binary crate and resources for WebAssembly build
60+
- `wasm`: Binary crate and resources for WebAssembly build
6161
- `tests`: integration test snippets
6262

6363
# Contributing
@@ -68,7 +68,7 @@ Most tasks are listed in the [issue tracker](https://github.com/RustPython/RustP
6868
Check issues labeled with `good first issue` if you wish to start coding.
6969

7070
Another approach is to checkout the sourcecode: builtin functions and object methods are often the simplest
71-
and easiest way to contribute.
71+
and easiest way to contribute.
7272

7373
You can also simply run
7474
`cargo run tests/snippets/whats_left_to_implement.py` to assist in finding any
@@ -135,44 +135,51 @@ cd emsdk-portable/
135135

136136
## Build
137137

138-
Move into the `wasm` directory. This contains a custom library crate optimized for wasm build of RustPython.
138+
Move into the `wasm` directory. This directory contains a library crate for interop
139+
with python to rust to js and back in `wasm/lib`, the demo website found at
140+
https://rustpython.github.io/demo in `wasm/demo`, and an example of how to use
141+
the crate as a library in one's own JS app in `wasm/example`.
139142

140-
```bash
143+
```sh
141144
cd wasm
142145
```
143146

144-
For testing on a development server, you can run the `build.sh` script. For release build which generates files for deploying to a HTTP server, run `release.sh`.
145-
146-
If you don't want to use the above scripts, you can do it manually as follows:
147+
Go to the demo directory. This is the best way of seeing the changes made to either
148+
the library or the JS demo, as the `rustpython_wasm` module is set to the global
149+
JS variable `rp` on the website.
147150

148-
Run the build. This can take several minutes depending on the machine.
149-
150-
```
151-
wasm-pack build
151+
```sh
152+
cd demo
152153
```
153154

154-
Upon successful build, cd in the the `/pkg` directory and run:
155+
Now, start the webpack development server. It'll compile the crate and then
156+
the demo app. This will likely take a long time, both the wasm-pack portion and
157+
the webpack portion (from after it says "Your crate has been correctly compiled"),
158+
so be patient.
155159

160+
```sh
161+
npm run dev
156162
```
157-
npm link
158-
```
159-
160-
Now move back out into the `/app` directory. The files here have been adapted from [wasm-pack-template](https://github.com/rustwasm/wasm-pack-template).
161163

162-
Finally, run:
163-
164-
```
165-
npm install
166-
npm link rustpython_wasm
164+
You can now open the webpage on https://localhost:8080 and Python code in either
165+
the text box or browser devtools with:
166+
167+
```js
168+
rp.pyEval(
169+
`
170+
print(js_vars['a'] * 9)
171+
`,
172+
{
173+
vars: {
174+
a: 9
175+
}
176+
}
177+
);
167178
```
168179

169-
and you will be able to run the files with:
170-
171-
```
172-
node_modules/.bin/webpack-dev-server
173-
```
174-
175-
Now open the webpage on https://localhost:8080, you'll be able to run Python code in the text box.
180+
Alternatively, you can run `npm run build` to build the app once, without watching
181+
for changes, or `npm run dist` to build the app in release mode, both for the
182+
crate and webpack.
176183

177184
# Code style
178185

@@ -195,4 +202,3 @@ These are some useful links to related projects:
195202
- https://github.com/ProgVal/pythonvm-rust
196203
- https://github.com/shinglyu/RustPython
197204
- https://github.com/windelbouwman/rspython
198-

0 commit comments

Comments
 (0)