Skip to content

Commit a55d1ff

Browse files
committed
Add unstable documentation for -Zgc
1 parent 9886525 commit a55d1ff

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/doc/src/reference/unstable.md

+61
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ For the latest nightly, see the [nightly version] of this page.
8585
* [check-cfg](#check-cfg) --- Compile-time validation of `cfg` expressions.
8686
* [host-config](#host-config) --- Allows setting `[target]`-like configuration settings for host build targets.
8787
* [target-applies-to-host](#target-applies-to-host) --- Alters whether certain flags will be passed to host build targets.
88+
* [gc](#gc) --- Global cache garbage collection.
8889
* rustdoc
8990
* [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
9091
* [scrape-examples](#scrape-examples) --- Shows examples within documentation.
@@ -1665,6 +1666,66 @@ version = "0.1.0"
16651666
workspace = true
16661667
```
16671668
1669+
## gc
1670+
1671+
* Tracking issue: TODO
1672+
1673+
The `-Zgc` flag enables garbage-collection within cargo's global cache within the cargo home directory.
1674+
This includes downloaded dependencies such as compressed `.crate` files, extracted `src` directories, registry index caches, and git dependencies.
1675+
When `-Zgc` is present, cargo will track the last time any file was used, and then uses those timestamps to manually or automatically delete files that have not been used for a while.
1676+
1677+
```sh
1678+
cargo build -Zgc
1679+
```
1680+
1681+
Automatic deletion happens on commands that are already doing a significant amount of work,
1682+
such as all of the build commands (`cargo build`, `cargo test`, `cargo check`, etc.), and `cargo fetch`.
1683+
Automatic deletion is only done once per day.
1684+
Automatic deletion is disabled if cargo is offline such as with `--offline` or `--frozen` to avoid deleting files that may need to be used if you are offline for a long period of time.
1685+
1686+
Manual deletion can be done with the `cargo clean` command.
1687+
Deletion of cache contents can be performed by passing one of the cache options:
1688+
1689+
- `--gc` --- Performs the same garbage collection that is performed by the once-a-day automatic deletion.
1690+
- `--max-src-age=DURATION` --- Deletes source cache files that have not been used since the given age.
1691+
- `--max-crate-age=DURATION` --- Deletes crate cache files that have not been used since the given age.
1692+
- `--max-index-age=DURATION` --- Deletes registry indexes that have not been used since then given age (including their `.crate` and `src` files).
1693+
- `--max-git-co-age=DURATION` --- Deletes git dependency checkouts that have not been used since then given age.
1694+
- `--max-git-db-age=DURATION` --- Deletes git dependency clones that have not been used since then given age.
1695+
- `--max-download-age=DURATION` --- Deletes any downloaded cache data that has not been used since then given age.
1696+
- `--max-src-size=SIZE` --- Deletes the oldest source cache files until the cache is under the given size.
1697+
- `--max-crate-size=SIZE` --- Deletes the oldest crate cache files until the cache is under the given size.
1698+
- `--max-git-size=SIZE` --- Deletes the oldest git dependency caches until the cache is under the given size.
1699+
- `--max-download-size=SIZE` --- Deletes the oldest downloaded cache data until the cache is under the given size.
1700+
1701+
A DURATION is specified in the form "N seconds/minutes/days/weeks/months" where N is an integer.
1702+
1703+
A SIZE is specified in the form "N *suffix*" where *suffix* is B, kB, MB, GB, kiB, MiB, or GiB, and N is an integer or floating point number. If no suffix is specified, the number is the number of bytes.
1704+
1705+
```sh
1706+
cargo clean --max-download-age=1week
1707+
cargo clean --max-git-size=0 --max-download-size=100MB
1708+
```
1709+
1710+
The automatic gc behavior can be specified via a cargo configuration setting.
1711+
The settings available are:
1712+
1713+
```toml
1714+
# The maximum frequency that automatic garbage collection happens.
1715+
# Can be "never" to disable automatic-gc, or "always" to run on every command.
1716+
frequency = "1 day"
1717+
# Anything older than this duration will be deleted in the source cache.
1718+
max-src-age = "1 month"
1719+
# Anything older than this duration will be deleted in the compressed crate cache.
1720+
max-crate-age = "3 months"
1721+
# Any index older than this duration will be deleted from the index cache.
1722+
max-index-age = "3 months"
1723+
# Any git checkout older than this duration will be deleted from the checkout cache.
1724+
max-git-co-age = "1 month"
1725+
# Any git clone older than this duration will be deleted from the git cache.
1726+
max-git-db-age = "3 months"
1727+
```
1728+
16681729
# Stabilized and removed features
16691730

16701731
## Compile progress

0 commit comments

Comments
 (0)