cargo-forge 0.1.5

An interactive Rust project generator with templates and common features
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# Cargo-Forge Troubleshooting Guide

This guide helps you resolve common issues when using Cargo-Forge.

## Table of Contents

- [Installation Issues]#installation-issues
- [Project Generation Errors]#project-generation-errors
- [Template Rendering Problems]#template-rendering-problems
- [Feature Compatibility Issues]#feature-compatibility-issues
- [Platform-Specific Problems]#platform-specific-problems
- [Performance Issues]#performance-issues
- [CI/CD Problems]#cicd-problems
- [Getting Help]#getting-help

## Installation Issues

### cargo-forge: command not found

**Problem**: After installing with `cargo install cargo-forge`, the command isn't recognized.

**Solution**:
```bash
# Check if cargo bin directory is in PATH
echo $PATH | grep -q ".cargo/bin" || echo "Cargo bin not in PATH"

# Add to PATH (add to ~/.bashrc or ~/.zshrc)
export PATH="$HOME/.cargo/bin:$PATH"

# Verify installation
which cargo-forge
cargo-forge --version
```

### Installation fails with linking errors

**Problem**: Compilation fails during installation.

**Solution**:
```bash
# Install system dependencies (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install pkg-config libssl-dev

# macOS
brew install openssl

# Windows - Install Visual Studio Build Tools
# Download from: https://visualstudio.microsoft.com/downloads/

# Retry installation
cargo install cargo-forge --locked
```

### Permission denied during installation

**Problem**: Cannot write to cargo directory.

**Solution**:
```bash
# Check permissions
ls -la ~/.cargo

# Fix permissions
chmod -R u+w ~/.cargo

# Alternative: Install to custom location
CARGO_INSTALL_ROOT=/custom/path cargo install cargo-forge
```

## Project Generation Errors

### "Failed to create project directory"

**Problem**: Cannot create the project directory.

**Causes & Solutions**:

1. **Directory already exists**
   ```bash
   # Check if directory exists
   ls my-project
   
   # Remove or use different name
   rm -rf my-project  # Careful!
   cargo-forge new my-project-v2
   ```

2. **No write permissions**
   ```bash
   # Check current directory permissions
   ls -la .
   
   # Create in writable location
   cd ~/projects
   cargo-forge new my-project
   ```

3. **Invalid project name**
   ```bash
   # Project names must be valid Rust identifiers
   # Bad: my-project!, 123project, my project
   # Good: my_project, my-project, project123
   ```

### "Template not found" error

**Problem**: Cargo-Forge cannot find template files.

**Solution**:
```bash
# Reinstall to ensure templates are included
cargo install cargo-forge --force

# Check installation integrity
cargo-forge --version

# If persists, report issue with:
cargo-forge new my-project --verbose
```

### "Failed to render template"

**Problem**: Template rendering fails with Tera errors.

**Common causes**:

1. **Special characters in input**
   ```bash
   # Avoid special characters in:
   # - Project name
   # - Author name (escape quotes)
   # - Description
   ```

2. **Missing required variables**
   ```bash
   # Use defaults or provide all required info
   cargo-forge new my-project \
     --author "Your Name" \
     --description "Project description"
   ```

## Template Rendering Problems

### Variables not replaced in generated files

**Problem**: See `{{ variable }}` in generated files.

**Solution**:
1. Check for typos in variable names
2. Ensure using `.tera` extension for templates
3. Verify template syntax:
   ```tera
   {# Correct #}
   {{ project_name }}
   
   {# Incorrect #}
   {{project_name}}    # Missing spaces
   {{ project name }}  # Space in variable name
   ```

### Conditional blocks not working

**Problem**: `{% if %}` blocks appear in output.

**Solution**:
```tera
{# Ensure proper syntax #}
{% if database %}
use sqlx::PgPool;
{% endif %}

{# Not: #}
{% if database = true %}  {# Wrong! #}
```

### Build fails after generation

**Problem**: Generated project doesn't compile.

**Debug steps**:
```bash
# Check generated Cargo.toml
cat my-project/Cargo.toml

# Verify dependencies are available
cd my-project
cargo check

# Update dependencies
cargo update

# Check for version conflicts
cargo tree
```

## Feature Compatibility Issues

### "Incompatible features selected"

**Problem**: Some feature combinations don't work together.

