Skip to content

Commit c07be7d

Browse files
authored
Merge pull request #74 from golemcloud/fetch-improvements
Fetch improvements
2 parents 7b6a930 + 775929b commit c07be7d

File tree

13 files changed

+3352
-332
lines changed

13 files changed

+3352
-332
lines changed

AGENTS.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# AGENTS.md - wasm-rquickjs Development Guide
2+
3+
## Project Overview
4+
5+
**wasm-rquickjs** is a command-line tool and library that wraps JavaScript code into WebAssembly Components using the QuickJS engine. The tool generates self-contained Rust crates that compile to WASM components.
6+
7+
## Project Structure
8+
9+
```
10+
wasm-rquickjs/
11+
├── crates/
12+
│ ├── wasm-rquickjs/ # Main library crate
13+
│ │ ├── skeleton/ # Embedded skeleton crate (separate project)
14+
│ │ └── src/
15+
│ └── wasi-logging/ # WASI logging support crate
16+
├── examples/ # Example projects
17+
├── src/ # CLI binary source (main.rs)
18+
├── tests/ # Integration tests
19+
├── Cargo.toml # Workspace root
20+
├── cleanup-skeleton.sh # Script to clean skeleton build artifacts
21+
└── README.md # Main documentation
22+
```
23+
24+
## Important Notes About @crates/wasm-rquickjs/skeleton
25+
26+
The `skeleton` crate is a **separate project** that is embedded within the `wasm-rquickjs` crate. It is crucial to understand the following:
27+
28+
### Cargo.toml Naming Convention
29+
30+
**The skeleton's `Cargo.toml` MUST be renamed to `Cargo.toml_` in the repository.**
31+
32+
- The file is stored as `Cargo.toml_` to avoid conflicts with Rust packaging when embedded
33+
- When working on the skeleton locally, rename it to `Cargo.toml` before building
34+
- Before committing changes back, rename it back to `Cargo.toml_`
35+
- The embedded file in the final package uses the renamed `Cargo.toml_`
36+
37+
### Building and Testing the Skeleton
38+
39+
The skeleton crate can be compiled separately from the main project:
40+
41+
```bash
42+
cd crates/wasm-rquickjs/skeleton
43+
44+
# Rename Cargo.toml_ to Cargo.toml for local development
45+
mv Cargo.toml_ Cargo.toml
46+
47+
# Build/test the skeleton
48+
cargo build
49+
cargo test
50+
51+
# Rename back before committing
52+
mv Cargo.toml Cargo.toml_
53+
```
54+
55+
### Runtime tests
56+
To test the builtin module of the skeleton, first define an example in `examples`, consisting of a pair of a JS file and a WIT interface,
57+
and then add one or more tests in `tests/runtime.rs` that use the example.
58+
59+
### Cleaning Skeleton Build Artifacts
60+
61+
After compiling the skeleton for testing, **always clean its build artifacts** before compiling the main `wasm-rquickjs` crate:
62+
63+
```bash
64+
./cleanup-skeleton.sh
65+
```
66+
67+
**Why?** The `include_dir!` macro embeds the entire skeleton directory into the main package during compilation. If the skeleton's `target/` directory is present, it will be embedded, causing:
68+
- Dramatically slower compilation times
69+
- Significantly larger resulting binaries
70+
71+
## Build Commands
72+
73+
### Build the CLI binary
74+
```bash
75+
cargo build --release
76+
```
77+
78+
### Run tests
79+
```bash
80+
cargo test
81+
```
82+
83+
### Build specific test harness
84+
```bash
85+
cargo test --test compilation
86+
cargo test --test runtime
87+
cargo test --test dts
88+
cargo test --test errors
89+
```
90+
91+
### Generate code for a JavaScript module
92+
```bash
93+
./target/release/wasm-rquickjs generate-wrapper-crate \
94+
--js <path/to/module.js> \
95+
--wit <path/to/wit/root> \
96+
--output <output/directory>
97+
```
98+
99+
### Generate TypeScript definitions
100+
```bash
101+
./target/release/wasm-rquickjs generate-dts \
102+
--wit <path/to/wit/root> \
103+
--output <output/directory>
104+
```
105+
106+
## Code Quality
107+
108+
### Formatting
109+
110+
The project uses `rustfmt` for code formatting. Before committing, ensure code is formatted:
111+
112+
```bash
113+
cargo fmt
114+
```
115+
116+
To check formatting without making changes:
117+
118+
```bash
119+
cargo fmt -- --check
120+
```
121+
122+
### Clippy Linting
123+
124+
The project uses Clippy with strict warnings enabled. All warnings must be fixed:
125+
126+
```bash
127+
cargo clippy -- -Dwarnings
128+
```
129+
130+
To fix common issues automatically:
131+
132+
```bash
133+
cargo clippy --fix -- -Dwarnings
134+
```
135+
136+
### Pre-commit Checks
137+
138+
Run all quality checks before committing:
139+
140+
```bash
141+
cargo fmt
142+
cargo clippy -- -Dwarnings
143+
cargo test
144+
```
145+
146+
## Workspace Configuration
147+
148+
The workspace is configured in the root `Cargo.toml` with the following members:
149+
- `crates/wasi-logging` - WASI logging support
150+
- `crates/wasm-rquickjs` - Main library crate
151+
152+
**Excluded from workspace:**
153+
- `crates/wasm-rquickjs/skeleton` - Separate project, compiled independently
154+
- `tmp/` - Temporary build artifacts
155+
156+
## Development Workflow
157+
158+
### When working on the skeleton (JavaScript APIs, core functionality):
159+
160+
1. Navigate to the skeleton directory
161+
2. Rename `Cargo.toml_` to `Cargo.toml`
162+
3. Make changes and test with `cargo build`/`cargo test`
163+
4. When done, run from the repo root: `./cleanup-skeleton.sh`
164+
5. Rename skeleton's `Cargo.toml` back to `Cargo.toml_`
165+
6. Commit your changes
166+
167+
### When working on code generation:
168+
169+
1. Modify the main `crates/wasm-rquickjs` crate
170+
2. Run tests with `cargo test`
171+
3. Changes to the skeleton will be embedded via `include_dir!` at compile time
172+
173+
### When working on the CLI:
174+
175+
1. Modify `src/main.rs`
176+
2. Build with `cargo build --release`
177+
3. Test with `cargo test --test compilation` or `cargo test --test runtime`
178+
179+
## Key Files
180+
181+
- `src/main.rs` - CLI entry point
182+
- `crates/wasm-rquickjs/src/` - Code generation logic
183+
- `crates/wasm-rquickjs/skeleton/src/` - JavaScript runtime APIs
184+
- `tests/` - Integration tests for compilation, runtime, DTS generation, and error handling
185+
186+
## Features
187+
188+
The generated crates support feature flags:
189+
- `logging` - Enable `wasi:logging` for JavaScript console API
190+
- `http` - Enable `wasi:http` for JavaScript fetch API
191+
192+
Both features are enabled by default in generated crates.
193+
194+
## Dependencies
195+
196+
Key external dependencies:
197+
- `rquickjs` - QuickJS Rust bindings
198+
- `wit-parser` / `wit-encoder` - WebAssembly Interface Type support
199+
- `wasmtime` - WASM runtime for testing
200+
- `cargo-component` - WASM component compilation (for end users)

Cargo.lock

Lines changed: 46 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ rand = "0.9.2"
9797
serde = "1.0.219"
9898
serde_json = "1.0.142"
9999
syn = "2.0.101"
100-
test-r = "2.2.0"
100+
test-r = "2.3.1"
101101
tokio = "1.47.1"
102102
tokio-util = "0.7.16"
103103
toml_edit = "0.22.27"

0 commit comments

Comments
 (0)