Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad0f8dd

Browse files
committed
Readme changes for compliation with wasm-pack
1 parent27b5796 commitad0f8dd

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

‎README.md‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ $ cargo test --all
6666

6767
#Compiling to WebAssembly
6868

69+
At this stage RustPython only has preliminary support for web assembly. The instructions here are intended for developers or those wishing to run a toy example.
70+
6971
##Setup
7072

71-
Using`rustup` add the compile target`wasm32-unknown-emscripten`. To do so you will need to have[rustup](https://rustup.rs/) installed.
73+
To get started, install[wasm-bingden](https://rustwasm.github.io/wasm-bindgen/whirlwind-tour/basic-usage.html)
74+
and[wasm-webpack](https://rustwasm.github.io/wasm-pack/installer/). You will also need to have`npm` installed.
75+
76+
<!-- Using `rustup` add the compile target `wasm32-unknown-emscripten`. To do so you will need to have [rustup](https://rustup.rs/) installed.
7277
7378
```bash
7479
rustup target add wasm32-unknown-emscripten
@@ -82,41 +87,58 @@ cd emsdk-portable/
8287
./emsdk update
8388
./emsdk install sdk-incoming-64bit
8489
./emsdk activate sdk-incoming-64bit
85-
source ./emsdk_env.sh
86-
```
90+
```-->
91+
92+
8793

8894
##Build
8995

90-
Move into the`wasm` directory. This contains a custombinary crate optimized fora web assembly build.
96+
Move into the`wasm` directory. This contains a customlibrary crate optimized forwasm build of RustPython.
9197

9298
```bash
9399
cd wasm
94100
```
95101

96102
From here run the build. This can take several minutes depending on the machine.
103+
104+
```
105+
wasm-pack build
106+
```
107+
108+
Upon successful build, cd in the the`/pkg` directory and run:
109+
97110
```
98-
cargo build --target=wasm32-unknown-emscripten --release
111+
npm link
99112
```
100113

101-
Upon successful build,thefollowingfileswill be available:
114+
Now move back out intothe`/app` directory. Thefileshere have been adapted from[wasm-pack-template](https://github.com/rustwasm/wasm-pack-template).
102115

116+
Finally, run:
103117

104118
```
105-
target/wasm32-unknown-emscripten/release/rustpython_wasm.wasm
106-
target/wasm32-unknown-emscripten/release/rustpython_wasm.js
119+
npm install
107120
```
108121

109-
-`rustpython_wasm.wasm`: the wasm build for rustpython. It includes both an parser and virtual machine.
110-
-`rustpython_wasm.js`: the loading scripts for the above wasm file.
122+
and you will be able to run the files with:
123+
124+
```
125+
webpack-dev-server
126+
```
111127

112-
You will also find`index.html` in the`wasm` directory.
113-
From here, you can copy these 3 files into the static assets directory of your web server and you should be
114-
able to see the ouput in the web console of your browser.
128+
Open a browser console and see the output of rustpython_wasm. To verify this, modify the line in`app/index.js`
115129

130+
```js
131+
rp.run_code("print('Hello Python!')\n");
116132
```
117-
Hello RustPython!
133+
134+
To the following:
135+
136+
```js
137+
rp.run_code("assert(False)\n");
118138
```
119139

140+
and you should observe:`Execution failed` in your console output, indicating that the execution of RustPython has failed.
141+
120142
#Code style
121143

122144
The code style used is the default rustfmt codestyle. Please format your code accordingly.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp