wasmhub 0.3.2

Download and manage WebAssembly runtimes for multiple languages
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
# Contributing to WasmHub

Thank you for your interest in contributing! This project aims to be community-driven.

## ๐Ÿ“ Project Structure

```sh
wasmhub/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib.rs                       # ๐Ÿ“ฆ Library code
โ”‚   โ””โ”€โ”€ bin/
โ”‚       โ””โ”€โ”€ wasmhub.rs               # ๐Ÿ”ง CLI binary (feature-gated)
โ”‚
โ”œโ”€โ”€ runtimes/                        # ๐Ÿ“ Runtime sources and manifests
โ”‚   โ””โ”€โ”€ go/
โ”‚       โ”œโ”€โ”€ main.go                  # Source file
โ”‚       โ”œโ”€โ”€ manifest.json            # Version metadata
โ”‚       โ””โ”€โ”€ *.wasm                   # Built binaries (gitignored)
โ”‚
โ”œโ”€โ”€ scripts/                         # ๐Ÿ”ง Build scripts
โ”‚   โ”œโ”€โ”€ build-all.sh                 # Build all runtimes
โ”‚   โ”œโ”€โ”€ build-go.sh                  # Build Go runtime
โ”‚   โ”œโ”€โ”€ build-rust.sh                # Build Rust runtime
โ”‚   โ”œโ”€โ”€ generate-metadata.sh         # Generate manifest.json
โ”‚   โ””โ”€โ”€ verify-binary.sh             # Verify WASM binary
โ”‚
โ”œโ”€โ”€ .github/workflows/
โ”‚   โ”œโ”€โ”€ ci.yml                       # โœ… CI pipeline (tests, lint, format)
โ”‚   โ”œโ”€โ”€ release.yml                  # ๐Ÿ“ฆ Release workflow (builds WASM + CLI)
โ”‚   โ”œโ”€โ”€ build-runtimes.yml           # ๐Ÿ”จ Build runtimes on push
โ”‚   โ””โ”€โ”€ docs.yml                     # ๐Ÿ“š Build + deploy docs site to Pages
โ”‚
โ”œโ”€โ”€ docs/                            # ๐Ÿ“š Eleventy docs site (GitHub Pages)
โ”‚   โ”œโ”€โ”€ content/                     # Markdown pages
โ”‚   โ”œโ”€โ”€ assets/theme.css             # Wasmhub theming
โ”‚   โ”œโ”€โ”€ .eleventy.js                 # Eleventy config
โ”‚   โ””โ”€โ”€ package.json                 # Site deps + build scripts
โ”‚
โ”œโ”€โ”€ Cargo.toml                       # ๐Ÿ“ฆ Package manifest
โ”œโ”€โ”€ Dockerfile                       # ๐Ÿณ Build environment for WASM
โ”œโ”€โ”€ justfile                         # ๐Ÿ› ๏ธ Build commands
โ”œโ”€โ”€ README.md                        # ๐Ÿ“– User-facing docs
โ”œโ”€โ”€ CONTRIBUTING.md                  # ๐Ÿ‘ฅ This file
โ”œโ”€โ”€ LICENSE                          # โš–๏ธ MIT License
โ””โ”€โ”€ .gitignore                       # ๐Ÿšซ Git ignore rules
```

The project is a single Rust crate with:
- **Library API** (`src/lib.rs`) - Can be used programmatically
- **CLI tool** (`src/bin/wasmhub.rs`) - Enabled with `--features cli`

## ๐Ÿš€ Ways to Contribute

1. **Report Bugs** - Open an issue with reproduction steps
2. **Request Features** - Suggest new runtimes or improvements
3. **Submit PRs** - Fix bugs, add runtimes, improve docs
4. **Improve Documentation** - Help others understand the project
5. **Share** - Star the repo, tell others about it

## ๐Ÿ”ง Development Setup

### Prerequisites

- Rust 1.85+ (`rustup install stable`)
- Git
- Just (optional, for convenient build commands: `cargo install just`)

### Clone & Build

```sh
# Clone repository
git clone https://github.com/anistark/wasmhub.git
cd wasmhub

# Build library only
cargo build

# Build library + CLI
cargo build --features cli

# Run tests
cargo test

# Run CLI locally
cargo run --features cli -- --help

# Install CLI globally
cargo install --path . --features cli
```

## ๐Ÿ“ Code Style

```sh
# Format code
just format

# Lint code
just lint

# Auto-fix linting issues
just lint-fix
```

