workspace_tools 0.12.0

Reliable workspace-relative path resolution for Rust projects. Automatically finds your workspace root and provides consistent file path handling regardless of execution context. Features memory-safe secret management, configuration loading with validation, and resource discovery.
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
# Task 012: Cargo Team Integration

**Priority**: ðŸ“Ķ Very High Impact  
**Phase**: 4 (Long-term Strategic)  
**Estimated Effort**: 12-18 months  
**Dependencies**: Task 001 (Cargo Integration), Task 010 (CLI Tool), proven ecosystem adoption  

## **Objective**
Collaborate with the Cargo team to integrate workspace_tools functionality directly into Cargo itself, making workspace path resolution a native part of the Rust toolchain and potentially reaching every Rust developer by default.

## **Strategic Approach**

### **Phase 1: Community Validation** (Months 1-6)
Before proposing integration, establish workspace_tools as the de-facto standard for workspace management in the Rust ecosystem.

**Success Metrics Needed:**
- 50k+ monthly downloads
- 2k+ GitHub stars  
- Integration in 5+ major Rust frameworks
- Positive community feedback and adoption
- Conference presentations and community validation

### **Phase 2: RFC Preparation** (Months 7-9)
Prepare a comprehensive RFC for workspace path resolution integration into Cargo.

### **Phase 3: Implementation & Collaboration** (Months 10-18)
Work with the Cargo team on implementation, testing, and rollout.

## **Technical Requirements**

### **Core Integration Proposal**
```rust
// Proposed Cargo workspace API integration
impl cargo::core::Workspace {
    /// Get workspace-relative path resolver
    pub fn path_resolver(&self) -> WorkspacePathResolver;
    
    /// Resolve workspace-relative paths in build scripts
    pub fn resolve_workspace_path<P: AsRef<Path>>(&self, path: P) -> PathBuf;
    
    /// Get standard workspace directories
    pub fn standard_directories(&self) -> StandardDirectories;
}

// New cargo subcommands
// cargo workspace info
// cargo workspace validate  
// cargo workspace create-dirs
// cargo workspace find <pattern>
```

### **Environment Variable Integration**
```toml
# Automatic injection into Cargo.toml build environment
[env]
WORKSPACE_ROOT = { value = ".", relative = true }
WORKSPACE_CONFIG_DIR = { value = "config", relative = true }
WORKSPACE_DATA_DIR = { value = "data", relative = true }
WORKSPACE_LOGS_DIR = { value = "logs", relative = true }
```

### **Build Script Integration**
```rust
// build.rs integration
fn main() {
    // Cargo would automatically provide these
    let workspace_root = std::env::var("WORKSPACE_ROOT").unwrap();
    let config_dir = std::env::var("WORKSPACE_CONFIG_DIR").unwrap();
    
    // Or through new cargo API
    let workspace = cargo::workspace();
    let config_path = workspace.resolve_path("config/build.toml");
}
```

## **Implementation Steps**

### **Phase 1: Community Building** (Months 1-6)

#### **Month 1-2: Ecosystem Integration**
```markdown
**Target Projects for Integration:**
- [ ] Bevy (game engine) - workspace-relative asset paths
- [ ] Axum/Tower (web) - configuration and static file serving  
- [ ] Tauri (desktop) - resource bundling and configuration
- [ ] cargo-dist - workspace-aware distribution
- [ ] cargo-generate - workspace template integration

**Approach:**
1. Contribute PRs adding workspace_tools support
2. Create framework-specific extension crates
3. Write migration guides and documentation
4. Present at framework-specific conferences
```

#### **Month 3-4: Performance and Reliability**
```rust
// Benchmark suite for cargo integration readiness
#[cfg(test)]
mod cargo_integration_benchmarks {
    use criterion::{black_box, criterion_group, criterion_main, Criterion};
    use workspace_tools::workspace;
    
    fn bench_workspace_resolution(c: &mut Criterion) {
        c.bench_function("workspace_resolution", |b| {
            b.iter(|| {
                let ws = workspace().unwrap();
                black_box(ws.root());
            })
        });
    }
    
    fn bench_path_joining(c: &mut Criterion) {
        let ws = workspace().unwrap();
        c.bench_function("path_joining", |b| {
            b.iter(|| {
                let path = ws.join("config/app.toml");
                black_box(path);
            })
        });
    }
    
    // Performance targets for cargo integration:
    // - Workspace resolution: < 1ms  
    // - Path operations: < 100Ξs
    // - Memory usage: < 1MB additional
    // - Zero impact on cold build times
}
```

#### **Month 5-6: Standardization**
```markdown
**Workspace Layout Standard Document:**

# Rust Workspace Layout Standard (RWLS)

## Standard Directory Structure
```
workspace-root/
├── Cargo.toml              # Workspace manifest
├── .cargo/                 # Cargo configuration (optional with native support)
├── config/                 # Application configuration
│   ├── {app}.toml         # Main application config  
│   ├── {app}.{env}.toml   # Environment-specific config
│   └── schema/            # Configuration schemas
├── data/                  # Application data and state
│   ├── cache/             # Cached data
│   └── state/             # Persistent state
├── logs/                  # Application logs
├── docs/                  # Project documentation
│   ├── api/               # API documentation
│   └── guides/            # User guides  
├── tests/                 # Integration tests
│   ├── fixtures/          # Test data
│   └── e2e/              # End-to-end tests
├── scripts/               # Build and utility scripts  
├── assets/                # Static assets (web, game, desktop)
└── .workspace/            # Workspace metadata
    ├── templates/         # Project templates
    └── plugins/           # Workspace plugins
```

## Environment Variables (Cargo Native)
- `WORKSPACE_ROOT` - Absolute path to workspace root
- `WORKSPACE_CONFIG_DIR` - Absolute path to config directory
- `WORKSPACE_DATA_DIR` - Absolute path to data directory
- `WORKSPACE_LOGS_DIR` - Absolute path to logs directory

## Best Practices
1. Use relative paths in configuration files
2. Reference workspace directories through environment variables
3. Keep workspace-specific secrets in `.workspace/secrets/`
4. Use consistent naming conventions across projects
```

### **Phase 2: RFC Development** (Months 7-9)

#### **Month 7: RFC Draft**
```markdown
# RFC: Native Workspace Path Resolution in Cargo

## Summary
Add native workspace path resolution capabilities to Cargo, eliminating the need for external crates and providing a standard foundation for workspace-relative path operations in the Rust ecosystem.

## Motivation
Currently, Rust projects struggle with runtime path resolution relative to workspace roots. This leads to:
- Fragile path handling that breaks based on execution context
- Inconsistent project layouts across the ecosystem  
- Need for external dependencies for basic workspace operations
- Complex configuration management in multi-environment deployments

## Detailed Design

### Command Line Interface
```bash
# New cargo subcommands
cargo workspace info                    # Show workspace information
cargo workspace validate              # Validate workspace structure
cargo workspace create-dirs           # Create standard directories
cargo workspace find <pattern>        # Find resources with patterns
cargo workspace path <relative-path>  # Resolve workspace-relative path
```

### Environment Variables
Cargo will automatically inject these environment variables:
```bash
CARGO_WORKSPACE_ROOT=/path/to/workspace
CARGO_WORKSPACE_CONFIG_DIR=/path/to/workspace/config  
CARGO_WORKSPACE_DATA_DIR=/path/to/workspace/data
CARGO_WORKSPACE_LOGS_DIR=/path/to/workspace/logs
CARGO_WORKSPACE_DOCS_DIR=/path/to/workspace/docs
CARGO_WORKSPACE_TESTS_DIR=/path/to/workspace/tests
```

### Rust API
```rust
// New std::env functions
pub fn workspace_root() -> Option<PathBuf>;
pub fn workspace_dir(name: &str) -> Option<PathBuf>;

