Skip to content

Commit d1d0837

Browse files
committed
Move overriding dependencies into a separate chapter.
1 parent 543e381 commit d1d0837

File tree

9 files changed

+389
-360
lines changed

9 files changed

+389
-360
lines changed

src/doc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
* [Cargo Reference](reference/index.md)
2222
* [Specifying Dependencies](reference/specifying-dependencies.md)
23+
* [Overriding Dependencies](reference/overriding-dependencies.md)
2324
* [The Manifest Format](reference/manifest.md)
2425
* [Cargo Targets](reference/cargo-targets.md)
2526
* [Workspaces](reference/workspaces.md)

src/doc/src/appendix/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ manifest is located.
188188
[integration-tests]: ../reference/cargo-targets.md#integration-tests
189189
[manifest]: ../reference/manifest.md
190190
[path dependency]: ../reference/specifying-dependencies.md#specifying-path-dependencies
191-
[path overrides]: ../reference/specifying-dependencies.md#overriding-with-local-dependencies
191+
[path overrides]: ../reference/overriding-dependencies.md#paths-overrides
192192
[pkgid-spec]: ../reference/pkgid-spec.md
193193
[rustdoc-unstable]: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html
194194
[target-feature]: ../../reference/attributes/codegen.html#the-target_feature-attribute

src/doc/src/reference/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ the `<triple>` part can be any target triple like
207207
* Environment: not supported
208208

