| Crates.io | valve_compilers |
| lib.rs | valve_compilers |
| version | 1.1.0 |
| created_at | 2025-07-17 12:49:32.233829+00 |
| updated_at | 2025-07-18 11:43:26.55652+00 |
| description | A type-safe, ergonomic, and extensible library for building command-line arguments for Valve's Source Engine compiler tools. |
| homepage | |
| repository | https://github.com/IaVashik/Valve-compileRS |
| max_upload_size | |
| id | 1757429 |
| size | 67,266 |
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.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:
.toml files. Adding a new tool or argument requires no code changes, just a new config file..toml file into the compiler_configs directory.build.rs script parses .toml configs and generates all necessary Rust modules, enums, and argument types.CompilerContext to automatically substitute placeholders like $gameDir, $mapName, and $bspPath in your arguments and working directories.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. ;)
Add valve_compilers to your Cargo.toml:
[dependencies]
valve_compilers = "1"
Here's a simple example of how to build a command for vbsp:
use valve_compilers::{Compiler, CompilerContext};
use valve_compilers::vbsp::{Vbsp, VbspArg}; // The Vbsp and VbspArg types are auto-generated!
use std::path::PathBuf;
fn main() {
// 1. Create a default compiler instance.
// This will be pre-populated with default arguments from vbsp.toml.
let mut vbsp = Vbsp::default();
// 2. Add or override arguments in a type-safe way.
vbsp.add_arg(VbspArg::Verbose);
vbsp.add_arg(VbspArg::NoWater);
vbsp.add_arg(VbspArg::MicroVolumeTest(0.5)); // Pass floats, ints, or paths directly.
// 3. Define the context for placeholder substitution.
let context = CompilerContext::new(
Some(PathBuf::from(r"C:\Steam\steamapps\common\Half-Life 2\bin")),
Some(PathBuf::from(r"C:\Steam\steamapps\common\Half-Life 2\hl2")),
Some(PathBuf::from(r"C:\Users\Gordon\maps\d1_trainstation_01.vmf")),
None, // Output directory (defaults to map's directory if None)
);
// The executable path is determined from the context's bin_dir.
// You can override it with an optional second argument.
let command_info = vbsp.build_command(&context, None);
// 4. Execute the command!
println!("Compiler: {}", command_info.name);
println!("Path: {}", command_info.compiler_path.display());
println!("Working Directory: {}", command_info.working_dir.display());
println!("Arguments: {}", command_info.args);
// You can now pass these details to std::process::Command.
}
The magic is in the build.rs script. On compilation, it:
.toml file in the compiler_configs/ directory.vbsp.rs).Vbsp) that implements the Compiler trait and an enum (e.g., VbspArg) that implements the CompilerArg trait.Contributions are welcome! Please feel free to open issues or submit pull requests.
Valve-compileRS is distributed under the terms of either the MIT license.