# Spec 0015: Move version.rs Generation to OUT_DIR
## Problem
Currently, `build.rs` generates `src/version.rs` at build time based on git history. This creates a git tracking problem:
- The file needs to exist for linters/IDEs to be happy
- But we don't want to commit build-time generated changes
- Users would need manual git configuration (`--assume-unchanged`) which doesn't propagate
## Solution
Use the same pattern as `generated_models.rs`: write `version.rs` to `OUT_DIR` and include it via the `include!` macro.
## Current Implementation
**build.rs:**
```rust
// Generate version module
let version_info = get_version_info();
let version_code = generate_version_module(&version_info);
fs::write("src/version.rs", version_code).expect("Failed to write version.rs");
```
**src/main.rs:**
```rust
pub mod version;
```
**src/version.rs:**
```rust
// Auto-generated by build.rs - do not edit
// NOTE: This will be overwritten during build with the real version information
pub const VERSION: &str = "...";
// ... rest of module
```
## Proposed Implementation
**build.rs changes:**
```rust
// Generate version module to OUT_DIR (same as generated_models.rs)
let version_info = get_version_info();
let version_code = generate_version_module(&version_info);
let version_path = Path::new(&out_dir).join("version.rs");
fs::write(&version_path, version_code).expect("Failed to write version.rs");
```
**src/main.rs changes:**
```rust
// Include version module from OUT_DIR (same pattern as models/mod.rs)
pub mod version {
include!(concat!(env!("OUT_DIR"), "/version.rs"));
}
```
**Remove src/version.rs:**
- Delete the file from the repository
- No placeholder needed
- No git tracking issues
## Benefits
1. **Consistency**: Uses the same pattern as `generated_models.rs`
2. **No git issues**: File is never in the source tree
3. **No manual setup**: Works automatically for all users
4. **Clean**: No placeholder files or git configuration needed
5. **IDE-friendly**: File exists after first build, IDEs can find it
## Implementation Steps
1. ✅ Analyze current usage (completed)
2. Modify `build.rs` to write to `OUT_DIR/version.rs`
3. Update `src/main.rs` to include from `OUT_DIR`
4. Remove `src/version.rs` from git tracking
5. Test build and version command
6. Update documentation if needed
## Testing
```bash
# Clean build
cargo clean
cargo build
# Verify version command works
cargo run -- version
# Verify file locations
ls target/debug/build/granite-cli-*/out/version.rs
ls src/version.rs # Should not exist
```
## Migration Notes
- Existing checkouts will have `src/version.rs` which can be safely deleted
- No breaking changes to the public API
- Version command continues to work identically