209209
An array of paths to local packages which are to be used as overrides for
210-
dependencies. For more information see the [Specifying Dependencies
211-
guide](specifying-dependencies.md#overriding-with-local-dependencies).
210+
dependencies. For more information see the [Overriding Dependencies
211+
guide](overriding-dependencies.md#paths-overrides).
212212

213213
#### `[alias]`
214214
* Type: string or array of strings

src/doc/src/reference/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The reference covers the details of various areas of Cargo.
44

55
* [Specifying Dependencies](specifying-dependencies.md)
6+
* [Overriding Dependencies](overriding-dependencies.md)
67
* [The Manifest Format](manifest.md)
78
* [Cargo Targets](cargo-targets.md)
89
* [Workspaces](workspaces.md)

src/doc/src/reference/manifest.md

Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ file consists of the following sections:
4343
* [`[target]`](specifying-dependencies.md#platform-specific-dependencies) — Platform-specific dependencies.
4444
* [`[badges]`](#the-badges-section) — Badges to display on [crates.io].
4545
* [`[features]`](features.md) — Conditional compilation features.
46-
* [`[patch]`](#the-patch-section) — Override dependencies.
47-
* [`[replace]`](#the-replace-section) — Override dependencies (deprecated).
46+
* [`[patch]`](overriding-dependencies.md#the-patch-section) — Override dependencies.
47+
* [`[replace]`](overriding-dependencies.md#the-replace-section) — Override dependencies (deprecated).
4848
* [`[profile]`](profiles.md) — Compiler settings and optimizations.
4949
* [`[workspace]`](workspaces.md) — The workspace definition.
5050

@@ -517,97 +517,7 @@ The `[profile]` tables provide a way to customize compiler settings such as
517517
optimizations and debug settings. See [the Profiles chapter](profiles.md) for
518518
more detail.
519519

520-
### The `[patch]` Section
521520

522-
This section of Cargo.toml can be used to [override dependencies][replace] with
523-
other copies. The syntax is similar to the `[dependencies]` section:
524-
525-
```toml
526-
[patch.crates-io]
527-
foo = { git = 'https://github.com/example/foo' }
528-
bar = { path = 'my/local/bar' }
529-
530-
[dependencies.baz]
531-
git = 'https://github.com/example/baz'
532-
533-
[patch.'https://github.com/example/baz']
534-
baz = { git = 'https://github.com/example/patched-baz', branch = 'my-branch' }
535-
```
536-
537-
The `[patch]` table is made of dependency-like sub-tables. Each key after
538-
`[patch]` is a URL of the source that is being patched, or the name of a
539-
registry. The name `crates-io` may be used to override the default registry
540-
[crates.io]. The first `[patch]` in the example above demonstrates overriding
541-
[crates.io], and the second `[patch]` demonstrates overriding a git source.
542-
543-
Each entry in these tables is a normal dependency specification, the same as
544-
found in the `[dependencies]` section of the manifest. The dependencies listed
545-
in the `[patch]` section are resolved and used to patch the source at the
546-
URL specified. The above manifest snippet patches the `crates-io` source (e.g.
547-
crates.io itself) with the `foo` crate and `bar` crate. It also
548-
patches the `https://github.com/example/baz` source with a `my-branch` that
549-
comes from elsewhere.
550-
551-
Sources can be patched with versions of crates that do not exist, and they can
552-
also be patched with versions of crates that already exist. If a source is
553-
patched with a crate version that already exists in the source, then the
554-
source's original crate is replaced.
555-
556-
More information about overriding dependencies can be found in the [overriding
557-
dependencies][replace] section of the documentation and [RFC 1969] for the
558-
technical specification of this feature.
559-
560-
[RFC 1969]: https://github.com/rust-lang/rfcs/pull/1969
561-
[replace]: specifying-dependencies.md#overriding-dependencies
562-
563-
#### Using `[patch]` with multiple versions
564-
565-
You can patch in multiple versions of the same crate with the `package` key used
566-
to rename dependencies. For example let's say that the `serde` crate has a
567-
bugfix that we'd like to use to its 1.\* series but we'd also like to prototype
568-
using a 2.0.0 version of serde we have in our git repository. To configure this
569-
we'd do:
570-
571-
```toml
572-
[patch.crates-io]
573-
serde = { git = 'https://github.com/serde-rs/serde' }
574-
serde2 = { git = 'https://github.com/example/serde', package = 'serde', branch = 'v2' }
575-
```
576-
577-
The first `serde = ...` directive indicates that serde 1.\* should be used from
578-
the git repository (pulling in the bugfix we need) and the second `serde2 = ...`
579-
directive indicates that the `serde` package should also be pulled from the `v2`
580-
branch of `https://github.com/example/serde`. We're assuming here that
581-
`Cargo.toml` on that branch mentions version 2.0.0.
582-
583-
Note that when using the `package` key the `serde2` identifier here is actually
584-
ignored. We simply need a unique name which doesn't conflict with other patched
585-
crates.
586-
587-
### The `[replace]` Section
588-
589-
> **Note**: `[replace]` is deprecated. You should use the [`[patch]`][patch]
590-
> table instead.
591-
592-
This section of Cargo.toml can be used to [override dependencies][replace] with
593-
other copies. The syntax is similar to the `[dependencies]` section:
594-
595-
```toml
596-
[replace]
597-
"foo:0.1.0" = { git = 'https://github.com/example/foo' }
598-
"bar:1.0.2" = { path = 'my/local/bar' }
599-
```
600-
601-
Each key in the `[replace]` table is a [package ID
602-
specification](pkgid-spec.md), which allows arbitrarily choosing a node in the
603-
dependency graph to override (the 3-part version number is required). The
604-
value of each key is the same as the `[dependencies]` syntax for specifying
605-
dependencies, except that you can't specify features. Note that when a crate
606-
is overridden the copy it's overridden with must have both the same name and
607-
version, but it can come from a different source (e.g., git or a local path).
608-
609-
More information about overriding dependencies can be found in the [overriding
610-
dependencies][replace] section of the documentation.
611521

612522
[`cargo init`]: ../commands/cargo-init.md
613523
[`cargo new`]: ../commands/cargo-new.md
@@ -619,7 +529,6 @@ dependencies][replace] section of the documentation.
619529
[spdx-2.1-license-expressions]: https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60
620530
[spdx-license-list-3.6]: https://github.com/spdx/license-list-data/tree/v3.6
621531
[SPDX site]: https://spdx.org/license-list
622-
[patch]: #the-patch-section
623532

624533
<script>
625534
(function() {
@@ -639,6 +548,9 @@ dependencies][replace] section of the documentation.
639548
"#rules": "features.html#rules",
640549
"#usage-in-end-products": "features.html#usage-in-end-products",
641550
"#usage-in-packages": "features.html#usage-in-packages",
551+
"#the-patch-section": "overriding-dependencies.html#the-patch-section",
552+
"#using-patch-with-multiple-versions": "overriding-dependencies.html#using-patch-with-multiple-versions",
553+
"#the-replace-section": "overriding-dependencies.html#the-replace-section",
642554
};
643555
var target = fragments[window.location.hash];
644556
if (target) {

0 commit comments

Comments
 (0)