File tree 2 files changed +69
-0
lines changed
2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -958,6 +958,30 @@ technical specification of this feature.
958
958
[ crates.io ] : https://crates.io/
959
959
[ replace ] : specifying-dependencies.md#overriding-dependencies
960
960
961
+ #### Using ` [patch] ` with multiple versions
962
+
963
+ You can patch in multiple versions of the same crate with the ` package ` key used
964
+ to rename dependencies. For example let's say that the ` serde ` crate has a
965
+ bugfix that we'd like to use to its 1.\* series but we'd also like to prototype
966
+ using a 2.0.0 version of serde we have in our git repository. To configure this
967
+ we'd do:
968
+
969
+ ``` toml
970
+ [patch .crates-io ]
971
+ serde = { git = ' https://github.com/serde-rs/serde' }
972
+ serde2 = { git = ' https://github.com/example/serde' , package = ' serde' , branch = ' v2' }
973
+ ```
974
+
975
+ The first ` serde = ... ` directive indicates that serde 1.\* should be used from
976
+ the git repository (pulling in the bugfix we need) and the second ` serde2 = ... `
977
+ directive indicates that the ` serde ` package should also be pulled from the ` v2 `
978
+ branch of ` https://github.com/example/serde ` . We're assuming here that
979
+ ` Cargo.toml ` on that branch mentions version 2.0.0.
980
+
981
+ Note that when using the ` package ` key the ` serde2 ` identifier here is actually
982
+ ignored. We simply need a unique name which doesn't conflict with other patched
983
+ crates.
984
+
961
985
### The ` [replace] ` Section
962
986
963
987
This section of Cargo.toml can be used to [ override dependencies] [ replace ] with
Original file line number Diff line number Diff line change @@ -1134,3 +1134,48 @@ package `[..]`
1134
1134
)
1135
1135
. run ( ) ;
1136
1136
}
1137
+
1138
+ #[ cargo_test]
1139
+ fn multipatch ( ) {
1140
+ Package :: new ( "a" , "1.0.0" ) . publish ( ) ;
1141
+ Package :: new ( "a" , "2.0.0" ) . publish ( ) ;
1142
+ let p = project ( )
1143
+ . file (
1144
+ "Cargo.toml" ,
1145
+ r#"
1146
+ [package]
1147
+ name = "foo"
1148
+ version = "0.0.1"
1149
+
1150
+ [dependencies]
1151
+ a1 = { version = "1", package = "a" }
1152
+ a2 = { version = "2", package = "a" }
1153
+
1154
+ [patch.crates-io]
1155
+ b1 = { path = "a1", package = "a" }
1156
+ b2 = { path = "a2", package = "a" }
1157
+ "# ,
1158
+ )
1159
+ . file ( "src/lib.rs" , "pub fn foo() { a1::f1(); a2::f2(); }" )
1160
+ . file (
1161
+ "a1/Cargo.toml" ,
1162
+ r#"
1163
+ [package]
1164
+ name = "a"
1165
+ version = "1.0.0"
1166
+ "# ,
1167
+ )
1168
+ . file ( "a1/src/lib.rs" , "pub fn f1() {}" )
1169
+ . file (
1170
+ "a2/Cargo.toml" ,
1171
+ r#"
1172
+ [package]
1173
+ name = "a"
1174
+ version = "2.0.0"
1175
+ "# ,
1176
+ )
1177
+ . file ( "a2/src/lib.rs" , "pub fn f2() {}" )
1178
+ . build ( ) ;
1179
+
1180
+ p. cargo ( "build" ) . run ( ) ;
1181
+ }
You can’t perform that action at this time.
0 commit comments