All PRs must pass formatting and linting checks.

## ๐Ÿงช Testing

Write tests for all new features:

```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_language_from_str() {
        assert_eq!(Language::from_str("nodejs"), Some(Language::NodeJs));
        assert_eq!(Language::from_str("unknown"), None);
    }
}
```

Run tests:
```sh
cargo test
```

## ๐Ÿ“ฆ Adding a New Runtime

WASM binaries are **not** committed to the repository. They are built by CI and published as GitHub Release assets.

### Steps to Add a New Runtime

1. **Create the source directory**: `runtimes/<language>/`
2. **Add the source file** (e.g., `main.go`, `lib.rs`)
3. **Create a build script**: `scripts/build-<language>.sh`
4. **Update `scripts/build-all.sh`** to include your language
5. **Add to `Language` enum** in `src/runtime.rs`
6. **Write tests**
7. **Update README.md** with the new runtime
8. **Submit PR**

Example for adding Java:
```sh
# Create runtime directory with source
mkdir -p runtimes/java
# Add source file (e.g., Main.java)

# Create build script
cat > scripts/build-java.sh << 'EOF'
#!/usr/bin/env bash
# Build Java to WASM using TeaVM or similar
EOF
chmod +x scripts/build-java.sh

# Update build-all.sh to include Java builds
# Update Language enum in src/runtime.rs
git commit -am "Add Java runtime support"
```

### Runtime Directory Structure

```sh
runtimes/
โ”œโ”€โ”€ go/
โ”‚   โ”œโ”€โ”€ main.go           # Source file (committed)
โ”‚   โ”œโ”€โ”€ manifest.json     # Generated by build (committed)
โ”‚   โ””โ”€โ”€ go-1.23.wasm      # Built binary (gitignored, in releases)
โ””โ”€โ”€ rust/
    โ”œโ”€โ”€ Cargo.toml        # Source (committed)
    โ”œโ”€โ”€ src/lib.rs        # Source (committed)
    โ”œโ”€โ”€ manifest.json     # Generated by build (committed)
    โ””โ”€โ”€ rust-1.75.wasm    # Built binary (gitignored, in releases)
```

### Manifest Format

Each runtime has a `manifest.json` that describes available versions:

```json
{
    "language": "go",
    "latest": "1.23",
    "versions": {
        "1.23": {
            "file": "go-1.23.wasm",
            "size": 266712,
            "sha256": "efa1e13f39dfd3783d0eff5669088ab99a1ea1d38ac79f29b02e2ad8ddfea29d",
            "released": "2026-02-03T13:23:13Z",
            "wasi": "wasip1",
            "features": []
        }
    }
}
```

The manifest is auto-generated by `scripts/generate-metadata.sh` during the build process.

## ๐Ÿ“š Documentation Site

