项目作者: 0xmad

项目描述 :
Tool to build dependencies only for rust projects using cargo. Helps speed up docker builds.
高级语言: Rust
项目地址: git://github.com/0xmad/cargo-build-dependencies.git
创建时间: 2020-05-17T12:02:04Z
项目社区:https://github.com/0xmad/cargo-build-dependencies

开源协议:

下载


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

  1. FROM rust:1.43 as rust-builder
  2. RUN mkdir /tmp/PROJECT_NAME
  3. WORKDIR /tmp/PROJECT_NAME
  4. COPY . .
  5. RUN cargo build --release

to

  1. FROM rust:1.43 as rust-builder
  2. RUN cargo install cargo-build-dependencies
  3. RUN cd /tmp && USER=root cargo new --bin PROJECT_NAME
  4. WORKDIR /tmp/PROJECT_NAME
  5. COPY Cargo.toml Cargo.lock ./
  6. RUN cargo build-dependencies --release
  7. COPY src /tmp/PROJECT_NAME/src
  8. RUN cargo build --release