Skip to content

Commit 28d9745

Browse files
committed
Write Specifying Dependencies page
1 parent f477f30 commit 28d9745

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,119 @@
11
# Specifying Dependencies
2+
3+
Your packages can depend on other libraries from Git repositories or subdirectories on your local file system.
4+
5+
## Specifying dependencies from Git repositories
6+
7+
To depend on a package located in a Git repository, the minimum information needed to specify is the location of the repository with the `git` key:
8+
9+
```toml /git/1
10+
[dependencies]
11+
quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git" }
12+
```
13+
14+
Scarb will fetch the `git` repository at this location and then look for a `Scarb.toml` for the requested package anywhere inside the Git repository
15+
(not necessarily at the root of it - for example, if repository contains multiple packages in subdirectories).
16+
17+
Since no other information has been specified, Scarb assumes that it is intended to use the latest commit on the main branch.
18+
You can combine the `git` key with `branch`, `tag` and `rev` keys to specify something else.
19+
Here is an example of specifying that you want to use the latest commit on a branch named `next`:
20+
21+
```toml /branch = "next"/
22+
[dependencies]
23+
quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git", branch = "next" }
24+
```
25+
26+
Anything that is not a branch or tag falls under `rev`.
27+
This can be a commit (short) hash, like `rev = "1f06df93"{:toml}`, or a named reference exposed by the remote repository such as `rev = "refs/pull/330/head"{:toml}`.
28+
What references are available varies by where the repository is hosted; GitHub in particular exposes a reference to the most recent commit of every pull request as shown, but other Git hosts often provide something equivalent, possibly under a different naming scheme.
29+
30+
## Specifying path dependencies
31+
32+
Scarb supports path dependencies, which are typically sub-packages that live within one repository.
33+
To depend on a package located in a local directory, you need to specify the path to it, relative to current `Scarb.toml`, with the `path` key:
34+
35+
```toml /path/1
36+
[dependencies]
37+
hello_utils = { path = "hello_utils" }
38+
```
39+
40+
Scarb does not cache path dependencies, any changes made in them will be reflected immediately in builds of your package.
41+
42+
## Version requirements
43+
44+
Scarb allows you to specify version requirements of dependencies with the `version` key:
45+
46+
```toml /version = "1.0.0"/
47+
[dependencies]
48+
hello_utils = { version = "1.0.0", path = "hello_utils" }
49+
```
50+
51+
The string `"1.0.0"{:toml}` is a version requirement.
52+
Although it looks like a specific version of the `hello_utils` package, it actually specifies a _range_ of versions and allows [SemVer](https://semver.org/) compatible updates.
53+
Scarb uses Rust's SemVer flavour, in a way implemented by the [`semver`](https://crates.io/crates/semver) crate.
54+
An update is allowed if the new version number does not modify the left-most non-zero digit in the major, minor, patch grouping.
55+
56+
Here are some more examples of version requirements and the versions that would be allowed with them:
57+
58+
```
59+
1.2.3 := >=1.2.3, <2.0.0
60+
1.2 := >=1.2.0, <2.0.0
61+
1 := >=1.0.0, <2.0.0
62+
0.2.3 := >=0.2.3, <0.3.0
63+
0.2 := >=0.2.0, <0.3.0
64+
0.0.3 := >=0.0.3, <0.0.4
65+
0.0 := >=0.0.0, <0.1.0
66+
0 := >=0.0.0, <1.0.0
67+
```
68+
69+
This compatibility convention is different from SemVer in the way it treats versions before 1.0.0.
70+
While SemVer says there is no compatibility before 1.0.0, Scarb considers `0.x.y` to be compatible with `0.x.z`, where `y ≥ z` and `x > 0`.
71+
72+
It is possible to further tweak the logic for selecting compatible versions using special operators, though it shouldn't be necessary most of the time.
73+
74+
### Caret requirements
75+
76+
Caret requirements are an alternative syntax for the default strategy, `^1.2.3` is exactly equivalent to `1.2.3`.
77+
78+
### Tilde requirements
79+
80+
Tilde requirements specify a minimal version with some ability to update.
81+
If you specify a major, minor, and patch version or only a major and minor version, only patch-level changes are allowed.
82+
If you only specify a major version, then minor- and patch-level changes are allowed.
83+
84+
`~1.2.3` is an example of a tilde requirement.
85+
86+
```
87+
~1.2.3 := >=1.2.3, <1.3.0
88+
~1.2 := >=1.2.0, <1.3.0
89+
~1 := >=1.0.0, <2.0.0
90+
```
91+
92+
### Wildcard requirements
93+
94+
Wildcard requirements allow for any version where the wildcard is positioned.
95+
96+
`*`, `1.*` and `1.2.*` are examples of wildcard requirements.
97+
98+
```
99+
* := >=0.0.0
100+
1.* := >=1.0.0, <2.0.0
101+
1.2.* := >=1.2.0, <1.3.0
102+
```
103+
104+
### Comparison requirements
105+
106+
Comparison requirements allow manually specifying a version range or an exact version to depend on.
107+
108+
Here are some examples of comparison requirements:
109+
110+
```
111+
>= 1.2.0
112+
> 1
113+
< 2
114+
= 1.2.3
115+
```
116+
117+
### Multiple requirements
118+
119+
As shown in the examples above, multiple version requirements can be separated with a comma, e.g., `>= 1.2, < 1.5`.

0 commit comments

Comments
 (0)