https://github.com/0xmad/cargo-build-dependencies
Tool to build dependencies only for rust projects using cargo. Helps speed up docker builds.
https://github.com/0xmad/cargo-build-dependencies
cargo-dependencies-only cargo-plugins cargo-subcommand development-tools
Last synced: 8 months ago
JSON representation
Tool to build dependencies only for rust projects using cargo. Helps speed up docker builds.
- Host: GitHub
- URL: https://github.com/0xmad/cargo-build-dependencies
- Owner: 0xmad
- Created: 2020-05-17T12:02:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T22:20:24.000Z (about 5 years ago)
- Last Synced: 2025-03-26T13:53:46.465Z (about 1 year ago)
- Topics: cargo-dependencies-only, cargo-plugins, cargo-subcommand, development-tools
- Language: Rust
- Homepage:
- Size: 31.3 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# cargo-build-dependencies
[](https://crates.io/crates/cargo-build-dependencies)
This tool extends [Cargo](https://doc.rust-lang.org/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
```