#cargo-build #file #rebuild #rerun #ignore #changed #glob

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

#913 in Development tools

Download history 369/week @ 2023-11-20 504/week @ 2023-11-27 516/week @ 2023-12-04 569/week @ 2023-12-11 216/week @ 2023-12-18 71/week @ 2023-12-25 72/week @ 2024-01-01 178/week @ 2024-01-08 300/week @ 2024-01-15 407/week @ 2024-01-22 196/week @ 2024-01-29 612/week @ 2024-02-05 515/week @ 2024-02-12 257/week @ 2024-02-19 121/week @ 2024-02-26 790/week @ 2024-03-04

1,687 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–5.5MB
~94K SLoC