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

cargo uses file update time instead of content diff to determine whether to compile #5679

Closed
xfoxfu opened this issue Jul 4, 2018 · 2 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@xfoxfu
Copy link

xfoxfu commented Jul 4, 2018

I recently found that cargo uses file update time to determine whether to compile. Most times this works fine, but if I uses the following Dockerfile, the build output will remains the same as an bootstrap project.

FROM rust:1.27.0 AS build

WORKDIR /app
RUN USER=root cargo init

COPY Cargo.lock Cargo.toml ./
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --release --target x86_64-unknown-linux-musl

COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl

FROM scratch

COPY --from=build /app/target/x86_64-unknown-linux-musl/release/rust-docker /app/rust-docker
ENTRYPOINT [ "/app/rust-docker" ]

The container just outputs Hello world! as src/main.rs is changed before the compiled binary. I think cargo should use file content diff to determine whether to compile again, instead of file update time. Using file update time creates a confusion.

To workaround this, a RUN touch src/main.rs should be added after COPY . ..

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 4, 2018
@xfoxfu
Copy link
Author

xfoxfu commented Nov 30, 2018

I think a force-recompile flag may be provided instead of changing the default behavior. This may be easier.

@xfoxfu
Copy link
Author

xfoxfu commented Mar 1, 2019

Fixed as #6484.

@xfoxfu xfoxfu closed this as completed Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants