#directory #build #copying #script #file #linker #process

build xext-build-utils

Build utilities for Rust and C++ projects

2 releases

Uses new Rust 2024

0.1.1 Mar 8, 2025
0.1.0 Mar 8, 2025

#209 in Build Utils

Download history 224/week @ 2025-03-05 18/week @ 2025-03-12

242 downloads per month

MIT license

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 instance
  • link(name: &str) - Add library to link
  • copy(exts: Vec<String>) -> Result<(), BuildError> - Copy library files to target directory
  • verify_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 directory
  • get_target_dir() -> Result<PathBuf, BuildError> - Get target directory
  • print(content: &str) - Output build warning messages
  • watch(file: &str) - Add file change monitoring

License

MIT License

Contributing

Issues and Pull Requests are welcome!

No runtime deps