wasmrust 0.3.2

Rust WebAssembly plugin for Wasmrun - compile Rust projects to WebAssembly with wasm-bindgen support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# WasmRust Development Justfile
# Rust to WebAssembly compiler plugin for Wasmrun

# Default recipe - show available commands
default:
    @echo "๐Ÿฆ€ WasmRust Development Commands"
    @echo "==============================="
    @just --list

# ============================================================================
# DEVELOPMENT COMMANDS
# ============================================================================

# Format code with rustfmt
format:
    @echo "๐ŸŽจ Formatting code..."
    cargo fmt

# Run clippy linter
lint:
    @echo "๐Ÿ” Running linter..."
    cargo clippy --all-targets --all-features -- -D warnings

# Run clippy with automatic fixes
lint-fix:
    @echo "๐Ÿ”ง Running linter with fixes..."
    cargo clippy --all-targets --all-features --fix

# Check code without building
check:
    @echo "โœ… Checking code..."
    cargo check --all-features

# Check code with specific features
check-features feature:
    @echo "โœ… Checking with feature: {{feature}}"
    cargo check --features {{feature}}

# ============================================================================
# BUILD COMMANDS
# ============================================================================

# Clean build artifacts
clean:
    @echo "๐Ÿงน Cleaning build artifacts..."
    cargo clean

# Build the project (library mode)
build: format lint test
    @echo "๐Ÿ”จ Building library..."
    cargo build --release

# Build with CLI feature
build-cli:
    @echo "๐Ÿ”จ Building with CLI..."
    cargo build --release --features cli

# Build with wasmrun integration. Experimental feature.
build-wasmrun:
    @echo "๐Ÿ”จ Building with wasmrun integration..."
    cargo build --release --features wasmrun-integration

# Build all feature combinations
build-all:
    @echo "๐Ÿ”จ Building all feature combinations..."
    @echo "1. Library only (no features):"
    cargo build --release --no-default-features
    @echo "2. CLI only:"
    cargo build --release --no-default-features --features cli
    @echo "3. Wasmrun integration only:"
    cargo build --release --no-default-features --features wasmrun-integration
    @echo "4. All features:"
    cargo build --release --all-features

# ============================================================================
# TESTING COMMANDS
# ============================================================================

# Run all tests
test:
    @echo "๐Ÿงช Running tests..."
    cargo test

# Run tests with specific features
test-features feature:
    @echo "๐Ÿงช Running tests with feature: {{feature}}"
    cargo test --features {{feature}}

# Run tests with wasmrun integration
test-wasmrun:
    @echo "๐Ÿงช Running wasmrun integration tests..."
    cargo test --features wasmrun-integration

# Run integration tests (requires Rust toolchain)
test-integration:
    @echo "๐Ÿงช Running integration tests..."
    cargo test test_actual_compilation -- --ignored

# Run all tests with coverage
test-coverage:
    @echo "๐Ÿงช Running tests with coverage..."
    cargo test --all-features

# Test specific module
test-module module:
    @echo "๐Ÿงช Testing module: {{module}}"
    cargo test {{module}}

# ============================================================================
# CLI COMMANDS
# ============================================================================

# Run the CLI with help
cli-help:
    @echo "๐Ÿ“– Showing CLI help..."
    cargo run --features cli -- --help

# Run CLI info command
cli-info:
    @echo "โ„น๏ธ  CLI info..."
    cargo run --features cli -- info

# Run CLI frameworks command
cli-frameworks:
    @echo "๐ŸŒ Showing supported frameworks..."
    cargo run --features cli -- frameworks

# Check CLI dependencies
cli-check-deps:
    @echo "๐Ÿ” Checking CLI dependencies..."
    cargo run --features cli -- check-deps

# Run CLI with custom arguments
cli *args:
    @echo "๐Ÿš€ Running CLI with args: {{args}}"
    cargo run --features cli -- {{args}}

# ============================================================================
# EXAMPLE MANAGEMENT
# ============================================================================

# Set up example projects
setup-examples:
    @echo "๐Ÿ“ Setting up example projects..."
    @mkdir -p examples/{simple-rust,simple-web,complex-yew,trunk-app}/src
    @echo "โœ… Example directories created"

