Closed aminya closed 5 months ago
I found a workaround by creating empty packages. This fixes the issue, but it seems to negate the whole point of using cargo-chef to automate this process.
# Build the Cargo dependencies.
COPY ./Cargo.toml ./Cargo.lock ./rust-toolchain.toml ./
COPY ./.cargo/config.toml ./.cargo/config.toml
COPY ./packages/a/Cargo.toml ./packages/a/
COPY ./packages/b/Cargo.toml ./packages/b/
COPY ./packages/c/Cargo.toml ./packages/c/
COPY ./packages/d/Cargo.toml ./packages/d/
COPY ./packages/f/Cargo.toml ./packages/f/
RUN mkdir -p ./packages/a/src && touch ./packages/a/src/lib.rs && \
mkdir -p ./packages/b/src && touch ./packages/b/src/lib.rs && \
mkdir -p ./packages/c/src && touch ./packages/c/src/lib.rs && \
mkdir -p ./packages/d/src && touch ./packages/d/src/lib.rs && \
mkdir -p ./packages/f/src && touch ./packages/f/src/main.rs && \
cargo chef prepare --recipe-path recipe.json && \
cargo chef cook --profile=release_lto --recipe-path recipe.json --bin ${APP_NAME}
# Build the application.
RUN --mount=type=bind,source=packages,target=packages \
--mount=type=bind,source=.cargo,target=.cargo \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=bind,source=rust-toolchain.toml,target=rust-toolchain.toml \
cargo build --profile release_lto --bin ${APP_NAME} && \
cp ./target/release_lto/$APP_NAME /app/${APP_NAME}
Can you share the Dockerfile that doesn't cache? We also need a minimal reproducible example.
Closing since we can't reproduce.
I am using
cargo-chef
on a workspace and want to avoid rebuilds of the external packages. However, Cargo-chefcook
requires copying local packages in a workspace before cooking. Every time I change one of those files,cargo-chef
needs to recook the whole thing.Is there a way to only build the external dependencies?
This doesn't work because of not copying the source files of the workspace dependencies:
Those local dependencies are under
packages
and are linked to each other using{path = "../mylib" }