wrtype 0.1.0

A Rust implementation of wtype - a Wayland virtual keyboard tool that types text and sends key events
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
# Building from Source

This guide covers building wrtype from source code for development, customization, or contributing to the project.

## Prerequisites

### System Requirements

- **Rust** 1.70.0 or later
- **Git** for source control
- **pkg-config** for dependency discovery
- **Wayland development libraries**

### Rust Installation

Install Rust through rustup (recommended):

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
rustup update
```

### System Dependencies

**Ubuntu/Debian:**
```bash
sudo apt install \
    git \
    pkg-config \
    libwayland-dev \
    wayland-protocols \
    libxkbcommon-dev \
    build-essential
```

**Fedora/CentOS:**
```bash
sudo dnf install \
    git \
    pkgconf-pkg-config \
    wayland-devel \
    wayland-protocols-devel \
    libxkbcommon-devel \
    gcc
```

**Arch Linux:**
```bash
sudo pacman -S \
    git \
    pkgconf \
    wayland \
    wayland-protocols \
    libxkbcommon \
    base-devel
```

## Getting the Source

Clone the repository:

```bash
git clone https://github.com/conneroisu/wrtype.git
cd wrtype
```

### Repository Structure

```
wrtype/
├── src/           # Rust source code
│   ├── main.rs    # CLI and orchestration
│   ├── wayland.rs # Wayland protocol implementation
│   ├── keymap.rs  # XKB keymap generation
│   └── executor.rs# Command execution engine
├── docs/          # Documentation source
├── wtype/         # Original C implementation (reference)
├── Cargo.toml     # Rust dependencies and metadata
├── flake.nix      # Nix development environment
└── README.md      # Project overview
```

## Building with Cargo

### Development Build

```bash
# Build debug version (faster compilation, slower runtime)
cargo build

# Run directly without installing
cargo run -- "Hello from development build!"
```

### Release Build

```bash
# Build optimized release version
cargo build --release

# Binary will be at target/release/wrtype
./target/release/wrtype --version
```

### Running Tests

```bash
# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test test_name
```

### Code Quality

```bash
# Check code without building
cargo check

# Format code
cargo fmt

# Run linter
cargo clippy

# Generate documentation
cargo doc --open
```

## Building with Nix (Recommended)

### Development Environment

```bash
# Enter development shell with all dependencies
nix develop

# Or with direnv (if configured)
direnv allow
```

### Available Commands in Nix Shell

```bash
# Build the project
cargo build --release

# Run with hot reloading
cargo watch -x run

# Format all code
cargo fmt

# Check for issues
cargo clippy
```

### Building Documentation

```bash
# Build documentation site
nix build .#docs

# View built documentation
firefox result/index.html
```

## Development Workflow

### 1. Setup Development Environment

```bash
git clone https://github.com/conneroisu/wrtype.git
cd wrtype
nix develop  # or install dependencies manually
```

### 2. Make Changes

```bash
# Edit source files
$EDITOR src/main.rs

# Check compilation
cargo check
```

### 3. Test Changes

```bash
# Run tests
cargo test

# Test manually
cargo run -- "test input"

# Test with different options
cargo run -- -d 100 "slow typing"
```

### 4. Quality Checks

```bash
# Format code
cargo fmt

# Check for issues
cargo clippy

# Run full test suite
cargo test --release
```

### 5. Documentation

```bash
# Generate and view docs
cargo doc --open

# Build documentation site
cd docs && mdbook build
```

## Custom Builds

### Feature Flags

Currently wrtype doesn't use feature flags, but they can be added for optional functionality:

```toml
# In Cargo.toml
[features]
default = []
debug-protocol = []  # Enable protocol debugging
experimental = []    # Enable experimental features
```

### Cross Compilation

Build for different architectures:

```bash
# Install target
rustup target add aarch64-unknown-linux-gnu

# Cross compile (requires cross-compilation toolchain)
cargo build --target aarch64-unknown-linux-gnu --release
```

### Optimization Profiles

Customize build profiles in `Cargo.toml`:

```toml
[profile.release]
lto = true           # Link-time optimization
codegen-units = 1    # Better optimization
panic = "abort"      # Smaller binary
strip = true         # Remove debug symbols
```

## Debugging Builds

### Debug Information

```bash
# Build with debug info
cargo build

# Run with debugger
gdb target/debug/wrtype
rust-gdb target/debug/wrtype
```

### Environment Variables

```bash
# Enable Rust backtraces
RUST_BACKTRACE=1 cargo run -- "test"

# Enable full backtraces
RUST_BACKTRACE=full cargo run -- "test"

# Enable logging (if implemented)
RUST_LOG=debug cargo run -- "test"
```

### Wayland Debugging

```bash
# Enable Wayland debugging
WAYLAND_DEBUG=1 cargo run -- "test"

# Check available protocols
wayland-info | grep virtual_keyboard
```

## Common Build Issues

### Missing Dependencies

**Error:** `pkg-config` not found
```bash
# Install pkg-config
sudo apt install pkg-config  # Ubuntu/Debian
sudo dnf install pkgconf     # Fedora
```

**Error:** Wayland libraries not found
```bash
# Install Wayland development packages
sudo apt install libwayland-dev wayland-protocols
```

### Rust Version Issues

**Error:** Minimum supported Rust version
```bash
# Update Rust
rustup update

# Check version
rustc --version
```

### Linker Issues

**Error:** Cannot find linker
```bash
# Install build tools
sudo apt install build-essential  # Ubuntu/Debian
sudo dnf install gcc             # Fedora
```

## Performance Builds

### Maximum Optimization

```bash
# Use highest optimization level
RUSTFLAGS="-C target-cpu=native" cargo build --release

# Profile-guided optimization (advanced)
cargo build --release
# Run with representative workload to generate profile data
RUSTFLAGS="-C profile-use=profile.profdata" cargo build --release
```

### Size Optimization

```bash
# Optimize for size
RUSTFLAGS="-C opt-level=z" cargo build --release

# Use system allocator (smaller binary)
# Add to main.rs:
# #[global_allocator]
# static ALLOC: std::alloc::System = std::alloc::System;
```

## Contributing Builds

### Before Submitting

```bash
# Run full test suite
cargo test --release

# Check formatting
cargo fmt --check

# Check for clippy warnings
cargo clippy -- -D warnings

# Verify documentation builds
cargo doc --no-deps

# Test on multiple Wayland compositors if possible
```

### Continuous Integration

The project uses GitHub Actions for CI. Local verification:

```bash
# Run CI-equivalent checks
cargo check --all-targets
cargo test --all
cargo fmt --check
cargo clippy --all-targets -- -D warnings
```

## Packaging

### Creating Release Binary

```bash
# Build optimized release
cargo build --release

# Strip debug symbols
strip target/release/wrtype

# Verify binary
ldd target/release/wrtype
file target/release/wrtype
```

### Debian Package

```bash
# Install cargo-deb
cargo install cargo-deb

# Create .deb package
cargo deb
```

### RPM Package

```bash
# Install cargo-rpm
cargo install cargo-rpm

# Create .rpm package
cargo rpm build
```

This comprehensive build guide should help you successfully build wrtype from source for any purpose, whether development, customization, or distribution.