@@ -43,8 +43,8 @@ file consists of the following sections:
43
43
* [ ` [target] ` ] ( specifying-dependencies.md#platform-specific-dependencies ) — Platform-specific dependencies.
44
44
* [ ` [badges] ` ] ( #the-badges-section ) — Badges to display on [ crates.io] .
45
45
* [ ` [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).
48
48
* [ ` [profile] ` ] ( profiles.md ) — Compiler settings and optimizations.
49
49
* [ ` [workspace] ` ] ( workspaces.md ) — The workspace definition.
50
50
@@ -517,97 +517,7 @@ The `[profile]` tables provide a way to customize compiler settings such as
517
517
optimizations and debug settings. See [ the Profiles chapter] ( profiles.md ) for
518
518
more detail.
519
519
520
- ### The ` [patch] ` Section
521
520
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.
611
521
612
522
[ `cargo init` ] : ../commands/cargo-init.md
613
523
[ `cargo new` ] : ../commands/cargo-new.md
@@ -619,7 +529,6 @@ dependencies][replace] section of the documentation.
619
529
[ spdx-2.1-license-expressions ] : https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60
620
530
[ spdx-license-list-3.6 ] : https://github.com/spdx/license-list-data/tree/v3.6
621
531
[ SPDX site ] : https://spdx.org/license-list
622
- [ patch ] : #the-patch-section
623
532
624
533
<script >
625
534
(function () {
@@ -639,6 +548,9 @@ dependencies][replace] section of the documentation.
639
548
" #rules" : " features.html#rules" ,
640
549
" #usage-in-end-products" : " features.html#usage-in-end-products" ,
641
550
" #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" ,
642
554
};
643
555
var target = fragments[window .location .hash ];
644
556
if (target) {
0 commit comments