Skip to content

Cargo rebuilds with include_str but not include_bytes #1510

@nicholasbishop

Description

@nicholasbishop

I encountered a strange difference in Cargo's behavior related to the include_str and include_bytes macros. It seems like include_str adds a build dependency on the included file but include_bytes does not.

Here's a simplified test case:

// main.rs

pub fn main() {
    const INPUT: &'static str = include_str!("input.txt");
    //const INPUT: &'static [u8] = include_bytes!("input.txt");

    println!("{:?}", INPUT);
}

This file lives in a minimal repo created with cargo new. There's an input.txt file in src/. Here's the full thing: https://github.com/nicholasbishop/cargo-includes-bug

I run cargo build and it compiles the program as expected. I modify input.txt and run cargo build. The program recompiles, which is nice.

Then I comment out the include_str! line and uncomment the include_bytes! line. I run cargo build and it recompiles as expected. Then I modify input.txt and run cargo build. The program does not recompile.

Tested with:

rustc 1.0.0-nightly (6b95d8bed 2015-04-09) (built 2015-04-10)

cargo 0.0.1-pre-nightly (471c519 2015-04-08) (built 2015-04-09)

(This started out in a StackOverflow question: http://stackoverflow.com/questions/29200914/how-can-i-tell-cargo-to-rebuild-when-a-file-included-with-the-include-bytes-macr)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions