-
Notifications
You must be signed in to change notification settings - Fork 2.6k
cargo build doesn't detect file changes #9598
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
Comments
Thanks for the report! Unfortunately I'm not able to reproduce with the steps provided. Can you provide more information, such as which operating system you are using, which filesystem, are you running this in a strange environment like Docker? Here's the output that I have:
In general, cargo uses filesystem mtime timestamps to detect if something needs to be rebuilt. So if you are doing something that causes the timestemp to be in the past, then cargo won't think it has changed. |
I was first encountering this error when building a Docker image, this is the part of my config causing it
comparing the sha sums of the built binaries yields that they are the same, to fix that i added the line
I was able to reproduce it on Windows 10 with
Edit:
I just read this in your answer, this explains it but it was a very confusing and hard to debug bug, at least for me |
Ah, yea, IIRC when copying into docker, you may need to add a line to run I understand that it can be confusing and difficult to understand and debug. There are some issues tracking improvements to deal with this. Primarily #6529 would add change tracking based on file contents, and #2904 is for adding the ability to provide better ways to diagnose why things are or are not rebuilt. I'm going to close as the problems are well known and tracked in those linked issues. |
I executed the following command to delete the cache |
In my case, I'm trying to pre-build dependencies into a cached Docker layer. FROM rust:alpine AS build
WORKDIR /app
RUN apk add --no-cache build-base openssl-dev
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && \
echo 'fn main() { println!("Should not see this!") }' > src/main.rs && \
cargo build -r --locked && \
rm -rf src
COPY src src
# must `touch` here no matter the copy above is on Windows or Debian
RUN touch src/main.rs
RUN cargo install --path . --locked --offline
FROM alpine:latest AS publish
COPY --from=build /usr/local/cargo/bin/myapp /usr/local/bin/
ENTRYPOINT [ "myapp" ] Without the |
Well, after asking GitHub Copilot a few times, I figure that |
It appears as if cargo doesn't detect file changes when deleting and replacing files.
Running cargo 1.52.0 (6976741 2021-04-21)
cargo new --bin app
cd app
cargo build
running the generated binary should output "Hello, world!"
rm src/main.rs
echo fn main() { println!("Not Hello, world"); } > main.rs
cp main.rs src/main.rs
cargo build
this build finishes immediatelly and running the "generated" binary will output "Hello, world!" again
Is this behaviour intendet?
The text was updated successfully, but these errors were encountered: