mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-10 23:26:52 +03:00
[examples/raytrace-parallel] Replace Bash with Python for Windows compatibility (#3603)
This commit is contained in:
parent
18b1d9f292
commit
f117406532
2
examples/raytrace-parallel/.gitignore
vendored
2
examples/raytrace-parallel/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
raytrace_parallel.js
|
||||
raytrace_parallel_bg.wasm
|
@ -9,9 +9,7 @@ online][compiled]
|
||||
You can build the example locally with:
|
||||
|
||||
```
|
||||
$ ./run.sh
|
||||
$ python3 run.py
|
||||
```
|
||||
|
||||
(or running the commands on Windows manually)
|
||||
|
||||
and then visiting http://localhost:8080 in a browser should run the example!
|
||||
and then visiting http://localhost:8000 in a browser should run the example!
|
||||
|
57
examples/raytrace-parallel/build.py
Executable file
57
examples/raytrace-parallel/build.py
Executable file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
root_dir = os.path.dirname(__file__)
|
||||
|
||||
# A couple of steps are necessary to get this build working which makes it slightly
|
||||
# nonstandard compared to most other builds.
|
||||
#
|
||||
# * First, the Rust standard library needs to be recompiled with atomics
|
||||
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
|
||||
#
|
||||
# * Next we need to compile everything with the `atomics` and `bulk-memory`
|
||||
# features enabled, ensuring that LLVM will generate atomic instructions,
|
||||
# shared memory, passive segments, etc.
|
||||
|
||||
os.environ.update(
|
||||
{"RUSTFLAGS": "-C target-feature=+atomics,+bulk-memory,+mutable-globals"}
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"cargo",
|
||||
"build",
|
||||
"--target",
|
||||
"wasm32-unknown-unknown",
|
||||
"--release",
|
||||
"-Zbuild-std=std,panic_abort",
|
||||
],
|
||||
cwd=root_dir,
|
||||
).check_returncode()
|
||||
|
||||
# Note the usage of `--target no-modules` here which is required for passing
|
||||
# the memory import to each wasm module.
|
||||
subprocess.run(
|
||||
[
|
||||
"cargo",
|
||||
"run",
|
||||
"-p",
|
||||
"wasm-bindgen-cli",
|
||||
"--",
|
||||
os.path.join(
|
||||
root_dir,
|
||||
"..",
|
||||
"..",
|
||||
"target",
|
||||
"wasm32-unknown-unknown",
|
||||
"release",
|
||||
"raytrace_parallel.wasm",
|
||||
),
|
||||
"--out-dir",
|
||||
os.path.join(root_dir, "pkg"),
|
||||
"--target",
|
||||
"no-modules",
|
||||
],
|
||||
cwd=root_dir,
|
||||
).check_returncode()
|
@ -2,22 +2,4 @@
|
||||
|
||||
set -ex
|
||||
|
||||
# A couple of steps are necessary to get this build working which makes it slightly
|
||||
# nonstandard compared to most other builds.
|
||||
#
|
||||
# * First, the Rust standard library needs to be recompiled with atomics
|
||||
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
|
||||
#
|
||||
# * Next we need to compile everything with the `atomics` and `bulk-memory`
|
||||
# features enabled, ensuring that LLVM will generate atomic instructions,
|
||||
# shared memory, passive segments, etc.
|
||||
|
||||
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
|
||||
cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||
|
||||
# Note the usage of `--target no-modules` here which is required for passing
|
||||
# the memory import to each wasm module.
|
||||
cargo run -p wasm-bindgen-cli -- \
|
||||
../../target/wasm32-unknown-unknown/release/raytrace_parallel.wasm \
|
||||
--out-dir . \
|
||||
--target no-modules
|
||||
python3 build.py
|
||||
|
@ -219,7 +219,7 @@
|
||||
document.getElementById('render').disabled = true;
|
||||
document.getElementById('concurrency').disabled = true;
|
||||
</script>
|
||||
<script src='raytrace_parallel.js'></script>
|
||||
<script src='pkg/raytrace_parallel.js'></script>
|
||||
<script src='index.js'></script>
|
||||
</body>
|
||||
</html>
|
||||
|
9
examples/raytrace-parallel/run.py
Executable file
9
examples/raytrace-parallel/run.py
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
root_dir = os.path.dirname(__file__)
|
||||
|
||||
subprocess.run(["python3", "build.py"], cwd=root_dir).check_returncode()
|
||||
|
||||
subprocess.run(["python3", "server.py"], cwd=root_dir).check_returncode()
|
@ -2,6 +2,6 @@
|
||||
|
||||
set -ex
|
||||
|
||||
./build.sh
|
||||
python3 build.py
|
||||
|
||||
python3 server.py
|
||||
|
@ -1,5 +1,5 @@
|
||||
// synchronously, using the browser, import out shim JS scripts
|
||||
importScripts('raytrace_parallel.js');
|
||||
importScripts('pkg/raytrace_parallel.js');
|
||||
|
||||
// Wait for the main thread to send us the shared module/memory. Once we've got
|
||||
// it, initialize it all with the `wasm_bindgen` global we imported via
|
||||
|
@ -9,9 +9,7 @@ online][compiled]
|
||||
You can build the example locally with:
|
||||
|
||||
```
|
||||
$ ./run.sh
|
||||
$ python3 run.py
|
||||
```
|
||||
|
||||
(or running the commands on Windows manually)
|
||||
|
||||
and then visiting http://localhost:8080 in a browser should run the example!
|
||||
|
58
examples/wasm-audio-worklet/build.py
Normal file
58
examples/wasm-audio-worklet/build.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
root_dir = os.path.dirname(__file__)
|
||||
|
||||
# A couple of steps are necessary to get this build working which makes it slightly
|
||||
# nonstandard compared to most other builds.
|
||||
#
|
||||
# * First, the Rust standard library needs to be recompiled with atomics
|
||||
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
|
||||
#
|
||||
# * Next we need to compile everything with the `atomics` and `bulk-memory`
|
||||
# features enabled, ensuring that LLVM will generate atomic instructions,
|
||||
# shared memory, passive segments, etc.
|
||||
|
||||
os.environ.update(
|
||||
{"RUSTFLAGS": "-C target-feature=+atomics,+bulk-memory,+mutable-globals"}
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"cargo",
|
||||
"build",
|
||||
"--target",
|
||||
"wasm32-unknown-unknown",
|
||||
"--release",
|
||||
"-Zbuild-std=std,panic_abort",
|
||||
],
|
||||
cwd=root_dir,
|
||||
).check_returncode()
|
||||
|
||||
# Note the usage of `--target no-modules` here which is required for passing
|
||||
# the memory import to each wasm module.
|
||||
subprocess.run(
|
||||
[
|
||||
"cargo",
|
||||
"run",
|
||||
"-p",
|
||||
"wasm-bindgen-cli",
|
||||
"--",
|
||||
os.path.join(
|
||||
root_dir,
|
||||
"..",
|
||||
"..",
|
||||
"target",
|
||||
"wasm32-unknown-unknown",
|
||||
"release",
|
||||
"wasm_audio_worklet.wasm",
|
||||
),
|
||||
"--out-dir",
|
||||
os.path.join(root_dir, "pkg"),
|
||||
"--target",
|
||||
"web",
|
||||
"--split-linked-modules",
|
||||
],
|
||||
cwd=root_dir,
|
||||
).check_returncode()
|
@ -2,21 +2,4 @@
|
||||
|
||||
set -ex
|
||||
|
||||
# A couple of steps are necessary to get this build working which makes it slightly
|
||||
# nonstandard compared to most other builds.
|
||||
#
|
||||
# * First, the Rust standard library needs to be recompiled with atomics
|
||||
# enabled. to do that we use Cargo's unstable `-Zbuild-std` feature.
|
||||
#
|
||||
# * Next we need to compile everything with the `atomics` and `bulk-memory`
|
||||
# features enabled, ensuring that LLVM will generate atomic instructions,
|
||||
# shared memory, passive segments, etc.
|
||||
|
||||
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
|
||||
cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||
|
||||
cargo run -p wasm-bindgen-cli -- \
|
||||
../../target/wasm32-unknown-unknown/release/wasm_audio_worklet.wasm \
|
||||
--out-dir . \
|
||||
--target web \
|
||||
--split-linked-modules
|
||||
python3 build.py
|
||||
|
@ -5,7 +5,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
import init, {web_main} from "./wasm_audio_worklet.js";
|
||||
import init, {web_main} from "./pkg/wasm_audio_worklet.js";
|
||||
async function run() {
|
||||
await init();
|
||||
web_main();
|
||||
|
9
examples/wasm-audio-worklet/run.py
Normal file
9
examples/wasm-audio-worklet/run.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
root_dir = os.path.dirname(__file__)
|
||||
|
||||
subprocess.run(["python3", "build.py"], cwd=root_dir).check_returncode()
|
||||
|
||||
subprocess.run(["python3", "server.py"], cwd=root_dir).check_returncode()
|
@ -2,6 +2,6 @@
|
||||
|
||||
set -ex
|
||||
|
||||
./build.sh
|
||||
python3 build.py
|
||||
|
||||
python3 server.py
|
||||
|
Loading…
Reference in New Issue
Block a user