Skip to content

Commit 6844fa4

Browse files
Merge #2788
2788: build: customize `opt-level` to avoid building some crates twice r=quake,driftluo a=yangby-cryptape ### Purpose Since "Cargo PR-8500" merged, as "Cargo Issue-8502" said: "if a crate will also be built as a runtime dependency, that would result in Cargo building it twice, once with opt-level 0 and once with opt-level 3." So, in this PR I customize the `opt-level` to the default values, to make sure each crates only be compiled once. ### Results When `make prod` for `v0.42.0`: - This PR can reduce the number of compiled dependencies 9.56% (`596 -> 544`). - This PR can reduce the size of target directory 14.2% (`1_813_100 bytes -> 1_587_780 bytes`). - Save total compile time. **Notice: the size of final binary won't be chaneged.** ### References - [Cargo PR-8500: Build host dependencies with opt-level 0 by default](rust-lang/cargo#8500) - [Cargo Issue-8502: Support opt-level ranges to avoid building twice with different opt-level values](rust-lang/cargo#8502) - [Cargo Reference / Default profiles](https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles) Co-authored-by: Boyu Yang <[email protected]>
2 parents 85bf460 + d560f51 commit 6844fa4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ members = [
9090
[profile.release]
9191
overflow-checks = true
9292

93+
[profile.release.build-override]
94+
opt-level = 3
95+
96+
[profile.bench.build-override]
97+
opt-level = 3
98+
9399
[target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies]
94100
jemallocator = { version = "0.3.0", features = ["unprefixed_malloc_on_supported_platforms"] }
95101

test/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ jsonrpc-core = "17.1"
4242
# Prevent this from interfering with workspaces
4343
[workspace]
4444
members = ["."]
45+
46+
[profile.release.build-override]
47+
opt-level = 3
48+
49+
[profile.bench.build-override]
50+
opt-level = 3

0 commit comments

Comments
 (0)