Initial reorg.
This is largely the same as #305, but updated for the current tree.
This commit is contained in:
3
crates/misc/py/examples/import/.gitignore
vendored
Normal file
3
crates/misc/py/examples/import/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import.wasm
|
||||
main.wasm
|
||||
__pycache__
|
||||
15
crates/misc/py/examples/import/README.md
Normal file
15
crates/misc/py/examples/import/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Build example's file
|
||||
|
||||
To build `demo.wasm` use rustc (nightly) for wasm32 target with debug information:
|
||||
|
||||
```
|
||||
rustc +nightly --target=wasm32-unknown-unknown demo.rs --crate-type=cdylib
|
||||
```
|
||||
|
||||
# Run example
|
||||
|
||||
Point path to the built `wasmtime_py` library location when running python, e.g.
|
||||
|
||||
```
|
||||
PYTHONPATH=../../target/debug python3 run.py
|
||||
```
|
||||
11
crates/misc/py/examples/import/demo.rs
Normal file
11
crates/misc/py/examples/import/demo.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
extern "C" {
|
||||
fn callback(s: *const u8, s_len: u32) -> u32;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn test() {
|
||||
let msg = "Hello, world!";
|
||||
unsafe {
|
||||
callback(msg.as_ptr(), msg.len() as u32);
|
||||
}
|
||||
}
|
||||
10
crates/misc/py/examples/import/env.py
Normal file
10
crates/misc/py/examples/import/env.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def callback(msg_p: 'i32', msg_len: 'i32') -> 'i32':
|
||||
print('callback:', msg_p, msg_len)
|
||||
|
||||
# global memory
|
||||
# mv = memoryview(memory)
|
||||
|
||||
# msg = bytes(mv[msg_p:(msg_p + msg_len)]).decode('utf-8')
|
||||
# print(msg)
|
||||
|
||||
return 42
|
||||
4
crates/misc/py/examples/import/run.py
Normal file
4
crates/misc/py/examples/import/run.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import wasmtime
|
||||
import demo
|
||||
|
||||
demo.test()
|
||||
Reference in New Issue
Block a user