pyrossh / rust-embed

Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
MIT License
1.67k stars 85 forks source link

Compression feature breaks incremental builds #182

Closed djmarcin closed 2 years ago

djmarcin commented 2 years ago

When using the compression feature, incremental builds where only the embedded files change do not trigger a rebuild. This is most obvious when using both compression and debug-embed.

I think this is because include_bytes! has special logic in the compiler to add a dependency and trigger rebuilds when the file changes, but include_flate! does not (and does not use include_bytes! internally).

pyrossh commented 2 years ago

Do you think this can be fixed/added in the include_flate! repo? As that would help any other projects using it. I'm guessing its not going that easy though.

djmarcin commented 2 years ago

There is an unstable feature that would allow it to track the file, but that would mean that using it would require nightly. https://github.com/rust-lang/rust/issues/99515

There is another workaround which involves assigning include_bytes! to an unused temporary but I’m not sure if that defeats the point of the compression by including it in the binary again or if it gets optimized out.

I wanted to report it here in case it would be prudent to add a warning that compression should only be used with clean builds or something until this can be fixed.

pyrossh commented 2 years ago

Yeah maybe we can update the readme. Will do it thanks.

pyrossh commented 2 years ago

Done. thanks.

osiewicz commented 1 year ago

Hey, it looks like this issue was addressed within include_flate itself recently? https://github.com/SOF3/include-flate/commit/4cf6b8e1ece726e16e1fd5a7f7e9e2237726bf9f

pyrossh commented 1 year ago

Ahh nice. Will update include-flate to 0.2.0 and remove the note.

pyrossh commented 1 year ago

Release v6.8.0 with the changes thanks @djmarcin @osiewicz.

pyrossh commented 1 year ago

Seems like it breaks the tests,

   Compiling rust-embed v6.8.0 (/Users/pyrossh/Code/rust-embed)
error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/images/doc.txt: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/images/flower.jpg: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/images/llama.png: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/index.html: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/main.css: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: couldn't read /Users/pyrossh/Code/rust-embed//Users/pyrossh/Code/rust-embed/examples/public/main.js: No such file or directory (os error 2)
 --> tests/lib.rs:4:10
  |
4 | #[derive(RustEmbed)]
  |          ^^^^^^^^^
  |
  = note: this error originates in the macro `include_bytes` which comes from the expansion of the derive macro `RustEmbed` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `rust-embed` (test "lib") due to 6 previous errors
osiewicz commented 1 year ago

These paths look like a concatenation of absolute and relative path; I believe include-flate 0.2 explicitly dropped support for absolute paths, so perhaps they changed the API to accept only relative paths? https://github.com/SOF3/include-flate/commit/4d79700ba0a67b764700f591c0ab8635b6ba5bac

pyrossh commented 1 year ago

Fixed again in v6.8.1. Thanks.