#cargo-build #docker-build #cargo #cargo-subcommand #crates #build-time #dependencies

app cargo-build-deps

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

5 releases

Uses old Rust 2015

0.2.0 Jan 28, 2021
0.1.5 Feb 4, 2020
0.1.4 Mar 7, 2018
0.1.0 Feb 9, 2018

#340 in Cargo plugins

Download history 145/week @ 2024-07-21 90/week @ 2024-07-28 112/week @ 2024-08-04 56/week @ 2024-08-11 71/week @ 2024-08-18 50/week @ 2024-08-25 120/week @ 2024-09-01 87/week @ 2024-09-08 146/week @ 2024-09-15 96/week @ 2024-09-22 91/week @ 2024-09-29 66/week @ 2024-10-06 92/week @ 2024-10-13 68/week @ 2024-10-20 131/week @ 2024-10-27 96/week @ 2024-11-03

389 downloads per month

MIT/Apache

11KB
173 lines

cargo-build-deps

Build Status 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.

Inspired by (http://atodorov.org/blog/2017/08/30/speeding-up-rust-builds-inside-docker/)

Install

cargo install cargo-build-deps

Usage

cargo build-deps

Example

Change Dockerfile from

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

to

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

License

Licensed under either of these:

Contributing

Unless you explicitly state otherwise, any contribution you intentionally submit for inclusion in the work, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.

Dependencies

~2MB
~35K SLoC