|
4 | 4 |
|
5 | 5 | Subcommands of Cargo frequently need to refer to a particular package within a
|
6 | 6 | dependency graph for various operations like updating, cleaning, building, etc.
|
7 |
| -To solve this problem, Cargo supports Package ID Specifications. A specification |
| 7 | +To solve this problem, Cargo supports *Package ID Specifications*. A specification |
8 | 8 | is a string which is used to uniquely refer to one package within a graph of
|
9 | 9 | packages.
|
10 | 10 |
|
| 11 | +The specification may be fully qualified, such as |
| 12 | +`https://github.com/rust-lang/crates.io-index#regex:1.4.3` or it may be |
| 13 | +abbreviated, such as `regex`. The abbreviated form may be used as long as it |
| 14 | +uniquely identifies a single package in the dependency graph. If there is |
| 15 | +ambiguity, additional qualifiers can be added to make it unique. For example, |
| 16 | +if there are two versions of the `regex` package in the graph, then it can be |
| 17 | +qualified with a version to make it unique, such as `regex:1.4.3`. |
| 18 | + |
11 | 19 | #### Specification grammar
|
12 | 20 |
|
13 | 21 | The formal grammar for a Package Id Specification is:
|
14 | 22 |
|
15 | 23 | ```notrust
|
16 |
| -pkgid := pkgname |
17 |
| - | [ proto "://" ] hostname-and-path [ "#" ( pkgname | semver ) ] |
| 24 | +spec := pkgname |
| 25 | + | proto "://" hostname-and-path [ "#" ( pkgname | semver ) ] |
18 | 26 | pkgname := name [ ":" semver ]
|
19 | 27 |
|
20 | 28 | proto := "http" | "git" | ...
|
21 | 29 | ```
|
22 | 30 |
|
23 | 31 | Here, brackets indicate that the contents are optional.
|
24 | 32 |
|
| 33 | +The URL form can be used for git dependencies, or to differentiate packages |
| 34 | +that come from different sources such as different registries. |
| 35 | + |
25 | 36 | #### Example specifications
|
26 | 37 |
|
27 |
| -These could all be references to a package `foo` version `1.2.3` from the |
28 |
| -registry at `crates.io` |
29 |
| - |
30 |
| -| pkgid | name | version | url | |
31 |
| -|:-----------------------------|:-----:|:-------:|:----------------------:| |
32 |
| -| `foo` | `foo` | `*` | `*` | |
33 |
| -| `foo:1.2.3` | `foo` | `1.2.3` | `*` | |
34 |
| -| `crates.io/foo` | `foo` | `*` | `*://crates.io/foo` | |
35 |
| -| `crates.io/foo#1.2.3` | `foo` | `1.2.3` | `*://crates.io/foo` | |
36 |
| -| `crates.io/bar#foo:1.2.3` | `foo` | `1.2.3` | `*://crates.io/bar` | |
37 |
| -| `https://crates.io/foo#1.2.3`| `foo` | `1.2.3` | `https://crates.io/foo` | |
| 38 | +The following are references to the `regex` package on `crates.io`: |
| 39 | + |
| 40 | +| Spec | Name | Version | |
| 41 | +|:------------------------------------------------------------|:-------:|:-------:| |
| 42 | +| `regex` | `regex` | `*` | |
| 43 | +| `regex:1.4.3` | `regex` | `1.4.3` | |
| 44 | +| `https://github.com/rust-lang/crates.io-index#regex` | `regex` | `*` | |
| 45 | +| `https://github.com/rust-lang/crates.io-index#regex:1.4.3` | `regex` | `1.4.3` | |
| 46 | + |
| 47 | +The following are some examples of specs for several different git dependencies: |
| 48 | + |
| 49 | +| Spec | Name | Version | |
| 50 | +|:----------------------------------------------------------|:----------------:|:--------:| |
| 51 | +| `https://github.com/rust-lang/cargo#0.52.0` | `cargo` | `0.52.0` | |
| 52 | +| `https://github.com/rust-lang/cargo#cargo-platform:0.1.1` | <nobr>`cargo-platform`</nobr> | `0.1.1` | |
| 53 | +| `ssh://git@github.com/rust-lang/regex.git#regex:1.4.3` | `regex` | `1.4.3` | |
| 54 | + |
| 55 | +Local packages on the filesystem can use `file://` URLs to reference them: |
| 56 | + |
| 57 | +| Spec | Name | Version | |
| 58 | +|:---------------------------------------|:-----:|:-------:| |
| 59 | +| `file:///path/to/my/project/foo` | `foo` | `*` | |
| 60 | +| `file:///path/to/my/project/foo#1.1.8` | `foo` | `1.1.8` | |
38 | 61 |
|
39 | 62 | #### Brevity of specifications
|
40 | 63 |
|
|
0 commit comments