cargo-build-dependencies

Crates.iocargo-build-dependencies
lib.rscargo-build-dependencies
version0.1.3
sourcesrc
created_at2020-05-17 12:27:23.415567
updated_at2020-07-01 22:09:28.530496
descriptionA cargo subcommand to build dependencies, helps speed up docker builds by allowing dependencies to be built earlier and cached.
homepage
repositoryhttps://github.com/errmac-v/cargo-build-dependencies
max_upload_size
id242639
size21,072
Anton (0xmad)

documentation

README

cargo-build-dependencies

Crates.io

This tool extends Cargo to allow you to build only the dependencies in a given rust project. This is useful for docker builds where each build step is cached. The time it takes to build dependencies is often a significant portion of the overall build time. Therefore it is beneficial in docker builds to build dependencies in a separate step earlier than the main build. Since the dependency building step will be cached, dependencies will not need to be rebuilt when the project's own source code changes.

Based on https://github.com/nacardin/cargo-build-deps

Install

cargo install cargo-build-dependencies

Usage

cargo build-dependencies

Example

Change Dockerfile from

FROM rust:1.43 as rust-builder
RUN mkdir /tmp/PROJECT_NAME
WORKDIR /tmp/PROJECT_NAME
COPY . .
RUN cargo build  --release

to

FROM rust:1.43 as rust-builder
RUN cargo install cargo-build-dependencies
RUN cd /tmp && USER=root cargo new --bin PROJECT_NAME
WORKDIR /tmp/PROJECT_NAME
COPY Cargo.toml Cargo.lock ./
RUN cargo build-dependencies --release
COPY src /tmp/PROJECT_NAME/src
RUN cargo build  --release
Commit count: 9

cargo fmt