Skip to content

Commit f117406

Browse files
authored
[examples/raytrace-parallel] Replace Bash with Python for Windows compatibility (#3603)
1 parent 18b1d9f commit f117406

File tree

14 files changed

+143
-51
lines changed

14 files changed

+143
-51
lines changed

examples/raytrace-parallel/.gitignore

-2
This file was deleted.

examples/raytrace-parallel/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ online][compiled]
99
You can build the example locally with:
1010

1111
```
12-
$ ./run.sh
12+
$ python3 run.py
1313
```
1414

15-
(or running the commands on Windows manually)
16-
17-
and then visiting http://localhost:8080 in a browser should run the example!
15+
and then visiting http://localhost:8000 in a browser should run the example!

examples/raytrace-parallel/build.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import subprocess
4+
5+
root_dir = os.path.dirname(__file__)
6+
7+
# A couple of steps are necessary to get this build working which makes it slightly
8+
# nonstandard compared to most other builds.
9+
#
10+
# * First, the Rust standard library needs to be recompiled with atomics
11+
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
12+
#
13+
# * Next we need to compile everything with the `atomics` and `bulk-memory`
14+
# features enabled, ensuring that LLVM will generate atomic instructions,
15+
# shared memory, passive segments, etc.
16+
17+
os.environ.update(
18+
{"RUSTFLAGS": "-C target-feature=+atomics,+bulk-memory,+mutable-globals"}
19+
)
20+
21+
subprocess.run(
22+
[
23+
"cargo",
24+
"build",
25+
"--target",
26+
"wasm32-unknown-unknown",
27+
"--release",
28+
"-Zbuild-std=std,panic_abort",
29+
],
30+
cwd=root_dir,
31+
).check_returncode()
32+
33+
# Note the usage of `--target no-modules` here which is required for passing
34+
# the memory import to each wasm module.
35+
subprocess.run(
36+
[
37+
"cargo",
38+
"run",
39+
"-p",
40+
"wasm-bindgen-cli",
41+
"--",
42+
os.path.join(
43+
root_dir,
44+
"..",
45+
"..",
46+
"target",
47+
"wasm32-unknown-unknown",
48+
"release",
49+
"raytrace_parallel.wasm",
50+
),
51+
"--out-dir",
52+
os.path.join(root_dir, "pkg"),
53+
"--target",
54+
"no-modules",
55+
],
56+
cwd=root_dir,
57+
).check_returncode()

examples/raytrace-parallel/build.sh

+1-19
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,4 @@
22

33
set -ex
44

5-
# A couple of steps are necessary to get this build working which makes it slightly
6-
# nonstandard compared to most other builds.
7-
#
8-
# * First, the Rust standard library needs to be recompiled with atomics
9-
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
10-
#
11-
# * Next we need to compile everything with the `atomics` and `bulk-memory`
12-
# features enabled, ensuring that LLVM will generate atomic instructions,
13-
# shared memory, passive segments, etc.
14-
15-
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
16-
cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
17-
18-
# Note the usage of `--target no-modules` here which is required for passing
19-
# the memory import to each wasm module.
20-
cargo run -p wasm-bindgen-cli -- \
21-
../../target/wasm32-unknown-unknown/release/raytrace_parallel.wasm \
22-
--out-dir . \
23-
--target no-modules
5+
python3 build.py

examples/raytrace-parallel/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
document.getElementById('render').disabled = true;
220220
document.getElementById('concurrency').disabled = true;
221221
</script>
222-
<script src='raytrace_parallel.js'></script>
222+
<script src='pkg/raytrace_parallel.js'></script>
223223
<script src='index.js'></script>
224224
</body>
225225
</html>

examples/raytrace-parallel/run.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import subprocess
4+
5+
root_dir = os.path.dirname(__file__)
6+
7+
subprocess.run(["python3", "build.py"], cwd=root_dir).check_returncode()
8+
9+
subprocess.run(["python3", "server.py"], cwd=root_dir).check_returncode()

examples/raytrace-parallel/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -ex
44