// Or through cargo metadata
use cargo_metadata::MetadataCommand;
let metadata = MetadataCommand::new().exec().unwrap();
let workspace_root = metadata.workspace_root;
```

### Build Script Integration
```rust
// build.rs
use std::env;
use std::path::Path;

fn main() {
    // Automatically available
    let workspace_root = env::var("CARGO_WORKSPACE_ROOT").unwrap();
    let config_dir = env::var("CARGO_WORKSPACE_CONFIG_DIR").unwrap();
    
    // Use for build-time path resolution
    let schema_path = Path::new(&config_dir).join("schema.json");
    println!("cargo:rerun-if-changed={}", schema_path.display());
}
```

### Cargo.toml Configuration
```toml
[workspace]
members = ["crate1", "crate2"]

# New workspace configuration section
[workspace.layout]
config_dir = "config"           # Default: "config"
data_dir = "data"               # Default: "data"  
logs_dir = "logs"               # Default: "logs"
docs_dir = "docs"               # Default: "docs"
tests_dir = "tests"             # Default: "tests"

# Custom directories
[workspace.layout.custom]
assets_dir = "assets"
scripts_dir = "scripts"
```

## Rationale and Alternatives

### Why integrate into Cargo?
1. **Universal Access**: Every Rust project uses Cargo
2. **Zero Dependencies**: No external crates needed
3. **Consistency**: Standard behavior across all projects
4. **Performance**: Native implementation optimized for build process
5. **Integration**: Seamless integration with existing Cargo features

### Alternative: Keep as External Crate
- **Pros**: Faster iteration, no cargo changes needed
- **Cons**: Requires dependency, not universally available, inconsistent adoption

### Alternative: New Standard Library Module
- **Pros**: Part of core Rust
- **Cons**: Longer RFC process, less Cargo integration

## Prior Art
- **Node.js**: `__dirname`, `process.cwd()`, package.json resolution
- **Python**: `__file__`, `sys.path`, setuptools workspace detection
- **Go**: `go mod` workspace detection and path resolution
- **Maven/Gradle**: Standard project layouts and path resolution

## Unresolved Questions
1. Should this be opt-in or enabled by default?
2. How to handle backwards compatibility?
3. What's the migration path for existing external solutions?
4. Should we support custom directory layouts?

## Future Extensions
- Workspace templates and scaffolding
- Multi-workspace (monorepo) support
- IDE integration hooks
- Plugin system for workspace extensions
```

#### **Month 8-9: RFC Refinement**
- Present RFC to Cargo team for initial feedback
- Address technical concerns and implementation details
- Build consensus within the Rust community
- Create prototype implementation

### **Phase 3: Implementation** (Months 10-18)

#### **Month 10-12: Prototype Development**
```rust
// Prototype implementation in Cargo
// src/cargo/core/workspace_path.rs

use std::path::{Path, PathBuf};
use anyhow::Result;

pub struct WorkspacePathResolver {
    workspace_root: PathBuf,
    standard_dirs: StandardDirectories,
}

impl WorkspacePathResolver {
    pub fn new(workspace_root: PathBuf) -> Self {
        let standard_dirs = StandardDirectories::new(&workspace_root);
        Self {
            workspace_root,
            standard_dirs,
        }
    }
    
    pub fn resolve<P: AsRef<Path>>(&self, relative_path: P) -> PathBuf {
        self.workspace_root.join(relative_path)
    }
    
    pub fn config_dir(&self) -> &Path {
        &self.standard_dirs.config
    }
    
    pub fn data_dir(&self) -> &Path {
        &self.standard_dirs.data
    }
    
    // ... other standard directories
}

#[derive(Debug)]
pub struct StandardDirectories {
    pub config: PathBuf,
    pub data: PathBuf,
    pub logs: PathBuf,
    pub docs: PathBuf,
    pub tests: PathBuf,
}

impl StandardDirectories {
    pub fn new(workspace_root: &Path) -> Self {
        Self {
            config: workspace_root.join("config"),
            data: workspace_root.join("data"),
            logs: workspace_root.join("logs"),
            docs: workspace_root.join("docs"),
            tests: workspace_root.join("tests"),
        }
    }
}

// Integration with existing Cargo workspace
impl cargo::core::Workspace<'_> {
    pub fn path_resolver(&self) -> WorkspacePathResolver {
        WorkspacePathResolver::new(self.root().to_path_buf())
    }
}
```

