You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frequency = 'always'# when to display a notification about a future incompat report
97
97
98
+
[gc.auto]
99
+
frequency = "1 day"# How often to perform automatic garbage collection
100
+
98
101
[cargo-new]
99
102
vcs = "none"# VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
100
103
@@ -657,6 +660,42 @@ Controls how often we display a notification to the terminal when a future incom
657
660
*`always` (default): Always display a notification when a command (e.g. `cargo build`) produces a future incompat report
658
661
*`never`: Never display a notification
659
662
663
+
### `[gc]`
664
+
665
+
The `[gc]` table defines settings for garbage collection in Cargo's caches, which will delete old, unused files.
666
+
667
+
#### `[gc.auto]`
668
+
669
+
The `[gc.auto]` table defines settings for automatic garbage collection in Cargo's caches.
670
+
When running `cargo` commands, Cargo will automatically track which files you are using within the global cache.
671
+
Periodically, Cargo will delete files that have not been used for some period of time.
672
+
Currently it will delete files that have to be downloaded from the network if they have not been used in 3 months. Files that can be generated without network access will be deleted if they have not been used in 1 month.
673
+
674
+
The automatic deletion of files only occurs when running commands that are already doing a significant amount of work, such as all of the build commands (`cargo build`, `cargo test`, `cargo check`, etc.), and `cargo fetch`.
675
+
676
+
Automatic deletion is disabled if cargo is offline such as with `--offline` or `--frozen` to avoid deleting artifacts that may need to be used if you are offline for a long period of time.
677
+
678
+
> **Note**: This tracking is currently only implemented for the global cache in Cargo's home directory.
679
+
> This includes registry indexes and source files downloaded from registries and git dependencies.
680
+
> Support for tracking build artifacts is not yet implemented, and tracked in [cargo#13136](https://github.com/rust-lang/cargo/issues/13136).
681
+
>
682
+
> Additionally, there is an unstable feature to support *manually* triggering garbage collection, and to further customize the configuration options.
683
+
> See the [Unstable chapter](unstable.md#gc) for more information.
684
+
685
+
##### `gc.auto.frequency`
686
+
* Type: string
687
+
* Default: `"1 day"`
688
+
* Environment: `CARGO_GC_AUTO_FREQUENCY`
689
+
690
+
This option defines how often Cargo will automatically delete unused files in the global cache.
691
+
This does *not* define how old the files must be, those thresholds are described [above](#gcauto).
692
+
693
+
It supports the following settings:
694
+
695
+
*`"never"` --- Never deletes old files.
696
+
*`"always"` --- Checks to delete old files every time Cargo runs.
697
+
* An integer followed by "seconds", "minutes", "hours", "days", "weeks", or "months" --- Checks to delete old files at most the given time frame.
698
+
660
699
### `[http]`
661
700
662
701
The `[http]` table defines settings for HTTP behavior. This includes fetching
Copy file name to clipboardExpand all lines: src/doc/src/reference/environment-variables.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,7 @@ In summary, the supported environment variables are:
101
101
*`CARGO_BUILD_DEP_INFO_BASEDIR` --- Dep-info relative directory, see [`build.dep-info-basedir`].
102
102
*`CARGO_CARGO_NEW_VCS` --- The default source control system with [`cargo new`], see [`cargo-new.vcs`].
103
103
*`CARGO_FUTURE_INCOMPAT_REPORT_FREQUENCY` --- How often we should generate a future incompat report notification, see [`future-incompat-report.frequency`].
104
+
*`CARGO_GC_AUTO_FREQUENCY` --- Configures how often automatic garbage collection runs, see [`gc.auto.frequency`].
104
105
*`CARGO_HTTP_DEBUG` --- Enables HTTP debugging, see [`http.debug`].
105
106
*`CARGO_HTTP_PROXY` --- Enables HTTP proxy, see [`http.proxy`].
106
107
*`CARGO_HTTP_TIMEOUT` --- The HTTP timeout, see [`http.timeout`].
@@ -167,6 +168,7 @@ In summary, the supported environment variables are:
The `-Zgc` flag enables garbage-collection within cargo's global cache within the cargo home directory.
1469
-
This includes downloaded dependencies such as compressed `.crate` files, extracted `src` directories, registry index caches, and git dependencies.
1470
-
When `-Zgc` is present, cargo will track the last time any index and dependency was used,
1471
-
and then uses those timestamps to manually or automatically delete cache entries that have not been used for a while.
1472
-
1473
-
```sh
1474
-
cargo build -Zgc
1475
-
```
1476
-
1477
-
### Automatic garbage collection
1478
-
1479
-
Automatic deletion happens on commands that are already doing a significant amount of work,
1480
-
such as all of the build commands (`cargo build`, `cargo test`, `cargo check`, etc.), and `cargo fetch`.
1481
-
The deletion happens just after resolution and packages have been downloaded.
1482
-
Automatic deletion is only done once per day (see `gc.auto.frequency` to configure).
1483
-
Automatic deletion is disabled if cargo is offline such as with `--offline` or `--frozen` to avoid deleting artifacts that may need to be used if you are offline for a long period of time.
1468
+
The `-Zgc` flag is used to enable certain features related to garbage-collection of cargo's global cache within the cargo home directory.
1484
1469
1485
1470
#### Automatic gc configuration
1486
1471
1487
-
The automatic gc behavior can be specified via a cargo configuration setting.
1472
+
The `-Zgc` flag will enable Cargo to read extra configuration options related to garbage collection.
1488
1473
The settings available are:
1489
1474
1490
1475
```toml
1491
1476
# Example config.toml file.
1492
1477
1493
1478
# This table defines the behavior for automatic garbage collection.
1494
1479
[gc.auto]
1495
-
# The maximum frequency that automatic garbage collection happens.
1496
-
# Can be "never" to disable automatic-gc, or "always" to run on every command.
1497
-
frequency = "1 day"
1498
1480
# Anything older than this duration will be deleted in the source cache.
1499
1481
max-src-age = "1 month"
1500
1482
# Anything older than this duration will be deleted in the compressed crate cache.
@@ -1507,9 +1489,13 @@ max-git-co-age = "1 month"
1507
1489
max-git-db-age = "3 months"
1508
1490
```
1509
1491
1492
+
Note that the [`gc.auto.frequency`] option was stabilized in Rust 1.82.
1493
+
1494
+
[`gc.auto.frequency`]: config.md#gcautofrequency
1495
+
1510
1496
### Manual garbage collection with `cargo clean`
1511
1497
1512
-
Manual deletion can be done with the `cargo clean gc` command.
1498
+
Manual deletion can be done with the `cargo clean gc -Zgc` command.
1513
1499
Deletion of cache contents can be performed by passing one of the cache options:
1514
1500
1515
1501
-`--max-src-age=DURATION` --- Deletes source cache files that have not been used since the given age.
@@ -1528,9 +1514,9 @@ A DURATION is specified in the form "N seconds/minutes/days/weeks/months" where
1528
1514
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.
0 commit comments