Crate depgraph

source ·
Expand description

A library to help build dependencies externally from rust. Uses petgraph under the hood for managing the graph structure.

§Example

An example is worth a thousand words - made up quote.

§Example build script

use std::path::Path;
use std::{fs, env};
use std::process::Command;

fn build_assembly(out: &Path, deps: &[&Path]) -> Result<(), String> {
    // Make sure the folder we're going to output to exists.
    let out_dir = out.parent().unwrap();
    fs::create_dir_all(out_dir).unwrap();

    // Run the command with correct argument order
    Command::new("yasm").args(&["-f", "elf64", "-o"]).arg(out).args(deps)
        .status().unwrap();
    // Everything went ok so we return Ok(()). Instead of panicking, we could
    // have returned an error message and handled it in main.
    Ok(())
}

fn main() {
    // Get the directory we should put files in.
    let out_dir = env::var("OUT_DIR").unwrap();
    let out_dir = Path::new(&out_dir);
    // Create the graph builder
    let graph = depgraph::DepGraphBuilder::new()
    // Add a rule to build an object file from an asm file using the build
    // script in `build_assembly`.
      .add_rule(out_dir.join("out/path/file.o"),
                &[Path::new("src/input_file.asm")],
                build_assembly)
    // Build the graph, internally this checks for cyclic dependencies.
      .build().unwrap();
    // Run the necessary build scripts in the correct order.
    graph.make(depgraph::MakeParams::None).unwrap();
}

Structs§

  • Contains the checked and parsed dependency graph, ready for execution (fn make)
  • Used to construct a DepGraph

Enums§

  • Any error that can occur during build
  • When running the build scripts, we can either only build when output files are newer than their dependencies, or we can force the build script to run regardless. This enum allows for those two choices.

Type Aliases§