Skip to content

Commit c4773dc

Browse files
committed
deploy: d141188
1 parent 4813f30 commit c4773dc

File tree

4 files changed

+148
-150
lines changed

4 files changed

+148
-150
lines changed

print.html

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,31 +1423,31 @@ <h2 id="what-to-test"><a class="header" href="#what-to-test">What to test?</a></
14231423
it is time to package and release it!</p>
14241424
<p>There are a few approaches,
14251425
and we’ll look at three of them
1426-
from quickest to set up to most convenient for users.</p>
1426+
from quickest to set up to most convenient for users.</p>
14271427
<h2 id="quickest-cargo-publish"><a class="header" href="#quickest-cargo-publish">Quickest: <code>cargo publish</code></a></h2>
14281428
<p>The easiest way to publish your app is with cargo.
14291429
Do you remember how we added external dependencies to our project?
1430-
Cargo downloaded them from its default crate registry”, <a href="https://crates.io/">crates.io</a>.
1430+
Cargo downloaded them from its default crate registry: <a href="https://crates.io/">crates.io</a>.
14311431
With <code>cargo publish</code>,
1432-
you too can publish crates to <a href="https://crates.io/">crates.io</a>.
1433-
And this works for all crates,
1432+
you can publish crates to <a href="https://crates.io/">crates.io</a>,
1433+
and this works for all crates,
14341434
including those with binary targets.</p>
1435-
<p>Publishing a crate to <a href="https://crates.io/">crates.io</a> is pretty straightforward:
1436-
If you haven’t already, create an account on <a href="https://crates.io/">crates.io</a>.
1437-
Currently, this is done via authorizing you on GitHub,
1435+
<p>Publishing a crate to <a href="https://crates.io/">crates.io</a> can be done in a few steps.
1436+
First, if you haven’t already, create an account on <a href="https://crates.io/">crates.io</a>,
1437+
which is done by authorizing you on GitHub,
14381438
so you’ll need to have a GitHub account
1439-
(and be logged in there).
1440-
Next, you log in using cargo on your local machine.
1439+
and be logged in there.
1440+
Second, you log in using cargo on your local machine.
14411441
For that, go to your
14421442
<a href="https://crates.io/me">crates.io account page</a>,
14431443
create a new token,
1444-
and then run <code>cargo login &lt;your-new-token&gt;</code>.
1444+
and run <code>cargo login &lt;your-new-token&gt;</code>.
14451445
You only need to do this once per computer.
14461446
You can learn more about this
14471447
in cargo’s <a href="https://doc.rust-lang.org/1.39.0/cargo/reference/publishing.html">publishing guide</a>.</p>
1448-
<p>Now that cargo as well as crates.io know you,
1448+
<p>Now that cargo and crates.io know you,
14491449
you are ready to publish crates.
1450-
Before you hastily go ahead and publish a new crate (version),
1450+
Before you hastily go ahead and publish a new crate version,
14511451
it’s a good idea to open your <code>Cargo.toml</code> once more
14521452
and make sure you added the necessary metadata.
14531453
You can find all the possible fields you can set
@@ -1469,57 +1469,57 @@ <h2 id="quickest-cargo-publish"><a class="header" href="#quickest-cargo-publish"
14691469
<p><strong>Note:</strong>
14701470
This example includes the mandatory license field
14711471
with a common choice for Rust projects:
1472-
The same license that is also used for the compiler itself.
1472+
The same license that is used for the compiler itself.
14731473
It also refers to a <code>README.md</code> file.
1474-
It should include a quick description of what your project is about,
1474+
It should include a quick description of what your project is about
14751475
and will be included not only on the crates.io page of your crate,
1476-
but also what GitHub shows by default on repository pages.</p>
1476+
but GitHub shows it by default on repository pages.</p>
14771477
</aside>
14781478
<h3 id="how-to-install-a-binary-from-cratesio"><a class="header" href="#how-to-install-a-binary-from-cratesio">How to install a binary from crates.io</a></h3>
14791479
<p>We’ve seen how to publish a crate to crates.io,
14801480
and you might be wondering how to install it.
14811481
In contrast to libraries,
14821482
which cargo will download and compile for you
1483-
when you run <code>cargo build</code> (or a similar command),
1483+
when you run <code>cargo build</code> or a similar command,
14841484
you’ll need to tell it to explicitly install binaries.</p>
14851485
<p>This is done using
14861486
<code>cargo install &lt;crate-name&gt;</code>.
1487-
It will by default download the crate,
1487+
It will download the crate by default,
14881488
compile all the binary targets it contains
14891489
(in “release” mode, so it might take a while)
14901490
and copy them into the <code>~/.cargo/bin/</code> directory.
1491-
(Make sure that your shell knows to look there for binaries!)</p>
1491+
Make sure that your shell knows to look there for binaries!</p>
14921492
<p>It’s also possible to
14931493
install crates from git repositories,
14941494
only install specific binaries of a crate,
14951495
and specify an alternative directory to install them to.
14961496
Have a look at <code>cargo install --help</code> for details.</p>
14971497
<h3 id="when-to-use-it"><a class="header" href="#when-to-use-it">When to use it</a></h3>
14981498
<p><code>cargo install</code> is a simple way to install a binary crate.
1499-
It’s very convenient for Rust developers to use,
1499+
It’s very convenient for Rust developers to use
15001500
but has some significant downsides:
15011501
Since it will always compile your source from scratch,
15021502
users of your tool will need to have
1503-
Rust, cargo, and all other system dependencies your project requires
1504-
to be installed on their machine.
1505-
Compiling large Rust codebases can also take some time.</p>
1503+
Rust, cargo, and all other system dependencies that your project requires
1504+
installed on their machine.
1505+
Compiling large Rust codebases can take some time.</p>
15061506
<p>It’s best to use this for distributing tools
15071507
that are targeted at other Rust developers.
1508-
For example:
1509-
A lot of cargo subcommands
1508+
For example,
1509+
a lot of cargo subcommands
15101510
like <code>cargo-tree</code> or <code>cargo-outdated</code>
15111511
can be installed with it.</p>
15121512
<h2 id="distributing-binaries"><a class="header" href="#distributing-binaries">Distributing binaries</a></h2>
15131513
<p>Rust is a language that compiles to native code
1514-
and by default statically links all dependencies.
1514+
and statically links all dependencies by default.
15151515
When you run <code>cargo build</code>
15161516
on your project that contains a binary called <code>grrs</code>,
15171517
you’ll end up with a binary file called <code>grrs</code>.
1518-
Try it out:
1518+
Try it out!
15191519
Using <code>cargo build</code>, it’ll be <code>target/debug/grrs</code>,
15201520
and when you run <code>cargo build --release</code>, it’ll be <code>target/release/grrs</code>.
15211521
Unless you use crates
1522-
that explicitly need external libraries to be installed on the target system
1522+
that explicitly need external libraries installed on the target system
15231523
(like using the system’s version of OpenSSL),
15241524
this binary will only depend on common system libraries.
15251525
That means,
@@ -1531,61 +1531,61 @@ <h2 id="distributing-binaries"><a class="header" href="#distributing-binaries">D
15311531
There is no need to have Rust installed on the user’s machine,
15321532
and instead of it taking a minute to compile,
15331533
they can instantly run the binary.</p>
1534-
<p>So, as we’ve seen,
1534+
<p>As we’ve seen,
15351535
<code>cargo build</code> <em>already</em> builds binaries for us.
1536-
The only issue is,
1536+
The issue is that
15371537
those are not guaranteed to work on all platforms.
15381538
If you run <code>cargo build</code> on your Windows machine,
15391539
you won’t get a binary that works on a Mac by default.
15401540
Is there a way to generate these binaries
1541-
for all the interesting platforms
1541+
for all of the target platforms
15421542
automatically?</p>
15431543
<h3 id="building-binary-releases-on-ci"><a class="header" href="#building-binary-releases-on-ci">Building binary releases on CI</a></h3>
15441544
<p>If your tool is open sourced
15451545
and hosted on GitHub,
15461546
it’s quite easy to set up a free CI (continuous integration) service
15471547
like <a href="https://travis-ci.com/">Travis CI</a>.
1548-
(There are other services that also work on other platforms, but Travis is very popular.)
1549-
This basically runs setup commands
1548+
There are other services that offer this functionality, but Travis is very popular.
1549+
This runs setup commands
15501550
in a virtual machine
15511551
each time you push changes to your repository.
15521552
What those commands are,
15531553
and the types of machines they run on,
15541554
is configurable.
1555-
For example:
1556-
A good idea is to run <code>cargo test</code>
1555+
For example,
1556+
a good idea is to run <code>cargo test</code>
15571557
on a machine with Rust and some common build tools installed.
15581558
If this fails,
15591559
you know there are issues in the most recent changes.</p>
15601560
<p>We can also use this
15611561
to build binaries and upload them to GitHub!
1562-
Indeed, if we run
1562+
If we run
15631563
<code>cargo build --release</code>
15641564
and upload the binary somewhere,
15651565
we should be all set, right?
15661566
Not quite.
15671567
We still need to make sure the binaries we build
15681568
are compatible with as many systems as possible.
15691569
For example,
1570-
on Linux we can compile not for the current system,
1571-
but instead for the <code>x86_64-unknown-linux-musl</code> target,
1572-
to not depend on default system libraries.
1570+
on Linux we can compile for the current system
1571+
or the <code>x86_64-unknown-linux-musl</code> target and
1572+
not depend on default system libraries.
15731573
On macOS, we can set <code>MACOSX_DEPLOYMENT_TARGET</code> to <code>10.7</code>
15741574
to only depend on system features present in versions 10.7 and older.</p>
15751575
<p>You can see one example of building binaries using this approach
15761576
<a href="https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.travis.yml#L74-L91">here</a> for Linux and macOS
1577-
and <a href="https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.appveyor.yml">here</a> for Windows (using AppVeyor).</p>
1578-
<p>Another way is to use pre-built (Docker) images
1577+
and <a href="https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.appveyor.yml">here</a> for Windows using AppVeyor.</p>
1578+
<p>Another way is to use pre-built (i.e. Docker) images
15791579
that contain all the tools we need
15801580
to build binaries.
1581-
This allows us to easily target more exotic platforms, too.
1581+
This allows us to easily target more exotic platforms as well.
15821582
The <a href="https://github.com/japaric/trust">trust</a> project contains
15831583
scripts that you can include in your project
1584-
as well as instructions on how to set this up.
1584+
and instructions on how to set this up.
15851585
It also includes support for Windows using AppVeyor.</p>
15861586
<p>If you’d rather set this up locally
15871587
and generate the release files on your own machine,
1588-
still have a look at trust.
1588+
have a look at <a href="https://github.com/japaric/trust">trust</a>.
15891589
It uses <a href="https://github.com/rust-embedded/cross">cross</a> internally,
15901590
which works similar to cargo
15911591
but forwards commands to a cargo process inside a Docker container.
@@ -1595,48 +1595,47 @@ <h3 id="how-to-install-these-binaries"><a class="header" href="#how-to-install-t
15951595
<p>You point your users to your release page
15961596
that might look something <a href="https://github.com/rustwasm/wasm-pack/releases/tag/v0.5.1">like this one</a>,
15971597
and they can download the artifacts we’ve just created.
1598-
The release artifacts we’ve just generated are nothing special:
1599-
At the end, they are just archive files that contain our binaries!
1598+
The release artifacts we’ve generated are nothing special.
1599+
They are just archive files that contain our binaries!
16001600
This means that users of your tool
16011601
can download them with their browser,
1602-
extract them (often happens automatically),
1602+
extract them (often automatically),
16031603
and copy the binaries to a place they like.</p>
1604-
<p>This does require some experience with manually installing programs,
1604+
<p>This does require some experience with manually installing programs,
16051605
so you want to add a section to your README file
16061606
on how to install this program.</p>
16071607
<aside class="note">
16081608
<p><strong>Note:</strong>
1609-
If you used <a href="https://github.com/japaric/trust">trust</a> to build your binaries and added them to GitHub releases,
1609+
If you use <a href="https://github.com/japaric/trust">trust</a> to build your binaries and add them to GitHub releases,
16101610
you can also tell people to run
16111611
<code>curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git your-name/repo-name</code>
16121612
if you think that makes it easier.</p>
16131613
</aside>
16141614
<h3 id="when-to-use-it-1"><a class="header" href="#when-to-use-it-1">When to use it</a></h3>
1615-
<p>Having binary releases is a good idea in general,
1616-
there’s hardly any downside to it.
1615+
<p>Having binary releases is a good idea in general.
1616+
There’s hardly any downside to it.
16171617
It does not solve the problem of users having to manually
16181618
install and update
16191619
your tools,
1620-
but they can quickly get the latest releases version
1620+
but they can quickly get the latest release’s version
16211621
without the need to install Rust.</p>
16221622
<h3 id="what-to-package-in-addition-to-your-binaries"><a class="header" href="#what-to-package-in-addition-to-your-binaries">What to package in addition to your binaries</a></h3>
16231623
<p>Right now,
16241624
when a user downloads our release builds,
16251625
they will get a <code>.tar.gz</code> file
16261626
that only contains binary files.
1627-
So, in our example project,
1628-
they will just get a single <code>grrs</code> file they can run.
1629-
But there are some more files we already have in our repository
1627+
In our example project,
1628+
they will just get a single <code>grrs</code> file they can run,
1629+
but there are more files we already have in our repository
16301630
that they might want to have.
1631-
The README file that tells them how to use this tool,
1631+
The README file that tells them how to use this tool
16321632
and the license file(s),
16331633
for example.
16341634
Since we already have them,
16351635
they are easy to add.</p>
1636-
<p>There are some more interesting files
1637-
that make sense especially for command-line tools,
1638-
though:
1639-
How about we also ship a man page in addition to that README file,
1636+
<p>There are more interesting files
1637+
that make sense, especially for command-line tools.
1638+
How about we ship a man page in addition to that README file
16401639
and config files that add completions of the possible flags to your shell?
16411640
You can write these by hand,
16421641
but <em>clap</em>, the argument parsing library we use
@@ -1646,21 +1645,21 @@ <h3 id="what-to-package-in-addition-to-your-binaries"><a class="header" href="#w
16461645
for more details.</p>
16471646
<h2 id="getting-your-app-into-package-repositories"><a class="header" href="#getting-your-app-into-package-repositories">Getting your app into package repositories</a></h2>
16481647
<p>Both approaches we’ve seen so far
1649-
are not how you typically install software on your machine.
1650-
Especially command-line tools
1648+
are not how you typically install software on your machine,
1649+
especially for command-line tools that
16511650
you install using global package managers
16521651
on most operating systems.
16531652
The advantages for users are quite obvious:
1654-
There is no need to think about how to install your program,
1655-
if it can be installed the same way as they install the other tools.
1653+
There is no need to think about how to install your program
1654+
if it can be installed the same way as they install other tools.
16561655
These package managers also allow users to update their programs
16571656
when a new version is available.</p>
16581657
<p>Sadly, supporting different systems means
16591658
you’ll have to look at how these different systems work.
16601659
For some,
16611660
it might be as easy as adding a file to your repository
16621661
(e.g. adding a Formula file like <a href="https://github.com/BurntSushi/ripgrep/blob/31adff6f3c4bfefc9e77df40871f2989443e6827/pkg/brew/ripgrep-bin.rb">this</a> for macOS’s <code>brew</code>),
1663-
but for others you’ll often need to send in patches yourself
1662+
but for others, you’ll often need to send in patches yourself
16641663
and add your tool to their repositories.
16651664
There are helpful tools like
16661665
<a href="https://crates.io/crates/cargo-bundle">cargo-bundle</a>,
@@ -1676,16 +1675,16 @@ <h3 id="an-example-ripgrep"><a class="header" href="#an-example-ripgrep">An exam
16761675
<p><a href="https://github.com/BurntSushi/ripgrep">ripgrep</a> is an alternative to <code>grep</code>/<code>ack</code>/<code>ag</code> and is written in Rust.
16771676
It’s quite successful and is packaged for many operating systems:
16781677
Just look at <a href="https://github.com/BurntSushi/ripgrep/tree/31adff6f3c4bfefc9e77df40871f2989443e6827#installation">the “Installation” section</a> of its README!</p>
1679-
<p>Note that it lists a few different options how you can install it:
1680-
It starts with a link to the GitHub releases
1681-
which contain the binaries so you can download them directly;
1682-
then it lists how to install it using a bunch of different package managers;
1683-
finally, you can also install it using <code>cargo install</code>.</p>
1684-
<p>This seems like a very good idea:
1685-
Don’t pick and choose one of the approaches presented here,
1686-
but start with <code>cargo install</code>,
1687-
add binary releases,
1688-
and finally start distributing your tool using system package managers.</p>
1678+
<p>Note that it lists a few different options on how you can install it:
1679+
It starts with a link to the GitHub releases,
1680+
which contain the binaries so that you can download them directly,
1681+
it lists how to install it using a bunch of different package managers,
1682+
and you can also install it using <code>cargo install</code>.</p>
1683+
<p>This seems like a very good idea.
1684+
Don’t pick and choose one of the approaches presented here.
1685+
Start with <code>cargo install</code>
1686+
and add binary releases
1687+
before finally distributing your tool using system package managers.</p>
16891688
<div style="break-before: page; page-break-before: always;"></div><h1 id="in-depth-topics"><a class="header" href="#in-depth-topics">In-depth topics</a></h1>
16901689
<p>A small collection of chapters covering some more details
16911690
that you might care about when writing your command line application.</p>

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)