Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nothing is rebuilt when the directory is modified #31

Open
ExpHP opened this Issue Aug 27, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@ExpHP
Copy link
Contributor

ExpHP commented Aug 27, 2018

Summary: Changes to the included directory are not tracked by rustc, and nothing is rebuilt unless an actual rust source file is changed (or the user must add a build.rs that recursively walks the directory to print cargo:rerun-if-changed= directives). This is in contrast to what was written in the closing comment on #25 back in 2017 June.

Script:

Bash script
#!/usr/bin/env bash

rm -rf rerun
mkdir rerun
cd rerun

cat >Cargo.toml <<EOF
[package]
name = "rerun"
version = "0.1.0"
authors = ["Michael Lamparski <diagonaldevice@gmail.com>"]

[[bin]]
name = "rerun"
path = "main.rs"

[dependencies]
include_dir = "0.2.1"
EOF

cat >main.rs <<EOF
#[macro_use]
extern crate include_dir;
use include_dir::{Dir};

const DIR: Dir = include_dir!("the-dir");

fn main() {
    show_dir(&DIR);
}

fn show_dir(dir: &Dir) {
    for file in dir.files() {
        println!("{}", file.path().display());
    }
    for dir in dir.dirs() {
        show_dir(dir);
    }
}
EOF

mkdir the-dir
touch the-dir/a
mkdir the-dir/b
touch the-dir/b/c
touch the-dir/b/d

cargo build

echo "--------------"

cargo run

echo "--------------"

touch the-dir/b/e # new file
cargo run

echo "--------------"

echo x > the-dir/b/d # modified file
cargo run

echo "--------------"

touch the-dir/c   # new file at toplevel
cargo run

echo "--------------"

touch the-dir/a   # remove one of the original files
cargo run

echo "--------------"

Output:

$ ./repro  
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling proc-macro2 v0.4.13                                                                                                                             
        ...
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 19.41s
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------

Expected Output:

$ ./repro  
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling proc-macro2 v0.4.13                                                                                                                             
        ...
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 19.41s
--------------
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
--------------
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
b/e
--------------
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s                                                                                                
     Running `target/debug/rerun`
a
b/d
b/c
b/e
--------------
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                
     Running `target/debug/rerun`
a
c
b/d
b/c
b/e
--------------
   Compiling rerun v0.1.0 (file:///home/lampam/cpp/throwaway/rerun/rerun)
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s                                                                                                
     Running `target/debug/rerun`
c
b/d
b/c
b/e
--------------
@Michael-F-Bryan

This comment has been minimized.

Copy link
Owner

Michael-F-Bryan commented Sep 1, 2018

Hmm... I'm not sure how we'd solve this. As far as I'm aware, a proc macro can't emit the usual "rerun if changed" messages so there isn't really a mechanism for re-executing the macro without that file being recompiled by rustc.

Ideally the include_dir!() call would emit all the necessary rerun messages so the user doesn't need to write their own build script. Would it be worth me proposing an RFC to enable the "rerun if changed" messages from a proc macro?

@ExpHP

This comment has been minimized.

Copy link
Contributor Author

ExpHP commented Sep 1, 2018

Hmm, I am uncertain that the cargo flags are the right fit for this since proc macros are expanded by rustc, but it surely is a problem worth solving. It would be good to start a thread on internals.rust-lang.org to start exploring the design space.

ExpHP added a commit to ExpHP/include_dir that referenced this issue Sep 1, 2018

use include_bytes! for less memory overhead
This uses `include_bytes!` to generate the bytestring rather than
the `quote!` macro.  With this change, the total memory used by rustc
for a crate that includes a 15 MB file drops from over 8 GB to only
about 700 MB.

This is similar to Michael-F-Bryan#23, but that predated the proc_macro.

It should also resolve *some* aspects of Michael-F-Bryan#31 (namely for modified
files), but not all. (the crate still has no way to track new files)
@Michael-F-Bryan

This comment has been minimized.

Copy link
Owner

Michael-F-Bryan commented Sep 2, 2018

I've created a thread on the internals forum, let's see what other people think. If possible, it'd be cool to emit a cargo:rerun-if-changed=... to fix this issue, or have the ability to emit warnings when including really large files (for some definition of "really large").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.