# Create simple Rust WASM example
create-simple-rust:
    @echo "๐Ÿ“ Creating simple Rust WASM example..."
    @mkdir -p examples/simple-rust/src
    @echo '[package]\nname = "simple-rust"\nversion = "0.1.0"\nedition = "2021"\n\n[lib]\ncrate-type = ["cdylib"]' > examples/simple-rust/Cargo.toml
    @echo '#[no_mangle]\npub extern "C" fn add(a: i32, b: i32) -> i32 {\n    a + b\n}\n\n#[no_mangle]\npub extern "C" fn fibonacci(n: u32) -> u32 {\n    match n {\n        0 => 0,\n        1 => 1,\n        _ => fibonacci(n - 1) + fibonacci(n - 2),\n    }\n}' > examples/simple-rust/src/lib.rs

# Create wasm-bindgen example
create-simple-web:
    @echo "๐Ÿ“ Creating wasm-bindgen example..."
    @mkdir -p examples/simple-web/src
    @echo '[package]\nname = "simple-web"\nversion = "0.1.0"\nedition = "2021"\n\n[lib]\ncrate-type = ["cdylib"]\n\n[dependencies]\nwasm-bindgen = "0.2"\nweb-sys = "0.3"\njs-sys = "0.3"' > examples/simple-web/Cargo.toml
    @echo 'use wasm_bindgen::prelude::*;\n\n#[wasm_bindgen]\nextern "C" {\n    fn alert(s: &str);\n    #[wasm_bindgen(js_namespace = console)]\n    fn log(s: &str);\n}\n\n#[wasm_bindgen]\npub fn greet(name: &str) {\n    log(&format!("Hello from Rust, {}!", name));\n}\n\n#[wasm_bindgen]\npub struct Calculator;\n\n#[wasm_bindgen]\nimpl Calculator {\n    #[wasm_bindgen(constructor)]\n    pub fn new() -> Calculator {\n        Calculator\n    }\n    \n    #[wasm_bindgen]\n    pub fn add(&self, a: f64, b: f64) -> f64 {\n        a + b\n    }\n}' > examples/simple-web/src/lib.rs

# Create Yew example
create-complex-yew:
    @echo "๐Ÿ“ Creating Yew example..."
    @mkdir -p examples/complex-yew/src
    @echo '[package]\nname = "complex-yew"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\nyew = { version = "0.21", features = ["csr"] }\nwasm-bindgen = "0.2"\nweb-sys = "0.3"' > examples/complex-yew/Cargo.toml
    @echo 'use yew::prelude::*;\n\n#[function_component(Counter)]\nfn counter() -> Html {\n    let count = use_state(|| 0);\n    let onclick = {\n        let count = count.clone();\n        move |_| count.set(*count + 1)\n    };\n\n    html! {\n        <div>\n            <h2>{ "Counter: " }{ *count }</h2>\n            <button {onclick}>{ "Increment" }</button>\n        </div>\n    }\n}\n\n#[function_component(App)]\nfn app() -> Html {\n    html! {\n        <div>\n            <h1>{ "Hello Yew!" }</h1>\n            <Counter />\n        </div>\n    }\n}\n\nfn main() {\n    yew::Renderer::<App>::new().render();\n}' > examples/complex-yew/src/main.rs
    @echo '<!DOCTYPE html>\n<html>\n<head>\n    <meta charset="utf-8">\n    <title>Yew App</title>\n</head>\n<body></body>\n</html>' > examples/complex-yew/index.html

# Create Trunk example
create-trunk-app:
    @echo "๐Ÿ“ Creating Trunk example..."
    @mkdir -p examples/trunk-app/src
    @echo '[package]\nname = "trunk-app"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\nyew = { version = "0.21", features = ["csr"] }\nwasm-bindgen = "0.2"' > examples/trunk-app/Cargo.toml
    @echo '[build]\ntarget = "index.html"\n\n[watch]\nwatch = ["src", "Cargo.toml"]\nignore = ["dist"]' > examples/trunk-app/Trunk.toml
    @echo 'use yew::prelude::*;\n\n#[function_component(App)]\nfn app() -> Html {\n    html! {\n        <div>\n            <h1>{ "Trunk App" }</h1>\n            <p>{ "Built with Trunk!" }</p>\n        </div>\n    }\n}\n\nfn main() {\n    yew::Renderer::<App>::new().render();\n}' > examples/trunk-app/src/main.rs
    @echo '<!DOCTYPE html>\n<html>\n<head>\n    <meta charset="utf-8">\n    <title>Trunk App</title>\n</head>\n<body></body>\n</html>' > examples/trunk-app/index.html

# Create all examples
create-examples: create-simple-rust create-simple-web create-complex-yew create-trunk-app
    @echo "โœ… All examples created!"

# ============================================================================
# EXAMPLE TESTING
# ============================================================================

