vx-tool-rust 0.2.3

Rust tool support for vx
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# vx-tool-rust


[![Crates.io](https://img.shields.io/crates/v/vx-tool-rust.svg)](https://crates.io/crates/vx-tool-rust)
[![Documentation](https://docs.rs/vx-tool-rust/badge.svg)](https://docs.rs/vx-tool-rust)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Rust programming language tool support for the vx universal tool manager.

## Overview


`vx-tool-rust` provides Rust programming language support for vx, enabling automatic installation, version management, and execution of Rust toolchain commands through the vx interface.

## Features


- **Rust Toolchain**: Complete Rust compiler and tools
- **Cargo Integration**: Built-in Cargo package manager and build tool
- **Auto-Installation**: Automatic download and installation of Rust versions
- **Cross-Platform**: Windows, macOS, and Linux support
- **Version Management**: Install and switch between multiple Rust versions
- **Target Support**: Cross-compilation for multiple targets
- **Component Management**: Install additional Rust components

## Supported Commands


### Rust Compiler

```bash
# Compile Rust code

vx rustc main.rs
vx rustc --version
vx rustc --explain E0308

# Check code without building

vx rustc --emit=metadata main.rs
```

### Cargo Package Manager

```bash
# Project management

vx cargo new myproject
vx cargo init
vx cargo build
vx cargo run

# Testing

vx cargo test
vx cargo test --release
vx cargo bench

# Package management

vx cargo add serde
vx cargo remove serde
vx cargo update
```

### Development Tools

```bash
# Code formatting

vx cargo fmt
vx cargo fmt --check

# Linting

vx cargo clippy
vx cargo clippy -- -D warnings

# Documentation

vx cargo doc
vx cargo doc --open

# Publishing

vx cargo publish
vx cargo package
```

## Installation


### Through vx CLI

```bash
# Install latest stable

vx install rust

# Install specific version

vx install rust@1.75.0
vx install rust@1.74.1

# Install latest version

vx install rust@latest
```

### Version Constraints

```bash
# Semantic version ranges

vx install rust@^1.75.0   # Latest 1.75.x
vx install rust@~1.75.0   # Latest 1.75.0.x
vx install rust@>=1.70.0  # 1.70.0 or higher
```

## Configuration


### Project Configuration (.vx.toml)

```toml
[tools]
rust = "1.75.0"           # Specific version
# rust = "stable"         # Latest stable

# rust = "beta"           # Beta channel

# rust = "nightly"        # Nightly channel


[tools.rust]
auto_install = true
default_target = "x86_64-unknown-linux-gnu"
```

### Global Configuration

```toml
[tools.rust]
default_version = "stable"
auto_install = true
install_timeout = 600

[rust.settings]
default_toolchain = "stable"
profile = "default"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
```

## Toolchain Management


### Channels

- **stable**: Latest stable release (recommended)
- **beta**: Beta releases (6-week cycle)
- **nightly**: Nightly builds (daily)

### Components

```bash
# Install additional components

vx rustup component add rustfmt
vx rustup component add clippy
vx rustup component add rust-src
vx rustup component add rust-analyzer

# List components

vx rustup component list
vx rustup component list --installed
```

### Targets

```bash
# Add compilation targets

vx rustup target add wasm32-unknown-unknown
vx rustup target add x86_64-pc-windows-gnu
vx rustup target add aarch64-apple-darwin

# List targets

vx rustup target list
vx rustup target list --installed
```

## Platform Support


### Windows

- **x64**: Full support
- **x86**: Legacy support
- **ARM64**: Windows 11 ARM support

### macOS

- **x64**: Intel Mac support
- **ARM64**: Apple Silicon (M1/M2) support

### Linux

- **x64**: All major distributions
- **ARM64**: ARM-based systems
- **ARMv7**: Raspberry Pi support

## Cross-Compilation


### Common Targets

```bash
# WebAssembly

vx rustup target add wasm32-unknown-unknown
vx cargo build --target wasm32-unknown-unknown

# Windows from Linux

vx rustup target add x86_64-pc-windows-gnu
vx cargo build --target x86_64-pc-windows-gnu

# macOS from Linux

vx rustup target add x86_64-apple-darwin
vx cargo build --target x86_64-apple-darwin
```

### Build Configuration

```toml
# .cargo/config.toml

[build]
target = "x86_64-unknown-linux-gnu"

[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

[target.wasm32-unknown-unknown]
runner = "wasm-pack"
```

## Integration


### With vx-core

```rust
use vx_core::{Tool, ToolManager};
use vx_tool_rust::RustTool;

let rust_tool = RustTool::new();
let manager = ToolManager::new();

// Install Rust
manager.install_tool(&rust_tool, "1.75.0").await?;

// Execute Rust commands
manager.execute_tool(&rust_tool, &["--version"]).await?;
```

### Plugin Registration

```rust
use vx_core::{Plugin, PluginManager};
use vx_tool_rust::RustPlugin;

let plugin = RustPlugin::new();
let mut manager = PluginManager::new();

manager.register_plugin(Box::new(plugin))?;
```

## Development


### Building

```bash
cd crates/vx-tool-rust
cargo build
```

### Testing

```bash
cargo test
```

### Integration Testing

```bash
# Test with actual Rust installation

cargo test --features integration-tests
```

## Implementation Details


### Tool Structure

- **RustTool**: Main Rust compiler (rustc)
- **CargoTool**: Cargo package manager and build tool
- **RustupTool**: Rustup toolchain manager

### Version Resolution

1. **Project Config**: Check `.vx.toml` for version specification
2. **Global Config**: Fall back to global default
3. **Stable Channel**: Use latest stable if no version specified
4. **Auto-Install**: Download and install if not available

### Installation Process

1. **Rustup Download**: Download rustup installer
2. **Toolchain Install**: Install specified Rust version
3. **Component Setup**: Install default components
4. **Verification**: Verify installation integrity
5. **Environment Setup**: Configure CARGO_HOME and RUSTUP_HOME

## Project Templates


### Binary Application

```bash
# Create new binary project

vx cargo new myapp
cd myapp

# Add dependencies

vx cargo add clap serde

# Build and run

vx cargo build
vx cargo run
```

### Library Crate

```bash
# Create new library

vx cargo new --lib mylib
cd mylib

# Add dependencies

vx cargo add serde --features derive

# Test

vx cargo test
```

### WebAssembly Project

```bash
# Install wasm target

vx rustup target add wasm32-unknown-unknown

# Create project

vx cargo new --lib wasm-project
cd wasm-project

# Configure for wasm

cat >> Cargo.toml << EOF
[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
EOF

# Build for wasm

vx cargo build --target wasm32-unknown-unknown
```

## Error Handling


### Common Errors

- **Network Issues**: Download failures, registry timeouts
- **Permission Errors**: Installation directory access
- **Compilation Errors**: Code compilation failures
- **Dependency Conflicts**: Cargo dependency resolution

### Recovery

```bash
# Reinstall Rust

vx install rust@1.75.0 --force

# Clear Cargo cache

vx cargo clean

# Update dependencies

vx cargo update

# Use system Rust as fallback

vx --use-system-path cargo --version
```

## Performance


- **Fast Compilation**: Rust's efficient compilation
- **Incremental Builds**: Cargo's incremental compilation
- **Parallel Downloads**: Concurrent dependency downloads
- **Build Caching**: Shared build cache across projects

## Security


- **Checksum Verification**: SHA256 verification of downloads
- **HTTPS Only**: Secure downloads from official sources
- **Crate Verification**: Cargo registry verification
- **Sandboxed Builds**: Isolated build environments

## Troubleshooting


### Installation Issues

```bash
# Check Rust installation

vx rustc --version
vx cargo --version

# Verify toolchain

vx rustup show

# Check environment

vx rustup which rustc
vx rustup which cargo

# Force reinstall

vx remove rust@1.75.0
vx install rust@1.75.0
```

### Build Issues

```bash
# Check project

vx cargo check

# Clean build

vx cargo clean
vx cargo build

# Update dependencies

vx cargo update

# Debug build

vx cargo build --verbose
```

### Component Issues

```bash
# List components

vx rustup component list --installed

# Reinstall component

vx rustup component remove rustfmt
vx rustup component add rustfmt

# Update toolchain

vx rustup update
```

## Best Practices


### Project Structure

```
myproject/
├── Cargo.toml
├── Cargo.lock
├── src/
│   ├── main.rs
│   └── lib.rs
├── tests/
│   └── integration_test.rs
├── benches/
│   └── benchmark.rs
└── examples/
    └── example.rs
```

### Cargo.toml Configuration

```toml
[package]
name = "myproject"
version = "0.1.0"
edition = "2021"
rust-version = "1.70"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = ["full"] }

[dev-dependencies]
criterion = "0.5"

[[bench]]
name = "my_benchmark"
harness = false
```

## License


This project is licensed under the MIT License - see the [LICENSE](../../../LICENSE) file for details.

## Contributing


Contributions are welcome! Please see the [contributing guidelines](../../../CONTRIBUTING.md) for more information.

## Related Crates


- [`vx-core`]../../vx-core/README.md - Core functionality
- [`vx-cli`]../../vx-cli/README.md - Command-line interface
- [`vx-tool-node`]../vx-tool-node/README.md - Node.js tool
- [`vx-tool-go`]../vx-tool-go/README.md - Go tool