#### **Month 13-15: Core Implementation**
- Implement environment variable injection
- Add new cargo subcommands
- Integrate with build script environment
- Add workspace layout configuration parsing

#### **Month 16-18: Testing and Rollout**
- Comprehensive testing across different project types
- Performance benchmarking and optimization
- Documentation and migration guides
- Gradual rollout with feature flags

## **Success Metrics**

### **Technical Metrics**
- [ ] RFC accepted by Cargo team
- [ ] Prototype implementation working
- [ ] Zero performance impact on build times
- [ ] Full backwards compatibility maintained
- [ ] Integration tests pass for major project types

### **Ecosystem Impact**
- [ ] Major frameworks adopt native workspace resolution
- [ ] External workspace_tools usage begins migration
- [ ] IDE integration updates to use native features
- [ ] Community tutorials and guides created

### **Adoption Metrics**
- [ ] Feature used in 50%+ of new Cargo projects within 1 year
- [ ] Positive feedback from major project maintainers
- [ ] Integration featured in Rust blog and newsletters
- [ ] Presented at RustConf and major Rust conferences

## **Risk Mitigation**

### **Technical Risks**
- **Performance Impact**: Extensive benchmarking and optimization
- **Backwards Compatibility**: Careful feature flag design
- **Complexity**: Minimal initial implementation, iterate based on feedback

### **Process Risks**  
- **RFC Rejection**: Build stronger community consensus first
- **Implementation Delays**: Contribute development resources to Cargo team
- **Maintenance Burden**: Design for minimal ongoing maintenance

### **Ecosystem Risks**
- **Fragmentation**: Maintain external crate during transition
- **Migration Complexity**: Provide automated migration tools
- **Alternative Standards**: Stay engaged with broader ecosystem discussions

## **Rollout Strategy**

### **Pre-Integration (Months 1-6)**
1. Maximize workspace_tools adoption and validation
2. Build relationships with Cargo team members
3. Gather detailed ecosystem usage data
4. Create comprehensive benchmarking suite

### **RFC Process (Months 7-9)**
1. Submit RFC with extensive community validation
2. Present at Rust team meetings and working groups
3. Address feedback and iterate on design
4. Build consensus among key stakeholders

### **Implementation (Months 10-18)**
1. Collaborate closely with Cargo maintainers
2. Provide development resources and expertise
3. Ensure thorough testing and documentation
4. Plan gradual rollout with feature flags

### **Post-Integration (Ongoing)**
1. Support migration from external solutions
2. Maintain compatibility and handle edge cases
3. Gather feedback and plan future enhancements
4. Evangelize best practices and standard layouts

## **Long-term Vision**

If successful, this integration would make workspace_tools obsolete as a separate crate while establishing workspace path resolution as a fundamental part of the Rust development experience. Every Rust developer would have access to reliable, consistent workspace management without additional dependencies.

**Ultimate Success**: Being mentioned in the Rust Book as the standard way to handle workspace-relative paths, similar to how `cargo test` or `cargo doc` are presented as fundamental Rust toolchain capabilities.

This task represents the highest strategic impact for workspace_tools - transforming it from a useful crate into a permanent part of the Rust ecosystem.