Skip to content

Commit b6ad359

Browse files
committed
PR #12 follow-up: docs, CI, gitignore for Rust example
- .gitignore: scope target/ and Cargo.lock to examples/rust/ - book en/ja c-api.md: add Rust FFI quickstart section + example ref - ci.yml: add Rust FFI example build+run step after Setup Rust
1 parent 775224c commit b6ad359

4 files changed

Lines changed: 61 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ jobs:
6666
rustup target add wasm32-wasip1
6767
rustc --version
6868
69+
- name: Run Rust FFI example
70+
if: runner.os != 'Windows'
71+
run: cd examples/rust && cargo run
72+
6973
- name: Install wasm-tools
7074
run: |
7175
source .github/tool-versions

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ zig-cache/
1212
# Python
1313
__pycache__/
1414

15-
# Rust
16-
target/
17-
Cargo.lock
15+
# Rust example build artifacts
16+
examples/rust/target/
17+
examples/rust/Cargo.lock
1818

1919
# Editor
2020
*.swp

book/en/src/c-api.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ zig build lib
116116
python3 examples/python/basic.py
117117
```
118118

119+
## Quickstart: Rust (FFI)
120+
121+
Rust can call the same C API via `extern "C"` bindings:
122+
123+
```rust
124+
#[link(name = "zwasm")]
125+
unsafe extern "C" {
126+
fn zwasm_module_new(wasm_ptr: *const u8, len: usize) -> *mut zwasm_module_t;
127+
fn zwasm_module_invoke(
128+
module: *mut zwasm_module_t, name: *const std::ffi::c_char,
129+
args: *const u64, nargs: u32, results: *mut u64, nresults: u32,
130+
) -> bool;
131+
fn zwasm_module_delete(module: *mut zwasm_module_t);
132+
}
133+
```
134+
135+
Build and run (requires Rust 1.85+ for edition 2024):
136+
137+
```bash
138+
zig build shared-lib
139+
cd examples/rust && cargo run
140+
# f() = 42
141+
```
142+
143+
See `examples/rust/` for the full working example.
144+
119145
## API reference
120146

121147
Functions are grouped by domain. All signatures live in `include/zwasm.h`.
@@ -285,5 +311,5 @@ zwasm_module_delete(mod);
285311
## Next steps
286312
287313
- [Build Configuration](./build-configuration.md) — customize which features are compiled in
288-
- `examples/c/` and `examples/python/` — working examples in the repository
314+
- `examples/c/`, `examples/python/`, and `examples/rust/` — working examples in the repository
289315
- `include/zwasm.h` — the complete C header with doc comments

book/ja/src/c-api.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ zig build lib
116116
python3 examples/python/basic.py
117117
```
118118

119+
## クイックスタート: Rust (FFI)
120+
121+
Rust からも `extern "C"` バインディングで同じ C API を呼び出せます:
122+
123+
```rust
124+
#[link(name = "zwasm")]
125+
unsafe extern "C" {
126+
fn zwasm_module_new(wasm_ptr: *const u8, len: usize) -> *mut zwasm_module_t;
127+
fn zwasm_module_invoke(
128+
module: *mut zwasm_module_t, name: *const std::ffi::c_char,
129+
args: *const u64, nargs: u32, results: *mut u64, nresults: u32,
130+
) -> bool;
131+
fn zwasm_module_delete(module: *mut zwasm_module_t);
132+
}
133+
```
134+
135+
ビルドと実行 (Rust 1.85+ が必要、edition 2024):
136+
137+
```bash
138+
zig build shared-lib
139+
cd examples/rust && cargo run
140+
# f() = 42
141+
```
142+
143+
完全な動作例は `examples/rust/` を参照してください。
144+
119145
## API リファレンス
120146

121147
関数はドメインごとにグループ化されています。すべてのシグネチャは `include/zwasm.h` に定義されています。
@@ -285,5 +311,5 @@ zwasm_module_delete(mod);
285311
## 次のステップ
286312
287313
- [ビルド設定](./build-configuration.md) — コンパイルに含める機能のカスタマイズ
288-
- `examples/c/``examples/python/` — リポジトリ内の動作する例
314+
- `examples/c/``examples/python/`、`examples/rust/` — リポジトリ内の動作する例
289315
- `include/zwasm.h` — ドキュメントコメント付きの完全な C ヘッダ

0 commit comments

Comments
 (0)