The docs site lives in `docs/` and is built with [Eleventy 3.x](https://www.11ty.dev/) using the [eleventy-libdoc](https://github.com/ita-design-system/eleventy-libdoc) starter. It's deployed to GitHub Pages at **https://anistark.github.io/wasmhub/** automatically when anything under `docs/**` lands on `main`.

### Run the docs locally

```sh
just docs-install      # first time only โ€” installs pnpm deps
just docs              # โ†’ http://localhost:8080/
just docs-build        # production build โ†’ docs/_site/
just docs-clean        # remove _site/
```

Or directly with pnpm if you prefer:

```sh
cd docs
pnpm install
pnpm run serve
```

> **Use pnpm**, not npm. The lockfile and CI are pinned to pnpm.

### Add or edit a page

1. Create or edit a `.md` file under `docs/content/`
2. Add YAML frontmatter (title, navigation order โ€” see existing pages for the libdoc convention)
3. Cross-link to other pages using the Eleventy `url` filter so the `/wasmhub/` path prefix works on GitHub Pages:
   ```liquid
   [CLI reference]({{ '/cli/' | url }})
   ```
4. Preview locally with `npm run serve`
5. Open a PR โ€” once merged, the site rebuilds and deploys within ~2 minutes

### Theming

Wasmhub branding lives in `docs/assets/theme.css` and overrides libdoc's CSS custom properties. **Don't edit libdoc's vendored CSS directly** โ€” it makes future libdoc upgrades painful. If you need to add styles libdoc doesn't expose as variables, add them to `theme.css`.

### Adding screenshots/images

Drop images into `docs/assets/` (or a subfolder). libdoc uses `@11ty/eleventy-img` + `sharp` for transcoding/responsive variants โ€” reference images normally in Markdown and the build handles the rest.

### Build for production

```sh
cd docs
pnpm run build         # output in docs/_site/ (gitignored)
```

CI does this automatically โ€” you don't need to commit build output.

---

## ๐Ÿ”„ CI/CD and Releases

### Continuous Integration

Every PR and push to `main` triggers CI checks:
- **Test**: Runs `cargo test` on Linux, macOS, and Windows
- **Format**: Checks code formatting with `cargo fmt`
- **Lint**: Runs `cargo clippy` for linting

### Release Process

When a GitHub Release is created:

1. **WASM runtimes are built** using the Docker build environment
2. **Manifests are generated** with checksums and metadata
3. **Binaries are uploaded** as release assets
4. **CLI binaries** are cross-compiled for all platforms

To create a release:
```sh
# Update version in Cargo.toml, then run:
just publish

# Or for GitHub release only (no crates.io):
just publish-github

# Or with explicit version:
just release 0.3.2
```

### Build Environment

WASM runtimes are built in a Docker container with:
- WASI SDK (for C/C++ compilation)
- TinyGo (for Go compilation)
- Rust with `wasm32-wasip1` target
- `wasm-opt` for binary optimization

To build locally:
```sh
# Using Docker (recommended)
just docker-build          # Build the Docker image
just docker-build-runtimes # Build all WASM runtimes

# Or install dependencies natively and run
./scripts/build-all.sh
```

---

## ๐Ÿ› Reporting Bugs

Open an issue with:
- **Description** - What went wrong?
- **Steps to reproduce**
- **Expected behavior**
- **Actual behavior**
- **Environment** - OS, Rust version, etc.

## ๐Ÿ’ก Feature Requests

Open an issue with:
- **Use case** - Why is this needed?
- **Proposed solution**
- **Alternatives considered**

## ๐Ÿ”€ Pull Request Process

1. **Fork** the repository
2. **Create a branch** - `git checkout -b feature/my-feature`
3. **Make changes** - Follow code style
4. **Write tests** - Ensure coverage
5. **Update docs** - If needed
6. **Commit** - Use clear commit messages
7. **Push** - `git push origin feature/my-feature`
8. **Open PR** - Fill out the template

### PR Checklist

- [ ] Code follows Rust style guide (`cargo fmt`)
- [ ] No clippy warnings (`cargo clippy`)
- [ ] Tests added and passing (`cargo test`)
- [ ] Documentation updated
- [ ] CHANGELOG.md updated (if applicable)

## ๐Ÿ“œ Commit Messages

Use conventional commits:

```
feat: add Java runtime support
fix: correct cache path on Windows
docs: update CLI usage examples
test: add integration tests for loader
chore: update dependencies
```

## ๐Ÿท๏ธ Issue Labels

- `good-first-issue` - Great for newcomers
- `help-wanted` - Need community help
- `bug` - Something isn't working
- `enhancement` - New feature request
- `documentation` - Docs improvements

## โš–๏ธ Code of Conduct

Be respectful, inclusive, and collaborative. We're building this together.

## ๐Ÿ“ž Questions?

- Open a [Discussion]https://github.com/anistark/wasmhub/discussions
- Ask on Discord (coming soon)
- Email: ani@anistark.com

## ๐Ÿ’ก Quick Reference

### Common Commands

Using justfile (recommended):

```sh
# Show all available commands
just --list

# Format code
just format

# Lint code
just lint

# Auto-fix lint issues
just lint-fix

# Check compilation
just check

# Build library
just build

# Build with all features
just build-all

# Run tests
just test

# Run all CI checks locally
just ci

# Install CLI globally
just install
```

Or using cargo directly:

```sh
# Build everything (library + CLI)
cargo build --all-features

# Run all tests
cargo test

# Format code
cargo fmt --all

# Lint code
cargo clippy --all-features

# Run CLI locally
cargo run --features cli -- list

# Check documentation
cargo doc --open

# Build release binary
cargo build --release --features cli
```

### Project Layout

- **src/lib.rs** - Public API for the library
- **src/bin/wasmhub.rs** - CLI application code
- **runtimes/** - Downloaded WASM runtime binaries
- **Cargo.toml** - Package manifest with `cli` feature flag

### Feature Flags

- **default** - Library only, no CLI
- **cli** - Includes CLI binary with `clap` argument parsing

Thank you for contributing! ๐ŸŽ‰