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

Viewed 370

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 <hello@near.org>"]
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 = []
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.

Related