2 releases
Uses new Rust 2024
0.1.1 | Mar 8, 2025 |
---|---|
0.1.0 | Mar 8, 2025 |
#209 in Build Utils
242 downloads per month
17KB
259 lines
Cargo Build Utils
A utility library for simplifying Rust project build scripts (build.rs), mainly used for handling external library linking and file copying operations.
Features
- External library file management and linking
- Cross-platform library file naming conventions (Windows, Linux, macOS)
- Automatic copying of dependency library files to target directory
- Library file existence verification
- Build process warnings and file watching
Usage Example
In your build.rs
:
use build_utils::{Library, BuildError};
fn main() -> Result<(), BuildError> {
// Initialize library manager with library directory
let lib = Library::new("libs")?;
// Verify required library files exist
lib.verify_libs(&["mylib", "otherlib"])?;
// Set linking options
lib.link("mylib");
// Copy library files to target directory
lib.copy(vec![
"dll".to_string(), // Windows
"so".to_string(), // Linux
"dylib".to_string() // macOS
])?;
Ok(())
}
Installation
Add to your Cargo.toml
:
[build-dependencies]
build_utils = "0.1.0"
API Documentation
Library
Main struct for managing external libraries.
new(lib_path: &'static str) -> Result<Self, BuildError>
- Create new instancelink(name: &str)
- Add library to linkcopy(exts: Vec<String>) -> Result<(), BuildError>
- Copy library files to target directoryverify_libs(required_libs: &[&str]) -> Result<(), BuildError>
- Verify library files exist
Utils
Provides common build script utility functions.
get_out_dir() -> Result<String, BuildError>
- Get output directoryget_target_dir() -> Result<PathBuf, BuildError>
- Get target directoryprint(content: &str)
- Output build warning messageswatch(file: &str)
- Add file change monitoring
License
MIT License
Contributing
Issues and Pull Requests are welcome!