#ignore #cargo-build #gitignore #rebuild #file #rerun #trigger

rerun_except

Rerun a cargo build except when specified files are changed

4 releases (1 stable)

1.0.0 Mar 1, 2021
0.1.2 Apr 28, 2020
0.1.1 Nov 21, 2019
0.1.0 May 26, 2019

#1313 in Development tools

Download history 402/week @ 2024-07-22 869/week @ 2024-07-29 398/week @ 2024-08-05 206/week @ 2024-08-12 312/week @ 2024-08-19 301/week @ 2024-08-26 88/week @ 2024-09-02 128/week @ 2024-09-09 642/week @ 2024-09-16 299/week @ 2024-09-23 426/week @ 2024-09-30 378/week @ 2024-10-07 729/week @ 2024-10-14 564/week @ 2024-10-21 1180/week @ 2024-10-28 1287/week @ 2024-11-04

3,766 downloads per month
Used in 2 crates

Apache-2.0/MIT

8KB

rerun_except

Specify which files should not trigger a cargo rebuild.

In normal operation, cargo rebuilds a project when any potentially relevant file changes. One can use the rerun-if-changed instruction to tell cargo to only rebuild if certain files are changed. However, it is easy to forget to add new files when using rerun-if-changed, causing cargo not to rebuild a project when it should.

rerun_except inverts this logic, causing cargo to rebuild a project when a file changes unless you explicitly ignored that file. This is safer than rerun-if-changed because if you forget to explicitly ignore files, then cargo will still rebuild your project.

rerun_except uses the ignore library to specify which files to ignore in gitignore format. Note that explicit ignore files in your project (e.g. .gitignore) are implicitly added to the list of ignored files.

For example if you have the following file layout:

proj/
  .gitignore
  Cargo.toml
  src/
    lib.rs
  lang_tests/
    run.rs
    test1.lang
    test2.lang
  target/
    ...

and you do not want the two .lang files to trigger a rebuild then you would tell rerun_except to exclude lang_tests/*.lang. Assuming, as is common, that your .gitignore file also the target/ directory, then rerun_except will also ignore the target directory.

Adding a new file such as lang_tests/test3.lang will not trigger a rebuild (since it is covered by the ignore glob lang_tests/*.lang), but adding a new file such as build.rs will trigger a rebuild (since it is not covered by an ignore glob).

To use rerun_except in this manner you simply need to call rerun_except::rerun_except with an array of ignore globs in gitignore format as part of your build.rs file:

use rerun_except::rerun_except;

fn main() {
    rerun_except(&["lang_tests/*.lang"]).unwrap();
}

Dependencies

~4–12MB
~126K SLoC