**Common incompatibilities**:
- WASM + Database (WASM can't use system databases)
- Embedded + Docker (Different deployment models)
- No-std + certain async runtimes

**Solution**: Choose compatible features or use workspace for separation.

### Database connection fails

**Problem**: Generated project can't connect to database.

**Solutions**:

1. **PostgreSQL**
   ```bash
   # Ensure PostgreSQL is running
   sudo systemctl status postgresql
   
   # Create database
   createdb my_project_db
   
   # Update .env
   DATABASE_URL=postgresql://user:pass@localhost/my_project_db
   ```

2. **MySQL**
   ```bash
   # Check MySQL service
   sudo systemctl status mysql
   
   # Create database
   mysql -u root -p -e "CREATE DATABASE my_project_db;"
   ```

3. **SQLite**
   ```bash
   # SQLite creates file automatically
   # Just ensure directory is writable
   DATABASE_URL=sqlite://./my_project.db
   ```

### Authentication not working

**Problem**: JWT/OAuth setup fails.

**Solutions**:

1. **Missing JWT secret**
   ```bash
   # Generate secure secret
   openssl rand -hex 32
   
   # Add to .env
   JWT_SECRET=your_generated_secret_here
   ```

2. **OAuth redirect URLs**
   ```bash
   # Update OAuth provider settings with:
   # Callback URL: http://localhost:3000/auth/callback
   ```

## Platform-Specific Problems

### Windows

#### Path separators in generated files

**Problem**: Backslashes in paths cause issues.

**Solution**: Cargo-Forge handles this automatically, but if issues persist:
```rust
// Use PathBuf for cross-platform paths
use std::path::PathBuf;
let path = PathBuf::from("assets").join("file.txt");
```

#### Line ending issues

**Problem**: CRLF vs LF conflicts.

**Solution**:
```bash
# Configure git
git config --global core.autocrlf true

# Or use .gitattributes
echo "* text=auto" > .gitattributes
```

### macOS

#### SSL certificate issues

**Problem**: Can't verify SSL certificates.

**Solution**:
```bash
# Update certificates
brew install ca-certificates

# Set environment variable
export SSL_CERT_FILE=/usr/local/etc/openssl/cert.pem
```

### Linux

#### Missing development headers

**Problem**: Compilation fails with missing headers.

**Solution**:
```bash
# Ubuntu/Debian
sudo apt-get install build-essential libssl-dev pkg-config

# Fedora
sudo dnf install gcc openssl-devel

# Arch
sudo pacman -S base-devel openssl
```

## Performance Issues

### Slow project generation

**Problem**: Takes too long to generate project.

**Solutions**:

1. **Disable virus scanner temporarily**
   - Windows Defender can slow file operations

2. **Use faster disk**
   ```bash
   # Generate in RAM disk if available
   cargo-forge new /tmp/my-project
   ```

3. **Skip optional features**
   ```bash
   # Minimal generation
   cargo-forge new my-project --non-interactive
   ```

### High memory usage

**Problem**: Cargo-Forge uses too much memory.

**Solution**:
- Close other applications
- Use `--dry-run` to preview without generation
- Report issue if consistent problem

## CI/CD Problems

### GitHub Actions workflow fails

**Problem**: Generated CI workflow has errors.

**Common fixes**:

1. **Rust version issues**
   ```yaml
   # Update .github/workflows/ci.yml
   - uses: dtolnay/rust-toolchain@stable
     with:
       toolchain: stable  # or specific version
   ```

2. **Missing secrets**
   ```yaml
   # Add to repository settings:
   # - CARGO_REGISTRY_TOKEN
   # - DOCKER_HUB_TOKEN
   ```

### GitLab CI pipeline errors

**Problem**: Pipeline fails with cache or runner issues.

**Solution**:
```yaml
# Update .gitlab-ci.yml
variables:
  CARGO_HOME: ${CI_PROJECT_DIR}/.cargo

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .cargo/
    - target/
```

## Common Error Messages

### "Error: Too many open files"

**Solution**:
```bash
# Increase file limit (temporary)
ulimit -n 4096

# Permanent (add to ~/.bashrc)
echo "ulimit -n 4096" >> ~/.bashrc
```

### "Error: Disk quota exceeded"

**Solution**:
```bash
# Check disk usage
df -h

# Clean cargo cache
cargo clean
rm -rf ~/.cargo/registry/cache
```

### "Error: Version conflict"

**Solution**:
```bash
# Update all dependencies
cargo update

# Or use specific versions
cargo update -p problematic-crate
```

## Debug Mode

Enable verbose output for troubleshooting:

```bash
# Set environment variable
export RUST_LOG=debug
export CARGO_FORGE_DEBUG=1

# Run with verbose flag
cargo-forge new my-project --verbose

# Capture full output
cargo-forge new my-project --verbose 2>&1 | tee forge-debug.log
```

## Reporting Issues

When reporting issues, include:

1. **System Information**
   ```bash
   cargo-forge --version
   rustc --version
   cargo --version
   uname -a  # or OS version
   ```

2. **Complete Error Message**
   ```bash
   cargo-forge new test-project 2>&1 | tee error.log
   ```

3. **Steps to Reproduce**
   - Exact commands used
   - Options selected
   - Expected vs actual behavior

4. **Debug Log**
   ```bash
   RUST_LOG=debug cargo-forge new test-project 2>&1 > debug.log
   ```

## Getting Help

### Resources

1. **Documentation**
   - README.md
   - [Online Docs]https://docs.rs/cargo-forge
   - Template examples

2. **Community**
   - [GitHub Discussions]https://github.com/marcuspat/cargo-forge/discussions
   - Stack Overflow - tag: cargo-forge

3. **Direct Support**
   - [Issue Tracker]https://github.com/marcuspat/cargo-forge/issues

### Quick Fixes Checklist

- [ ] Rust toolchain up to date?
- [ ] Cargo-Forge latest version?
- [ ] Valid project name?
- [ ] Sufficient disk space?
- [ ] Required system dependencies installed?
- [ ] Environment variables set correctly?
- [ ] File permissions correct?

### Emergency Recovery

If all else fails:

```bash
# Complete reinstall
cargo uninstall cargo-forge
rm -rf ~/.cargo/registry/cache/cargo-forge*
cargo install cargo-forge

# Manual template usage
git clone https://github.com/marcuspat/cargo-forge
cd cargo-forge/templates
# Manually copy and customize templates
```

Remember: Most issues have simple solutions. Check the basics first!