# Check if examples can be handled
check-examples:
    @echo "๐Ÿ” Checking if examples can be handled..."
    @echo ""
    @if [ -d "examples/simple-rust" ]; then \
        echo "1. Checking simple-rust:"; \
        just cli can-handle examples/simple-rust; \
        echo ""; \
    fi
    @if [ -d "examples/simple-web" ]; then \
        echo "2. Checking simple-web:"; \
        just cli can-handle examples/simple-web; \
        echo ""; \
    fi
    @if [ -d "examples/complex-yew" ]; then \
        echo "3. Checking complex-yew:"; \
        just cli can-handle examples/complex-yew; \
        echo ""; \
    fi
    @if [ -d "examples/trunk-app" ]; then \
        echo "4. Checking trunk-app:"; \
        just cli can-handle examples/trunk-app; \
    fi

# Inspect example projects
inspect-examples:
    @echo "๐Ÿ“Š Inspecting example projects..."
    @echo ""
    @if [ -d "examples/simple-rust" ]; then \
        echo "1. Inspecting simple-rust:"; \
        just cli inspect examples/simple-rust; \
        echo ""; \
    fi
    @if [ -d "examples/simple-web" ]; then \
        echo "2. Inspecting simple-web:"; \
        just cli inspect examples/simple-web; \
        echo ""; \
    fi
    @if [ -d "examples/complex-yew" ]; then \
        echo "3. Inspecting complex-yew:"; \
        just cli inspect examples/complex-yew; \
        echo ""; \
    fi

# Compile examples
compile-examples:
    @echo "๐Ÿ”จ Compiling examples..."
    @echo ""
    @if [ -d "examples/simple-rust" ]; then \
        echo "1. Compiling simple-rust:"; \
        just cli compile --project examples/simple-rust --output examples/simple-rust/dist; \
        echo ""; \
    fi
    @if [ -d "examples/simple-web" ]; then \
        echo "2. Compiling simple-web:"; \
        just cli compile --project examples/simple-web --output examples/simple-web/dist; \
        echo ""; \
    fi
    @if [ -d "examples/complex-yew" ]; then \
        echo "3. Compiling complex-yew:"; \
        just cli compile --project examples/complex-yew --output examples/complex-yew/dist; \
        echo ""; \
    fi

# Compile examples with verbose output
compile-examples-verbose:
    @echo "๐Ÿ”จ Compiling examples (verbose)..."
    @echo ""
    @if [ -d "examples/simple-rust" ]; then \
        echo "1. Compiling simple-rust (verbose):"; \
        just cli compile --project examples/simple-rust --output examples/simple-rust/dist --verbose; \
        echo ""; \
    fi
    @if [ -d "examples/simple-web" ]; then \
        echo "2. Compiling simple-web (verbose):"; \
        just cli compile --project examples/simple-web --output examples/simple-web/dist --verbose; \
        echo ""; \
    fi
    @if [ -d "examples/complex-yew" ]; then \
        echo "3. Compiling complex-yew (verbose):"; \
        just cli compile --project examples/complex-yew --output examples/complex-yew/dist --verbose; \
        echo ""; \
    fi

# Test specific example
test-example example:
    @echo "๐Ÿงช Testing {{example}} example..."
    @if [ -d "examples/{{example}}" ]; then \
        echo "โœ… Directory exists"; \
        just cli can-handle examples/{{example}}; \
        echo ""; \
        just cli inspect examples/{{example}}; \
        echo ""; \
        just cli compile --project examples/{{example}} --output examples/{{example}}/dist --verbose; \
    else \
        echo "โŒ Example '{{example}}' not found. Available examples:"; \
        ls examples/ 2>/dev/null || echo "No examples directory found. Run 'just create-examples' first."; \
    fi

# Clean example outputs
clean-examples:
    @echo "๐Ÿงน Cleaning example outputs..."
    @rm -rf examples/*/dist
    @rm -rf examples/*/target
    @echo "โœ… Example outputs cleaned"

# ============================================================================
# INSTALLATION & PUBLISHING
# ============================================================================

# Install locally for testing (CLI mode)
install-cli:
    @echo "๐Ÿ“ฆ Installing CLI locally..."
    cargo install --path . --features cli --force

# Install locally for testing (library mode)  
install-lib:
    @echo "๐Ÿ“ฆ Installing library locally..."
    cargo install --path . --no-default-features --force

# Uninstall local installation
uninstall:
    @echo "๐Ÿ—‘๏ธ  Uninstalling local installation..."
    cargo uninstall wasmrust

# Publish to crates.io (dry run first)
publish-test:
    @echo "๐Ÿš€ Dry run publish to crates.io..."
    cargo publish --dry-run

