Skip to content

Commit 81b295d

Browse files
committed
fix wasi-py-rs review comments
1 parent 13d18bb commit 81b295d

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

python/examples/embedding/wasi-py-rs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
pyo3 = { version = "0.19.0", features = ["abi3-py311"] }
8-
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", branch="rust-py-example", features = ["py_main"] }
8+
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = ["py_main"] }
99

1010
[build-dependencies]
11-
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", branch="rust-py-example", features = ["build"] }
11+
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = ["build"] }

python/examples/embedding/wasi-py-rs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ Take a look at [Cargo.toml](./Cargo.toml) to see how to add it as a build depend
5757

5858
```toml
5959
[build-dependencies]
60-
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", branch="rust-py-example", features = ["build"] }
60+
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = ["build"] }
6161
```
6262

6363
Then, in the [build.rs](./build.rs) file we only need to add this to the `main` method:
6464

6565
```rs
66+
fn main() {
67+
// ...
6668
use wlr_libpy::bld_cfg::configure_static_libs;
6769
configure_static_libs().unwrap().emit_link_flags();
70+
// ...
71+
}
6872
```
6973

7074
This will ensure that all required libraries are downloaded and the linker is configured to use them.

python/examples/embedding/wasi-py-rs/src/bin/py-func-caller.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,7 @@ use wasi_py_rs::py_module::make_person_module;
66
pub fn main() -> PyResult<()> {
77
append_to_inittab!(make_person_module);
88

9-
let function_code = "def my_func(*args, **kwargs):
10-
import sys
11-
print(f'Hello from Python (libpython3.11.a / {sys.version}) in Wasm(Rust).\\nargs=', args)
12-
13-
import person
14-
people = []
15-
for name, age, tags in args:
16-
p = person.Person(name, age)
17-
for t in tags:
18-
p.add_tag(t)
19-
people.append(p)
20-
21-
filtered = person.filter_by_tag(people, 'student')
22-
print(f'Original people: {people}')
23-
print(f'Filtered people by `student`: {filtered}')
24-
";
25-
9+
let function_code = include_str!("py-func.py");
2610
call_function(
2711
"my_func",
2812
function_code,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def my_func(*args, **kwargs):
2+
import sys
3+
print(f'Hello from Python (libpython3.11.a / {sys.version}) in Wasm(Rust).\\nargs=', args)
4+
5+
import person
6+
people = []
7+
for name, age, tags in args:
8+
p = person.Person(name, age)
9+
for t in tags:
10+
p.add_tag(t)
11+
people.append(p)
12+
13+
filtered = person.filter_by_tag(people, 'student')
14+
print(f'Original people: {people}')
15+
print(f'Filtered people by `student`: {filtered}')

python/tools/wlr-libpy/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ To use this feature add this to your Cargo.toml
1212

1313
```toml
1414
[build-dependencies]
15-
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", branch="rust-py-example", features = ["build"] }
15+
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = ["build"] }
1616
```
1717

1818
Then, in the `build.rs` file of your project you only need to call `configure_static_libs().unwrap().emit_link_flags()` like this:
1919

2020
```rs
2121
fn main() {
22+
// ...
2223
use wlr_libpy::bld_cfg::configure_static_libs;
2324
configure_static_libs().unwrap().emit_link_flags();
25+
// ...
2426
}
2527
```
2628

@@ -39,12 +41,14 @@ To use this feature add this to your Cargo.toml
3941
```toml
4042
[dependencies]
4143
...
42-
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", branch="rust-py-example", features = ["py_main"] }
44+
wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = ["py_main"] }
4345
```
4446

4547
Then to call on the `Py_Main` method just do this:
4648

4749
```rs
50+
fn main() {
4851
use wlr_libpy::py_main::py_main;
4952
py_main(std::env::args().collect());
53+
}
5054
```

0 commit comments

Comments
 (0)