#cargo #cargo-subcommand #cli #dependencies #crates

app cargo-build-dependencies

A cargo subcommand to build dependencies, helps speed up docker builds by allowing dependencies to be built earlier and cached

5 releases

0.1.3 Jul 1, 2020
0.1.2 Jul 1, 2020
0.1.1 May 17, 2020
0.1.0 May 17, 2020

#192 in Cargo plugins

Download history 10/week @ 2021-09-30 8/week @ 2021-10-07 1/week @ 2021-10-14 11/week @ 2021-10-21 2/week @ 2021-10-28 11/week @ 2021-11-04 36/week @ 2021-11-11 25/week @ 2021-11-18 34/week @ 2021-11-25 27/week @ 2021-12-02 8/week @ 2021-12-09 15/week @ 2021-12-16 11/week @ 2021-12-23 25/week @ 2021-12-30 25/week @ 2022-01-06 23/week @ 2022-01-13

84 downloads per month

MIT license

12KB
236 lines

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

Dependencies

~1.5MB
~24K SLoC