1 stable release
new 1.0.0 | Apr 25, 2025 |
---|
#216 in Build Utils
42KB
793 lines
Compilation Database Generator (Rust)
A fast Rust implementation of Clang's JSON Compilation Database generator for GNU make
-based build systems. This is a Rust rewrite of compiledb-go for even better performance and safety.
Features
- Fast compilation database generation
- No clean build required in most cases
- Cross-compilation friendly
- Supports both command string and arguments list formats
- Configurable file exclusion patterns
- Full path resolution for compiler executables
- Async I/O for improved performance with large build logs
Installation
From crates.io
cargo install compiledb
From source
git clone https://github.com/yourusername/compiledb-rs
cd compiledb-rs
cargo install --path .
Usage
Basic Usage
Generate compilation database from make output:
# Using the make wrapper
compiledb make
# Using make output directly
make -Bnwk | compiledb
Command-line Options
USAGE: compiledb [options] command [command options] [args]...
OPTIONS:
-p, --parse <file> Build log file to parse compilation commands
-o, --output <file> Output file [default: compile_commands.json]
-d, --build-dir <path> Path to be used as initial build dir
-e, --exclude <pattern> Regular expressions to exclude files
-n, --no-build Only generates compilation db file
-v, --verbose Print verbose messages
-S, --no-strict Do not check if source files exist
-m, --macros <macro> Add predefined compiler macros
-c, --command-style Use command string format instead of arguments list
--full-path Write full path to compiler executable
--regex-compile <re> Regular expressions to find compile commands
--regex-file <re> Regular expressions to find source files
COMMANDS:
make Run make and generate compilation database
help Print this message or help for a command
Examples
- Generate database using make wrapper:
compiledb make
- Parse from existing build log:
compiledb --parse build.log
- Use command style output:
compiledb --command-style make
- Use full compiler paths:
PATH=/opt/gcc/bin:$PATH compiledb --full-path make
- Custom make target with flags:
compiledb make -f custom.mk -j8 target
Performance
This Rust implementation offers several performance improvements over the original Go version:
- Zero-copy parsing where possible
- Async I/O for file operations
- Efficient string handling
- Thread-safe by design
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
GNU GPLv3 - See LICENSE for details
Dependencies
~10–22MB
~326K SLoC