Valve-compileRS is a type-safe, ergonomic, and extensible Rust library for building command-line arguments for Valve's Source Engine compiler tools like vbsp, vvis, and vrad.
Overview
Interfacing with the Source Engine's command-line tools can be cumbersome and error-prone. This library solves that problem by providing a native Rust API that is:
- Configuration-Driven: All compiler arguments are defined in simple
.tomlfiles. Adding a new tool or argument requires no code changes, just a new config file. - Type-Safe: The build script automatically generates enums and structs, so you can't pass a string where an integer is expected. This eliminates a whole class of runtime errors.
- Ergonomic: The API is designed to be intuitive and easy to use, with a fluent builder-like pattern for constructing commands.
- Extensible: Easily add support for custom or community-made compiler tools by dropping a new
.tomlfile into thecompiler_configsdirectory.
Features
- Automatic Code Generation: A powerful
build.rsscript parses.tomlconfigs and generates all necessary Rust modules, enums, and argument types. - Contextual Placeholder Replacement: Uses a
CompilerContextto automatically substitute placeholders like$gameDir,$mapName, and$bspPathin your arguments and working directories. - Game Compatibility Checks: Arguments can be constrained to specific game App IDs, preventing the use of incompatible flags (e.g., CS:GO-specific arguments in Team Fortress 2).
- Without unnecessary dependencies: that says it all :P
Why?
This crate provides the ideal backend for any application that automates the Source Engine compile process. It's perfectly suited for building custom CLI/GUI wrappers, CI/CD automation scripts, or even a new map editor—like a "Hammer 2.0" rewritten in Rust. ;)
Installation
Add valve_compilers to your Cargo.toml:
[]
= "1"
Quick Start
Here's a simple example of how to build a command for vbsp:
use ;
use ; // The Vbsp and VbspArg types are auto-generated!
use PathBuf;
How It Works
The magic is in the build.rs script. On compilation, it:
- Reads every
.tomlfile in thecompiler_configs/directory. - For each file, it generates a corresponding Rust module (e.g.,
vbsp.rs). - Each module contains a struct (e.g.,
Vbsp) that implements theCompilertrait and an enum (e.g.,VbspArg) that implements theCompilerArgtrait. - This generated code is then included into the crate, providing a fully type-safe API for the compilers defined in your configs.
Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
License
Valve-compileRS is distributed under the terms of either the MIT license.