@@ -5,35 +5,35 @@ it is time to package and release it!
55
66There are a few approaches,
77and we'll look at three of them
8- from " quickest to set up" to " most convenient for users" .
8+ from quickest to set up to most convenient for users.
99
1010## Quickest: ` cargo publish `
1111
1212The easiest way to publish your app is with cargo.
1313Do you remember how we added external dependencies to our project?
14- Cargo downloaded them from its default " crate registry", [ crates.io] .
14+ Cargo downloaded them from its default crate registry: [ crates.io] .
1515With ` cargo publish ` ,
16- you too can publish crates to [ crates.io] .
17- And this works for all crates,
16+ you can publish crates to [ crates.io] ,
17+ and this works for all crates,
1818including those with binary targets.
1919
20- Publishing a crate to [ crates.io] is pretty straightforward:
21- If you haven't already, create an account on [ crates.io] .
22- Currently, this is done via authorizing you on GitHub,
20+ Publishing a crate to [ crates.io] can be done in a few steps.
21+ First, if you haven't already, create an account on [ crates.io] ,
22+ which is done by authorizing you on GitHub,
2323so you'll need to have a GitHub account
24- ( and be logged in there) .
25- Next , you log in using cargo on your local machine.
24+ and be logged in there.
25+ Second , you log in using cargo on your local machine.
2626For that, go to your
2727[ crates.io account page] ,
2828create a new token,
29- and then run ` cargo login <your-new-token> ` .
29+ and run ` cargo login <your-new-token> ` .
3030You only need to do this once per computer.
3131You can learn more about this
3232in cargo's [ publishing guide] .
3333
34- Now that cargo as well as crates.io know you,
34+ Now that cargo and crates.io know you,
3535you are ready to publish crates.
36- Before you hastily go ahead and publish a new crate ( version) ,
36+ Before you hastily go ahead and publish a new crate version,
3737it's a good idea to open your ` Cargo.toml ` once more
3838and make sure you added the necessary metadata.
3939You can find all the possible fields you can set
@@ -59,11 +59,11 @@ categories = ["command-line-utilities"]
5959** Note:**
6060This example includes the mandatory license field
6161with a common choice for Rust projects:
62- The same license that is also used for the compiler itself.
62+ The same license that is used for the compiler itself.
6363It also refers to a ` README.md ` file.
64- It should include a quick description of what your project is about,
64+ It should include a quick description of what your project is about
6565and will be included not only on the crates.io page of your crate,
66- but also what GitHub shows by default on repository pages.
66+ but GitHub shows it by default on repository pages.
6767
6868</aside >
6969
@@ -78,16 +78,16 @@ We've seen how to publish a crate to crates.io,
7878and you might be wondering how to install it.
7979In contrast to libraries,
8080which cargo will download and compile for you
81- when you run ` cargo build ` ( or a similar command) ,
81+ when you run ` cargo build ` or a similar command,
8282you'll need to tell it to explicitly install binaries.
8383
8484This is done using
8585` cargo install <crate-name> ` .
86- It will by default download the crate,
86+ It will download the crate by default ,
8787compile all the binary targets it contains
8888(in "release" mode, so it might take a while)
8989and copy them into the ` ~/.cargo/bin/ ` directory.
90- ( Make sure that your shell knows to look there for binaries!)
90+ Make sure that your shell knows to look there for binaries!
9191
9292It's also possible to
9393install crates from git repositories,
@@ -98,33 +98,33 @@ Have a look at `cargo install --help` for details.
9898### When to use it
9999
100100` cargo install ` is a simple way to install a binary crate.
101- It's very convenient for Rust developers to use,
101+ It's very convenient for Rust developers to use
102102but has some significant downsides:
103103Since it will always compile your source from scratch,
104104users of your tool will need to have
105- Rust, cargo, and all other system dependencies your project requires
106- to be installed on their machine.
107- Compiling large Rust codebases can also take some time.
105+ Rust, cargo, and all other system dependencies that your project requires
106+ installed on their machine.
107+ Compiling large Rust codebases can take some time.
108108
109109It's best to use this for distributing tools
110110that are targeted at other Rust developers.
111- For example:
112- A lot of cargo subcommands
111+ For example,
112+ a lot of cargo subcommands
113113like ` cargo-tree ` or ` cargo-outdated `
114114can be installed with it.
115115
116116## Distributing binaries
117117
118118Rust is a language that compiles to native code
119- and by default statically links all dependencies.
119+ and statically links all dependencies by default .
120120When you run ` cargo build `
121121on your project that contains a binary called ` grrs ` ,
122122you'll end up with a binary file called ` grrs ` .
123- Try it out:
123+ Try it out!
124124Using ` cargo build ` , it'll be ` target/debug/grrs ` ,
125125and when you run ` cargo build --release ` , it'll be ` target/release/grrs ` .
126126Unless you use crates
127- that explicitly need external libraries to be installed on the target system
127+ that explicitly need external libraries installed on the target system
128128(like using the system's version of OpenSSL),
129129this binary will only depend on common system libraries.
130130That means,
@@ -138,14 +138,14 @@ There is no need to have Rust installed on the user's machine,
138138and instead of it taking a minute to compile,
139139they can instantly run the binary.
140140
141- So, as we've seen,
141+ As we've seen,
142142` cargo build ` _ already_ builds binaries for us.
143- The only issue is,
143+ The issue is that
144144those are not guaranteed to work on all platforms.
145145If you run ` cargo build ` on your Windows machine,
146146you won't get a binary that works on a Mac by default.
147147Is there a way to generate these binaries
148- for all the interesting platforms
148+ for all of the target platforms
149149automatically?
150150
151151### Building binary releases on CI
@@ -154,15 +154,15 @@ If your tool is open sourced
154154and hosted on GitHub,
155155it's quite easy to set up a free CI (continuous integration) service
156156like [ Travis CI] .
157- ( There are other services that also work on other platforms , but Travis is very popular.)
158- This basically runs setup commands
157+ There are other services that offer this functionality , but Travis is very popular.
158+ This runs setup commands
159159in a virtual machine
160160each time you push changes to your repository.
161161What those commands are,
162162and the types of machines they run on,
163163is configurable.
164- For example:
165- A good idea is to run ` cargo test `
164+ For example,
165+ a good idea is to run ` cargo test `
166166on a machine with Rust and some common build tools installed.
167167If this fails,
168168you know there are issues in the most recent changes.
@@ -171,39 +171,39 @@ you know there are issues in the most recent changes.
171171
172172We can also use this
173173to build binaries and upload them to GitHub!
174- Indeed, if we run
174+ If we run
175175` cargo build --release `
176176and upload the binary somewhere,
177177we should be all set, right?
178178Not quite.
179179We still need to make sure the binaries we build
180180are compatible with as many systems as possible.
181181For example,
182- on Linux we can compile not for the current system,
183- but instead for the ` x86_64-unknown-linux-musl ` target,
184- to not depend on default system libraries.
182+ on Linux we can compile for the current system
183+ or the ` x86_64-unknown-linux-musl ` target and
184+ not depend on default system libraries.
185185On macOS, we can set ` MACOSX_DEPLOYMENT_TARGET ` to ` 10.7 `
186186to only depend on system features present in versions 10.7 and older.
187187
188188You can see one example of building binaries using this approach
189189[ here] [ wasm-pack-travis ] for Linux and macOS
190- and [ here] [ wasm-pack-appveyor ] for Windows ( using AppVeyor) .
190+ and [ here] [ wasm-pack-appveyor ] for Windows using AppVeyor.
191191
192192[ wasm-pack-travis ] : https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.travis.yml#L74-L91
193193[ wasm-pack-appveyor ] : https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.appveyor.yml
194194
195- Another way is to use pre-built (Docker) images
195+ Another way is to use pre-built (i.e. Docker) images
196196that contain all the tools we need
197197to build binaries.
198- This allows us to easily target more exotic platforms, too .
198+ This allows us to easily target more exotic platforms as well .
199199The [ trust] project contains
200200scripts that you can include in your project
201- as well as instructions on how to set this up.
201+ and instructions on how to set this up.
202202It also includes support for Windows using AppVeyor.
203203
204204If you'd rather set this up locally
205205and generate the release files on your own machine,
206- still have a look at trust.
206+ have a look at [ trust] .
207207It uses [ cross] internally,
208208which works similar to cargo
209209but forwards commands to a cargo process inside a Docker container.
@@ -218,23 +218,23 @@ The definitions of the images are also available in
218218You point your users to your release page
219219that might look something [ like this one] [ wasm-pack-release ] ,
220220and they can download the artifacts we've just created.
221- The release artifacts we've just generated are nothing special:
222- At the end, they are just archive files that contain our binaries!
221+ The release artifacts we've generated are nothing special.
222+ They are just archive files that contain our binaries!
223223This means that users of your tool
224224can download them with their browser,
225- extract them (often happens automatically),
225+ extract them (often automatically),
226226and copy the binaries to a place they like.
227227
228228[ wasm-pack-release ] : https://github.com/rustwasm/wasm-pack/releases/tag/v0.5.1
229229
230- This does require some experience with manually " installing" programs,
230+ This does require some experience with manually installing programs,
231231so you want to add a section to your README file
232232on how to install this program.
233233
234234<aside class =" note " >
235235
236236** Note:**
237- If you used [ trust] to build your binaries and added them to GitHub releases,
237+ If you use [ trust] to build your binaries and add them to GitHub releases,
238238you can also tell people to run
239239` curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git your-name/repo-name `
240240if you think that makes it easier.
@@ -243,12 +243,12 @@ if you think that makes it easier.
243243
244244### When to use it
245245
246- Having binary releases is a good idea in general,
247- there 's hardly any downside to it.
246+ Having binary releases is a good idea in general.
247+ There 's hardly any downside to it.
248248It does not solve the problem of users having to manually
249249install and update
250250your tools,
251- but they can quickly get the latest releases version
251+ but they can quickly get the latest release's version
252252without the need to install Rust.
253253
254254### What to package in addition to your binaries
@@ -257,20 +257,19 @@ Right now,
257257when a user downloads our release builds,
258258they will get a ` .tar.gz ` file
259259that only contains binary files.
260- So, in our example project,
261- they will just get a single ` grrs ` file they can run.
262- But there are some more files we already have in our repository
260+ In our example project,
261+ they will just get a single ` grrs ` file they can run,
262+ but there are more files we already have in our repository
263263that they might want to have.
264- The README file that tells them how to use this tool,
264+ The README file that tells them how to use this tool
265265and the license file(s),
266266for example.
267267Since we already have them,
268268they are easy to add.
269269
270- There are some more interesting files
271- that make sense especially for command-line tools,
272- though:
273- How about we also ship a man page in addition to that README file,
270+ There are more interesting files
271+ that make sense, especially for command-line tools.
272+ How about we ship a man page in addition to that README file
274273and config files that add completions of the possible flags to your shell?
275274You can write these by hand,
276275but _ clap_ , the argument parsing library we use
@@ -286,13 +285,13 @@ for more details.
286285## Getting your app into package repositories
287286
288287Both approaches we've seen so far
289- are not how you typically install software on your machine.
290- Especially command-line tools
288+ are not how you typically install software on your machine,
289+ especially for command-line tools that
291290you install using global package managers
292291on most operating systems.
293292The advantages for users are quite obvious:
294- There is no need to think about how to install your program,
295- if it can be installed the same way as they install the other tools.
293+ There is no need to think about how to install your program
294+ if it can be installed the same way as they install other tools.
296295These package managers also allow users to update their programs
297296when a new version is available.
298297
@@ -301,7 +300,7 @@ you'll have to look at how these different systems work.
301300For some,
302301it might be as easy as adding a file to your repository
303302(e.g. adding a Formula file like [ this] [ rg-formula ] for macOS's ` brew ` ),
304- but for others you'll often need to send in patches yourself
303+ but for others, you'll often need to send in patches yourself
305304and add your tool to their repositories.
306305There are helpful tools like
307306[ cargo-bundle] ( https://crates.io/crates/cargo-bundle ) ,
@@ -323,17 +322,17 @@ and that is available in many different package managers.
323322It's quite successful and is packaged for many operating systems:
324323Just look at [ the "Installation" section] [ rg-install ] of its README!
325324
326- Note that it lists a few different options how you can install it:
327- It starts with a link to the GitHub releases
328- which contain the binaries so you can download them directly;
329- then it lists how to install it using a bunch of different package managers;
330- finally, you can also install it using ` cargo install ` .
331-
332- This seems like a very good idea:
333- Don't pick and choose one of the approaches presented here,
334- but start with ` cargo install ` ,
335- add binary releases,
336- and finally start distributing your tool using system package managers.
325+ Note that it lists a few different options on how you can install it:
326+ It starts with a link to the GitHub releases,
327+ which contain the binaries so that you can download them directly,
328+ it lists how to install it using a bunch of different package managers,
329+ and you can also install it using ` cargo install ` .
330+
331+ This seems like a very good idea.
332+ Don't pick and choose one of the approaches presented here.
333+ Start with ` cargo install `
334+ and add binary releases
335+ before finally distributing your tool using system package managers.
337336
338337[ ripgrep ] : https://github.com/BurntSushi/ripgrep
339338[ rg-install ] : https://github.com/BurntSushi/ripgrep/tree/31adff6f3c4bfefc9e77df40871f2989443e6827#installation
0 commit comments