4 releases

0.1.4 Jul 28, 2019
0.1.3 Jan 23, 2019
0.1.2 Jan 22, 2019
0.1.1 Jan 21, 2019
0.1.0 Jan 21, 2019

#391 in Build Utils

Download history 1612/week @ 2024-09-22 2134/week @ 2024-09-29 1870/week @ 2024-10-06 2730/week @ 2024-10-13 2790/week @ 2024-10-20 3078/week @ 2024-10-27 3182/week @ 2024-11-03 1945/week @ 2024-11-10 2621/week @ 2024-11-17 3638/week @ 2024-11-24 3072/week @ 2024-12-01 3631/week @ 2024-12-08 3045/week @ 2024-12-15 575/week @ 2024-12-22 1307/week @ 2024-12-29 2684/week @ 2025-01-05

7,780 downloads per month
Used in 45 crates (13 directly)

Apache-2.0

36KB

Apache 2.0 licensed

Rust build-script dependencies generator

This is the Rust build-script dependencies generator for data/IDL files

The functionality shall be integrated into the build.script build.rs. The function rerun_if_changed_paths(glob_pattern: &str) will expand the GLOB pattern and will print the files-paths and directory paths to console. The Cargo-tool will evaluate the output. The compilation of the crate is re-run if specified files have changed since the last build.

GLOB Pattern Examples

"data/*" will enumerate all files/directories in directory "data/" and watchin changes

"data/" - will add the directory itself to the watch-list, triggering a rerun in case new entities are added.

"data/**/*.protobuf" will traverse all sub-directories enumerating all protobuf files.

"data/**" will traverse all sub-directories enumerating all directories.

Rule of thumb

Add files, if changes to files shall be detected.

Add directories, if the build-process shall be rerun in case of new files.

Setup

This illustrates a setup. Intention in this example is to rerun the build-process if the files in directory "data/*" have been modified or new files have been added to that directory.

The build-process will execute proc_macros reading those files and generating Rust-code.

A complete example/setup can be found at github test-generator/example

For further tooling around the build-scripts, please take a look at the crate build-helper

Cargo.toml

[package]
name = "datatester"
build = "build.rs"

...
[build-dependencies]
build-deps = "^0.1"
...

build.rs


// declared in Cargo.toml as "[build-dependencies]"
extern crate build_deps;

fn main() {
    // Enumerate files in sub-folder "data/*", being relevant for the code-generation (for example)
    // If function returns with error, exit with error message.
    build_deps::rerun_if_changed_paths( "data/*" ).unwrap();

    // Adding the parent directory "data" to the watch-list will capture new-files being added
    build_deps::rerun_if_changed_paths( "data" ).unwrap();
}

Integration into Conditional Build-Process

The following diagram illustrates the integration of the build-script into the conditional cargo build-process.

 <Diagram - Build Script Intregration>

Dependencies

~50KB