# Publish to crates.io
publish:
    @echo "๐Ÿš€ Publishing to crates.io..."
    cargo publish

# ============================================================================
# DEVELOPMENT WORKFLOWS
# ============================================================================

# Quick development cycle: format, lint, test, build
dev: format lint test build
    @echo "โœ… Development cycle complete!"

# Full development cycle with all features
dev-full: format lint test-wasmrun build-all
    @echo "โœ… Full development cycle complete!"

# Prepare for release: full test, build all, test publish
release-prep: format lint test-coverage build-all publish-test
    @echo "โœ… Release preparation complete!"

# Complete example workflow: create, test, compile
examples-full: create-examples check-examples inspect-examples compile-examples
    @echo "โœ… Complete example workflow finished!"

# ============================================================================
# MAINTENANCE COMMANDS
# ============================================================================

# Update dependencies
update-deps:
    @echo "๐Ÿ“ฆ Updating dependencies..."
    cargo update

# Check for outdated dependencies
check-outdated:
    @echo "๐Ÿ” Checking for outdated dependencies..."
    cargo outdated

# Generate documentation
docs:
    @echo "๐Ÿ“š Generating documentation..."
    cargo doc --all-features --no-deps --open

# Check security advisories
security-audit:
    @echo "๐Ÿ”’ Running security audit..."
    cargo audit

# Run benchmarks (if available)
bench:
    @echo "โšก Running benchmarks..."
    cargo bench

# ============================================================================
# UTILITY COMMANDS
# ============================================================================

# Show project information
info:
    @echo "๐Ÿฆ€ WasmRust Project Information"
    @echo "==============================="
    @echo "Version: $(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')"
    @echo "Features: cli, wasmrun-integration"
    @echo "Examples: $(ls examples/ 2>/dev/null | wc -l || echo 0) available"
    @echo "Tests: $(cargo test --dry-run 2>&1 | grep -c 'test result:' || echo 'unknown')"

# Show dependency tree
deps-tree:
    @echo "๐ŸŒณ Dependency tree..."
    cargo tree

# Show feature flags
features:
    @echo "๐Ÿด Available features..."
    @echo "โ€ข cli              - Command line interface"
    @echo "โ€ข wasmrun-integration - Wasmrun plugin integration"
    @echo "โ€ข default          - wasmrun-integration (enabled by default)"

# Check workspace
workspace-check:
    @echo "๐Ÿ” Workspace check..."
    @echo "Current directory: $(pwd)"
    @echo "Cargo.toml exists: $(test -f Cargo.toml && echo 'Yes' || echo 'No')"
    @echo "src/ directory exists: $(test -d src && echo 'Yes' || echo 'No')"
    @echo "Examples directory: $(test -d examples && echo 'Yes' || echo 'No')"

# Show all available recipes with descriptions
help:
    @echo "๐Ÿฆ€ WasmRust Development Commands"
    @echo "==============================="
    @echo ""
    @echo "๐Ÿ“– DEVELOPMENT:"
    @echo "  format           - Format code with rustfmt"
    @echo "  lint             - Run clippy linter"
    @echo "  lint-fix         - Run clippy with fixes"
    @echo "  check            - Check code without building"
    @echo ""
    @echo "๐Ÿ”จ BUILD:"
    @echo "  build            - Build library"
    @echo "  build-cli        - Build with CLI feature"
    @echo "  build-wasmrun    - Build with wasmrun integration"
    @echo "  build-all        - Build all feature combinations"
    @echo ""
    @echo "๐Ÿงช TESTING:"
    @echo "  test             - Run all tests"
    @echo "  test-wasmrun     - Run wasmrun integration tests"
    @echo "  test-integration - Run integration tests"
    @echo ""
    @echo "๐Ÿš€ CLI:"
    @echo "  cli-help         - Show CLI help"
    @echo "  cli-info         - Show plugin info"
    @echo "  cli *args        - Run CLI with custom arguments"
    @echo ""
    @echo "๐Ÿ“ EXAMPLES:"
    @echo "  create-examples  - Create all example projects"
    @echo "  check-examples   - Check example compatibility"
    @echo "  compile-examples - Compile all examples"
    @echo "  test-example     - Test specific example"
    @echo ""
    @echo "๐Ÿ”ง WORKFLOWS:"
    @echo "  dev              - Quick development cycle"
    @echo "  dev-full         - Full development cycle"
    @echo "  examples-full    - Complete example workflow"
    @echo ""
    @echo "For more details: just --list"