5-
./build.sh
5+
python3 build.py
66

77
python3 server.py

examples/raytrace-parallel/worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// synchronously, using the browser, import out shim JS scripts
2-
importScripts('raytrace_parallel.js');
2+
importScripts('pkg/raytrace_parallel.js');
33

44
// Wait for the main thread to send us the shared module/memory. Once we've got
55
// it, initialize it all with the `wasm_bindgen` global we imported via

examples/wasm-audio-worklet/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ online][compiled]
99
You can build the example locally with:
1010

1111
```
12-
$ ./run.sh
12+
$ python3 run.py
1313
```
1414

15-
(or running the commands on Windows manually)
16-
1715
and then visiting http://localhost:8080 in a browser should run the example!

examples/wasm-audio-worklet/build.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import subprocess
4+
5+
root_dir = os.path.dirname(__file__)
6+
7+
# A couple of steps are necessary to get this build working which makes it slightly
8+
# nonstandard compared to most other builds.
9+
#
10+
# * First, the Rust standard library needs to be recompiled with atomics
11+
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
12+
#
13+
# * Next we need to compile everything with the `atomics` and `bulk-memory`
14+
# features enabled, ensuring that LLVM will generate atomic instructions,
15+
# shared memory, passive segments, etc.
16+
17+
os.environ.update(
18+
{"RUSTFLAGS": "-C target-feature=+atomics,+bulk-memory,+mutable-globals"}
19+
)
20+
21+
subprocess.run(
22+
[
23+
"cargo",
24+
"build",
25+
"--target",
26+
"wasm32-unknown-unknown",
27+
"--release",
28+
"-Zbuild-std=std,panic_abort",
29+
],
30+
cwd=root_dir,
31+
).check_returncode()
32+
33+
# Note the usage of `--target no-modules` here which is required for passing
34+
# the memory import to each wasm module.
35+
subprocess.run(
36+
[
37+
"cargo",
38+
"run",
39+
"-p",
40+
"wasm-bindgen-cli",
41+
"--",
42+
os.path.join(
43+
root_dir,
44+
"..",
45+
"..",
46+
"target",
47+
"wasm32-unknown-unknown",
48+
"release",
49+
"wasm_audio_worklet.wasm",
50+
),
51+
"--out-dir",
52+
os.path.join(root_dir, "pkg"),
53+
"--target",
54+
"web",
55+
"--split-linked-modules",
56+
],
57+
cwd=root_dir,
58+
).check_returncode()

examples/wasm-audio-worklet/build.sh

+1-18
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,4 @@
22

33
set -ex
44

5-
# A couple of steps are necessary to get this build working which makes it slightly
6-
# nonstandard compared to most other builds.
7-
#
8-
# * First, the Rust standard library needs to be recompiled with atomics
9-
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
10-
#
11-
# * Next we need to compile everything with the `atomics` and `bulk-memory`
12-
# features enabled, ensuring that LLVM will generate atomic instructions,
13-
# shared memory, passive segments, etc.
14-
15-
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
16-
cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
17-
18-
cargo run -p wasm-bindgen-cli -- \
19-
../../target/wasm32-unknown-unknown/release/wasm_audio_worklet.wasm \
20-
--out-dir . \
21-
--target web \
22-
--split-linked-modules
5+
python3 build.py

examples/wasm-audio-worklet/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body>
77
<script type="module">
8-
import init, {web_main} from "./wasm_audio_worklet.js";
8+
import init, {web_main} from "./pkg/wasm_audio_worklet.js";
99
async function run() {
1010
await init();
1111
web_main();

examples/wasm-audio-worklet/run.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import subprocess
4+
5+
root_dir = os.path.dirname(__file__)
6+
7+
subprocess.run(["python3", "build.py"], cwd=root_dir).check_returncode()
8+
9+
subprocess.run(["python3", "server.py"], cwd=root_dir).check_returncode()

examples/wasm-audio-worklet/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -ex
44

5-
./build.sh
5+
python3 build.py
66

77
python3 server.py

0 commit comments

Comments
 (0)