@@ -13,50 +13,79 @@ limit to the number of versions which can be published, however.
13
13
First thing’s first, you’ll need an account on [ crates.io] to acquire
14
14
an API token. To do so, [ visit the home page] [ crates.io ] and log in via a GitHub
15
15
account (required for now). After this, visit your [ Account
16
- Settings] ( https://crates.io/me ) page and run the ` cargo login ` command
16
+ Settings] ( https://crates.io/me ) page and run the [ ` cargo login ` ] command
17
17
specified.
18
18
19
19
``` console
20
20
$ cargo login abcdefghijklmnopqrstuvwxyz012345
21
21
```
22
22
23
23
This command will inform Cargo of your API token and store it locally in your
24
- ` ~/.cargo/credentials ` (previously it was ` ~/.cargo/config ` ). Note that this
25
- token is a ** secret ** and should not be shared with anyone else. If it leaks for
26
- any reason, you should regenerate it immediately.
24
+ ` ~/.cargo/credentials ` . Note that this token is a ** secret ** and should not be
25
+ shared with anyone else. If it leaks for any reason, you should regenerate it
26
+ immediately.
27
27
28
28
### Before publishing a new crate
29
29
30
30
Keep in mind that crate names on [ crates.io] are allocated on a first-come-first-
31
31
serve basis. Once a crate name is taken, it cannot be used for another crate.
32
32
33
+ Check out the [ metadata you can
34
+ specify] ( reference/manifest.html#package-metadata ) in ` Cargo.toml ` to ensure
35
+ your crate can be discovered more easily! Before publishing, make sure you have
36
+ filled out the following fields:
37
+
38
+ - ` authors `
39
+ - ` license ` or ` license-file `
40
+ - ` description `
41
+ - ` homepage `
42
+ - ` documentation `
43
+ - ` repository `
44
+
45
+ It would also be a good idea to include some ` keywords ` and ` categories ` ,
46
+ though they are not required.
47
+
48
+ If you are publishing a library, you may also want to consult the [ Rust API
49
+ Guidelines] .
50
+
33
51
#### Packaging a crate
34
52
35
- The next step is to package up your crate into a format that can be uploaded to
36
- [ crates.io] . For this we’ll use the ` cargo package ` subcommand. This will take
37
- our entire crate and package it all up into a ` *.crate ` file in the
38
- ` target/package ` directory.
53
+ The next step is to package up your crate and upload it to [ crates.io] . For
54
+ this we’ll use the [ ` cargo publish ` ] subcommand. This command performs the following
55
+ steps:
56
+
57
+ 1 . Perform some verification checks on your package.
58
+ 2 . Compress your source code into a ` .crate ` file.
59
+ 3 . Extract the ` .crate ` file into a temporary directory and verify that it
60
+ compiles.
61
+ 4 . Upload the ` .crate ` file to [ crates.io] .
62
+ 5 . The registry will perform some additional checks on the uploaded package
63
+ before adding it.
64
+
65
+ It is recommended that you first run ` cargo publish --dry-run ` (or [ `cargo
66
+ package`] which is equivalent) to ensure there aren't any warnings or errors
67
+ before publishing. This will perform the first three steps listed above.
39
68
40
69
``` console
41
- $ cargo package
70
+ $ cargo publish --dry-run
42
71
```
43
72
44
- As an added bonus, the ` *.crate ` will be verified independently of the current
45
- source tree. After the ` *.crate ` is created, it’s unpacked into
46
- ` target/package ` and then built from scratch to ensure that all necessary files
47
- are there for the build to succeed. This behavior can be disabled with the
48
- ` --no-verify ` flag.
73
+ You can inspect the generated ` .crate ` file in the ` target/package ` directory.
74
+ [ crates.io] currently has a 10MB size limit on the ` .crate ` file. You may want
75
+ to check the size of the ` .crate ` file to ensure you didn't accidentally
76
+ package up large assets that are not required to build your package, such as
77
+ test data, website documentation, or code generation. You can check which
78
+ files are included with the following command:
49
79
50
- Now’s a good time to take a look at the ` *.crate ` file to make sure you didn’t
51
- accidentally package up that 2GB video asset, or large data files used for code
52
- generation, integration tests, or benchmarking. There is currently a 10MB
53
- upload size limit on ` *.crate ` files. So, if the size of ` tests ` and ` benches `
54
- directories and their dependencies are up to a couple of MBs, you can keep them
55
- in your package; otherwise, better to exclude them.
80
+ ``` console
81
+ $ cargo package --list
82
+ ```
56
83
57
84
Cargo will automatically ignore files ignored by your version control system
58
85
when packaging, but if you want to specify an extra set of files to ignore you
59
- can use the ` exclude ` key in the manifest:
86
+ can use the [ ` exclude `
87
+ key] ( reference/manifest.html#the-exclude-and-include-fields-optional ) in the
88
+ manifest:
60
89
61
90
``` toml
62
91
[package ]
@@ -67,10 +96,8 @@ exclude = [
67
96
]
68
97
```
69
98
70
- The syntax of each element in this array is what
71
- [ rust-lang/glob] ( https://github.com/rust-lang/glob ) accepts. If you’d rather
72
- roll with a whitelist instead of a blacklist, Cargo also supports an ` include `
73
- key, which if set, overrides the ` exclude ` key:
99
+ If you’d rather explicitly list the files to include, Cargo also supports an
100
+ ` include ` key, which if set, overrides the ` exclude ` key:
74
101
75
102
``` toml
76
103
[package ]
@@ -83,28 +110,22 @@ include = [
83
110
84
111
### Uploading the crate
85
112
86
- Now that we’ve got a ` *.crate ` file ready to go, it can be uploaded to
87
- [ crates.io] with the ` cargo publish ` command. And that’s it, you’ve now published
88
- your first crate!
113
+ When you are ready to publish, use the [ ` cargo publish ` ] command
114
+ to upload to [ crates.io] :
89
115
90
116
``` console
91
117
$ cargo publish
92
118
```
93
119
94
- If you’d like to skip the ` cargo package ` step, the ` cargo publish ` subcommand
95
- will automatically package up the local crate if a copy isn’t found already.
96
-
97
- Be sure to check out the [ metadata you can
98
- specify] ( reference/manifest.html#package-metadata ) to ensure your crate can be
99
- discovered more easily!
120
+ And that’s it, you’ve now published your first crate!
100
121
101
122
### Publishing a new version of an existing crate
102
123
103
- In order to release a new version, change the ` version ` value specified in your
104
- ` Cargo.toml ` manifest. Keep in mind [ the semver
105
- rules] ( reference/manifest.html#the-version-field ) . Then optionally run ` cargo package ` if
106
- you want to inspect the ` *.crate ` file for the new version before publishing,
107
- and run ` cargo publish ` to upload the new version.
124
+ In order to release a new version, change the ` version ` value specified in
125
+ your ` Cargo.toml ` manifest. Keep in mind [ the semver
126
+ rules] ( reference/manifest.html#the-version-field ) , and consult [ RFC 1105 ] for
127
+ what constitutes a semver-breaking change. Then run [ ` cargo publish ` ] as
128
+ described above to upload the new version.
108
129
109
130
### Managing a crates.io-based crate
110
131
@@ -176,7 +197,7 @@ is likely for you to encounter the following message when working with them:
176
197
> It looks like you don’t have permission to query a necessary property from
177
198
GitHub to complete this request. You may need to re-authenticate on [ crates.io]
178
199
to grant permission to read GitHub org memberships. Just go to
179
- https://crates.io/login
200
+ < https://crates.io/login > .
180
201
181
202
This is basically a catch-all for “you tried to query a team, and one of the
182
203
five levels of membership access control denied this”. That is not an
@@ -195,7 +216,7 @@ you will get the error above. You may also see this error if you ever try to
195
216
publish a crate that you don’t own at all, but otherwise happens to have a team.
196
217
197
218
If you ever change your mind, or just aren’t sure if [ crates.io] has sufficient
198
- permission, you can always go to https://crates.io/login , which will prompt you
219
+ permission, you can always go to < https://crates.io/login > , which will prompt you
199
220
for permission if [ crates.io] doesn’t have all the scopes it would like to.
200
221
201
222
An additional barrier to querying GitHub is that the organization may be
@@ -218,5 +239,11 @@ the “Grant Access” button next to its name:
218
239
219
240
![ Authentication Access Control] ( images/auth-level-acl.png )
220
241
242
+ [ RFC 1105 ] : https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md
243
+ [ Rust API Guidelines ] : https://rust-lang-nursery.github.io/api-guidelines/
244
+ [ `cargo login` ] : commands/cargo-login.html
245
+ [ `cargo package` ] : commands/cargo-package.html
246
+ [ `cargo publish` ] : commands/cargo-publish.html
221
247
[ crates.io ] : https://crates.io/
222
248
[ oauth-scopes ] : https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
249
+
0 commit comments