6
6
# Summary
7
7
[ summary ] : #summary
8
8
9
- This RFC proposes the concept of * augmenting sources* for Cargo. Sources can be
9
+ This RFC proposes the concept of * patching sources* for Cargo. Sources can be
10
10
have their existing versions of crates replaced with different copies, and
11
11
sources can also have "prepublished" crates by adding versions of a crate which
12
12
do not currently exist in the source. Dependency resolution will work * as if*
@@ -75,32 +75,32 @@ publication to crates.io.
75
75
[ design ] : #detailed-design
76
76
77
77
The design itself is relatively straightforward. The Cargo.toml file will
78
- support a new section for augmenting a source of crates:
78
+ support a new section for patching a source of crates:
79
79
80
80
``` toml
81
- [augment .crates-io ]
81
+ [patch .crates-io ]
82
82
xml-rs = { path = " path/to/fork" }
83
83
```
84
84
85
85
The listed dependencies have the same syntax as the normal ` [dependencies] `
86
86
section, but they must all come form a different source than the source being
87
- augmented . For example you can't augment crates.io with other crates from
87
+ patched . For example you can't patch crates.io with other crates from
88
88
crates.io! Cargo will load the crates and extract the version information for
89
89
each dependency's name, supplementing the source specified with the version it
90
90
finds. If the same name/version pair * already* exists in the source being
91
- augmented , then this will act just like ` [replace] ` , replacing its source with
92
- the one specified in the ` [augment ] ` section.
91
+ patched , then this will act just like ` [replace] ` , replacing its source with
92
+ the one specified in the ` [patch ] ` section.
93
93
94
- Like ` [replace] ` , the ` [augment ] ` section is only taken into account for the
94
+ Like ` [replace] ` , the ` [patch ] ` section is only taken into account for the
95
95
root crate (or workspace root); allowing it to accumulate anywhere in the crate
96
96
dependency graph creates intractable problems for dependency resolution.
97
97
98
- The sub-table of ` [augment ] ` (where ` crates-io ` is used above) is used to
99
- specify the source that's being augmented . Cargo will know ahead of time one
98
+ The sub-table of ` [patch ] ` (where ` crates-io ` is used above) is used to
99
+ specify the source that's being patched . Cargo will know ahead of time one
100
100
identifier, literally ` crates-io ` , but otherwise this field will currently be
101
101
interpreted as a URL of a source. The name ` crates-io ` will correspond to the
102
102
crates.io index, and other urls, such as git repositories, may also be specified
103
- for augmentation . Eventually it's intended we'll grow support for multiple
103
+ for patching . Eventually it's intended we'll grow support for multiple
104
104
registries here with their own identifiers, but for now just literally
105
105
` crates-io ` and other URLs are allowed.
106
106
@@ -121,7 +121,7 @@ With this setup, the dependency graph for Servo will contain *two* versions of
121
121
` 0.9.1 ` is considered a minor release against ` 0.9.0 ` , while ` 0.9.0 ` and ` 0.8.0 `
122
122
are incompatible.
123
123
124
- ### Scenario: augmenting with a bugfix
124
+ ### Scenario: patching with a bugfix
125
125
126
126
Let's say that while developing ` foo ` we've got a lock file pointing to ` xml-rs `
127
127
` 0.9.0 ` , and we found the ` 0.9.0 ` branch of ` xml-rs ` that hasn't been touched
@@ -132,7 +132,7 @@ First we'll check out `foo` locally and implement what we believe is a fix for
132
132
this bug, and next, we change ` Cargo.toml ` for ` foo ` :
133
133
134
134
``` toml
135
- [augment .crates-io ]
135
+ [patch .crates-io ]
136
136
xml-rs = { path = " ../xml-rs" }
137
137
```
138
138
@@ -153,7 +153,7 @@ that all of Servo compiles before pushing the changes through.
153
153
First, we change ` Cargo.toml ` for ` foo ` :
154
154
155
155
``` toml
156
- [augment .crates-io ]
156
+ [patch .crates-io ]
157
157
xml-rs = { git = " https://github.com/aturon/xml-rs" , branch = " 0.9.2" }
158
158
159
159
[dependencies ]
@@ -165,15 +165,15 @@ or introduce any `xml-rs` dependencies; it's enough to be using the fork of
165
165
` foo ` , which we would be anyway:
166
166
167
167
``` toml
168
- [augment .crates-io ]
168
+ [patch .crates-io ]
169
169
xml-rs = { git = " https://github.com/aturon/xml-rs" , branch = " 0.9.2" }
170
170
foo = { git = " https://github.com/aturon/foo" , branch = " fix-xml" }
171
171
```
172
172
173
173
Note that if Servo depended directly on ` foo ` it would also be valid to do:
174
174
175
175
``` toml
176
- [augment .crates-io ]
176
+ [patch .crates-io ]
177
177
xml-rs = { git = " https://github.com/aturon/xml-rs" , branch = " 0.9.2" }
178
178
179
179
[dependencies ]
@@ -195,7 +195,7 @@ want to do integration testing for (`servo`); no sibling crates needed to be
195
195
changed.
196
196
197
197
Once ` xml-rs ` version ` 0.9.2 ` is actually published, we will likely be able to
198
- remove the ` [augment ] ` sections. This is a discrete step that must be taken by
198
+ remove the ` [patch ] ` sections. This is a discrete step that must be taken by
199
199
crate authors, however (e.g. doesn't happen automatically) because the actual
200
200
published 0.9.2 may not be precisely what we thought it was going to be. For
201
201
example more changes could have been merged, it may not actually fix the bug,
@@ -207,7 +207,7 @@ What happens if `foo` instead needs to make a breaking change to `xml-rs`? The
207
207
workflow is identical. For ` foo ` :
208
208
209
209
``` toml
210
- [augment .crates-io ]
210
+ [patch .crates-io ]
211
211
xml-rs = { git = " https://github.com/aturon/xml-rs" , branch = " 0.10.0" }
212
212
213
213
[dependencies ]
@@ -217,7 +217,7 @@ xml-rs = "0.10.0"
217
217
For ` servo ` :
218
218
219
219
``` toml
220
- [augment .crates-io ]
220
+ [patch .crates-io ]
221
221
xml-rs = { git = " https://github.com/aturon/xml-rs" , branch = " 0.10.0" }
222
222
223
223
[dependencies ]
@@ -238,13 +238,13 @@ error message).
238
238
239
239
## Impact on ` Cargo.lock `
240
240
241
- Usage of ` [augment ] ` will perform backwards-incompatible modifications to
242
- ` Cargo.lock ` , meaning that usage of ` [augment ] ` will prevent previous versions
241
+ Usage of ` [patch ] ` will perform backwards-incompatible modifications to
242
+ ` Cargo.lock ` , meaning that usage of ` [patch ] ` will prevent previous versions
243
243
of Cargo from interpreting the lock file. Cargo will unconditionally resolve all
244
- entries in the ` [augment ] ` section to precise dependencies, encoding them all in
244
+ entries in the ` [patch ] ` section to precise dependencies, encoding them all in
245
245
the lock file whether they're used or not.
246
246
247
- Dependencies formed on crates listed in ` [augment ] ` will then be listed directly
247
+ Dependencies formed on crates listed in ` [patch ] ` will then be listed directly
248
248
in Cargo.lock, and the original listed crate will not be listed. In our example
249
249
above we had:
250
250
@@ -260,7 +260,7 @@ Note, however, that the lock file will still mention `xml-rs-0.8.0` and
260
260
` xml-rs-0.9.1 ` because ` bar ` and ` baz ` depend on it.
261
261
262
262
To help put some TOML where our mouth is let's say we depend on ` env_logger ` but
263
- we're using ` [augment ] ` to depend on a git version of the ` log ` crate, a
263
+ we're using ` [patch ] ` to depend on a git version of the ` log ` crate, a
264
264
dependency of ` env_logger ` . First we'll have our ` Cargo.toml ` including:
265
265
266
266
``` toml
@@ -288,11 +288,11 @@ version = "0.3.7"
288
288
source = " registry+https://github.com/rust-lang/crates.io-index"
289
289
```
290
290
291
- Next up we'll add our ` [augment ] ` section to crates.io:
291
+ Next up we'll add our ` [patch ] ` section to crates.io:
292
292
293
293
``` toml
294
294
# Cargo.toml
295
- [augment .crates-io ]
295
+ [patch .crates-io ]
296
296
log = { git = ' https://github.com/rust-lang-nursery/log' }
297
297
```
298
298
@@ -315,17 +315,17 @@ source = "git+https://github.com/rust-lang-nursery/log#cb9fa28812ac27c9cadc4e7b1
315
315
```
316
316
317
317
Notably ` log ` from crates.io * is not mentioned at all here* , and crucially so!
318
- Additionally Cargo has the fully resolved version of the ` log ` augmentation
318
+ Additionally Cargo has the fully resolved version of the ` log ` patch
319
319
available to it, down to the sha of what to check out.
320
320
321
321
When Cargo rebuilds from this ` Cargo.lock ` it will not query the registry for
322
322
versions of ` log ` , instead seeing that there's an exact dependency on the git
323
- repository (from the ` Cargo.lock ` ) and the repository is listed as an
324
- augmentation , so it'll follow that pointer.
323
+ repository (from the ` Cargo.lock ` ) and the repository is listed as a
324
+ patch , so it'll follow that pointer.
325
325
326
326
## Impact on ` [replace] `
327
327
328
- The ` [augment ] ` section in the manifest can in many ways be seen as a "replace
328
+ The ` [patch ] ` section in the manifest can in many ways be seen as a "replace
329
329
2.0". It is, in fact, strictly more expressive than the current ` [replace] `
330
330
section! For example these two sections are equivalent:
331
331
@@ -335,30 +335,30 @@ section! For example these two sections are equivalent:
335
335
336
336
# is the same as...
337
337
338
- [augment .crates-io ]
338
+ [patch .crates-io ]
339
339
log = { git = ' https://github.com/rust-lang-nursery/log' }
340
340
```
341
341
342
- This is not accidental! The intial development of the ` [augment ] ` feature was
342
+ This is not accidental! The intial development of the ` [patch ] ` feature was
343
343
actually focused on prepublishing dependencies and was called ` [prepublish] ` ,
344
344
but while discussing it a conclusion was reached that ` [prepublish] ` already
345
345
allowed replacing existing versions in a registry, but issued a warning when
346
346
doing so. It turned out that without a warning we ended up having a full-on
347
347
` [replace] ` replacement!
348
348
349
349
At this time, though, it is not planned to deprecate the ` [replace] ` section,
350
- nor remove it. After the ` [augment ] ` section is implemented, if it ends up
351
- working out this may change. If after a few cycles on stable the ` [augment ] `
350
+ nor remove it. After the ` [patch ] ` section is implemented, if it ends up
351
+ working out this may change. If after a few cycles on stable the ` [patch ] `
352
352
section seems to be working well we can issue an official deprecation for
353
353
` [replace] ` , printing a warning if it's still used.
354
354
355
- Documentation, however, will immediately begin to recommend ` [augment ] ` over
355
+ Documentation, however, will immediately begin to recommend ` [patch ] ` over
356
356
` [replace] ` .
357
357
358
358
# How We Teach This
359
359
[ how-we-teach-this ] : #how-we-teach-this
360
360
361
- Augmentation is a feature intended for large-scale projects spanning many repos
361
+ Patching is a feature intended for large-scale projects spanning many repos
362
362
and crates, where you want to make something like an atomic change across the
363
363
repos. As such, it should likely be explained in a dedicated section for
364
364
large-scale Cargo usage, which would also include build system integration and
@@ -369,8 +369,8 @@ this RFC) is generally enough to explain it. In the docs, these examples should
369
369
be spelled out in greater detail.
370
370
371
371
Most notably, however, the [ overriding dependenices] [ over ] section of Cargo's
372
- documentation will be rewritten to primarily mention ` [augment ] ` , but
373
- ` [replace] ` will be mentioned still with a recommendation to use ` [augment ] `
372
+ documentation will be rewritten to primarily mention ` [patch ] ` , but
373
+ ` [replace] ` will be mentioned still with a recommendation to use ` [patch ] `
374
374
instead if possible.
375
375
376
376
[ over ] : http://doc.crates.io/specifying-dependencies.html#overriding-dependencies
0 commit comments