Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why `cargo build` immediately after `cargo check` recompiles some dependencies?

What could be a possible reason for cargo build immediately after cargo check recompiling many (but not all) dependencies?

Cargo.toml

[package]
name = "greeter"
version = "0.1.0"
authors = ["Near Inc <[email protected]>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "3.1.0"

[profile.release]
codegen-units = 1
# Tell `rustc` to optimize for small code size.
opt-level = "z"
lto = true
debug = false
panic = "abort"
# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801
overflow-checks = true

[workspace]
members = []
like image 374
DeLorean88 Avatar asked Sep 13 '25 13:09

DeLorean88


1 Answers

cargo check is not a build. It simply checks that your code would compile, but doesn't necessarily build anything. See here for more information.

So cargo build will need to actually build some crates, that where not built during cargo check. Other crates may need to be fully compiled to check (for example crates used in a build.rs script or by procedural macros), and where therefore already compiled when you ran cargo build.

like image 174
PiRocks Avatar answered Sep 15 '25 01:09

PiRocks