Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opt-level ranges to avoid building twice with different opt-level values #8502

Open
joshtriplett opened this issue Jul 17, 2020 · 0 comments
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@joshtriplett
Copy link
Member

#8500 will change Cargo's default opt-level for build dependencies to 0. However, 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. We should have a way of specifying the default as having a minimum opt-level of 0, but allowing a higher opt-level. Then, Cargo could unify that and just build once, leaving build-time-only dependencies unoptimized, but optimizing dependencies shared between build-time and runtime.

@joshtriplett joshtriplett added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 17, 2020
@joshtriplett joshtriplett changed the title Support opt-level ranges to avoid building twice with differnet opt-level values Support opt-level ranges to avoid building twice with different opt-level values Jul 17, 2020
@ehuss ehuss added the A-profiles Area: profiles label Jul 29, 2020
bors bot added a commit to nervosnetwork/ckb that referenced this issue Jun 27, 2021
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 <yangby@cryptape.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants