You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The same license that is also used for the compiler itself.
1472
+
The same license that is used for the compiler itself.
1473
1473
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
1475
1475
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>
1477
1477
</aside>
1478
1478
<h3id="how-to-install-a-binary-from-cratesio"><aclass="header" href="#how-to-install-a-binary-from-cratesio">How to install a binary from crates.io</a></h3>
1479
1479
<p>We’ve seen how to publish a crate to crates.io,
1480
1480
and you might be wondering how to install it.
1481
1481
In contrast to libraries,
1482
1482
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,
1484
1484
you’ll need to tell it to explicitly install binaries.</p>
1485
1485
<p>This is done using
1486
1486
<code>cargo install <crate-name></code>.
1487
-
It will by default download the crate,
1487
+
It will download the crate by default,
1488
1488
compile all the binary targets it contains
1489
1489
(in “release” mode, so it might take a while)
1490
1490
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>
1492
1492
<p>It’s also possible to
1493
1493
install crates from git repositories,
1494
1494
only install specific binaries of a crate,
1495
1495
and specify an alternative directory to install them to.
1496
1496
Have a look at <code>cargo install --help</code> for details.</p>
1497
1497
<h3id="when-to-use-it"><aclass="header" href="#when-to-use-it">When to use it</a></h3>
1498
1498
<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
1500
1500
but has some significant downsides:
1501
1501
Since it will always compile your source from scratch,
1502
1502
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>
1506
1506
<p>It’s best to use this for distributing tools
1507
1507
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
1510
1510
like <code>cargo-tree</code> or <code>cargo-outdated</code>
There is no need to have Rust installed on the user’s machine,
1532
1532
and instead of it taking a minute to compile,
1533
1533
they can instantly run the binary.</p>
1534
-
<p>So, as we’ve seen,
1534
+
<p>As we’ve seen,
1535
1535
<code>cargo build</code><em>already</em> builds binaries for us.
1536
-
The only issue is,
1536
+
The issue is that
1537
1537
those are not guaranteed to work on all platforms.
1538
1538
If you run <code>cargo build</code> on your Windows machine,
1539
1539
you won’t get a binary that works on a Mac by default.
1540
1540
Is there a way to generate these binaries
1541
-
for all the interesting platforms
1541
+
for all of the target platforms
1542
1542
automatically?</p>
1543
1543
<h3id="building-binary-releases-on-ci"><aclass="header" href="#building-binary-releases-on-ci">Building binary releases on CI</a></h3>
1544
1544
<p>If your tool is open sourced
1545
1545
and hosted on GitHub,
1546
1546
it’s quite easy to set up a free CI (continuous integration) service
1547
1547
like <ahref="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
1550
1550
in a virtual machine
1551
1551
each time you push changes to your repository.
1552
1552
What those commands are,
1553
1553
and the types of machines they run on,
1554
1554
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>
1557
1557
on a machine with Rust and some common build tools installed.
1558
1558
If this fails,
1559
1559
you know there are issues in the most recent changes.</p>
1560
1560
<p>We can also use this
1561
1561
to build binaries and upload them to GitHub!
1562
-
Indeed, if we run
1562
+
If we run
1563
1563
<code>cargo build --release</code>
1564
1564
and upload the binary somewhere,
1565
1565
we should be all set, right?
1566
1566
Not quite.
1567
1567
We still need to make sure the binaries we build
1568
1568
are compatible with as many systems as possible.
1569
1569
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.
1573
1573
On macOS, we can set <code>MACOSX_DEPLOYMENT_TARGET</code> to <code>10.7</code>
1574
1574
to only depend on system features present in versions 10.7 and older.</p>
1575
1575
<p>You can see one example of building binaries using this approach
1576
1576
<ahref="https://github.com/rustwasm/wasm-pack/blob/51e6351c28fbd40745719e6d4a7bf26dadd30c85/.travis.yml#L74-L91">here</a> for Linux and macOS
1577
-
and <ahref="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 <ahref="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
1579
1579
that contain all the tools we need
1580
1580
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.
1582
1582
The <ahref="https://github.com/japaric/trust">trust</a> project contains
1583
1583
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.
1585
1585
It also includes support for Windows using AppVeyor.</p>
1586
1586
<p>If you’d rather set this up locally
1587
1587
and generate the release files on your own machine,
1588
-
still have a look at trust.
1588
+
have a look at <ahref="https://github.com/japaric/trust">trust</a>.
1589
1589
It uses <ahref="https://github.com/rust-embedded/cross">cross</a> internally,
1590
1590
which works similar to cargo
1591
1591
but forwards commands to a cargo process inside a Docker container.
that might look something <ahref="https://github.com/rustwasm/wasm-pack/releases/tag/v0.5.1">like this one</a>,
1597
1597
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!
1600
1600
This means that users of your tool
1601
1601
can download them with their browser,
1602
-
extract them (often happens automatically),
1602
+
extract them (often automatically),
1603
1603
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,
1605
1605
so you want to add a section to your README file
1606
1606
on how to install this program.</p>
1607
1607
<asideclass="note">
1608
1608
<p><strong>Note:</strong>
1609
-
If you used<ahref="https://github.com/japaric/trust">trust</a> to build your binaries and added them to GitHub releases,
1609
+
If you use<ahref="https://github.com/japaric/trust">trust</a> to build your binaries and add them to GitHub releases,
1610
1610
you can also tell people to run
1611
1611
<code>curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git your-name/repo-name</code>
1612
1612
if you think that makes it easier.</p>
1613
1613
</aside>
1614
1614
<h3id="when-to-use-it-1"><aclass="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.
1617
1617
It does not solve the problem of users having to manually
1618
1618
install and update
1619
1619
your tools,
1620
-
but they can quickly get the latest releases version
1620
+
but they can quickly get the latest release’s version
1621
1621
without the need to install Rust.</p>
1622
1622
<h3id="what-to-package-in-addition-to-your-binaries"><aclass="header" href="#what-to-package-in-addition-to-your-binaries">What to package in addition to your binaries</a></h3>
1623
1623
<p>Right now,
1624
1624
when a user downloads our release builds,
1625
1625
they will get a <code>.tar.gz</code> file
1626
1626
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
1630
1630
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
1632
1632
and the license file(s),
1633
1633
for example.
1634
1634
Since we already have them,
1635
1635
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
1640
1639
and config files that add completions of the possible flags to your shell?
1641
1640
You can write these by hand,
1642
1641
but <em>clap</em>, the argument parsing library we use
<h2id="getting-your-app-into-package-repositories"><aclass="header" href="#getting-your-app-into-package-repositories">Getting your app into package repositories</a></h2>
1648
1647
<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
1651
1650
you install using global package managers
1652
1651
on most operating systems.
1653
1652
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.
1656
1655
These package managers also allow users to update their programs
1657
1656
when a new version is available.</p>
1658
1657
<p>Sadly, supporting different systems means
1659
1658
you’ll have to look at how these different systems work.
1660
1659
For some,
1661
1660
it might be as easy as adding a file to your repository
1662
1661
(e.g. adding a Formula file like <ahref="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
<p><ahref="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.
1677
1676
It’s quite successful and is packaged for many operating systems:
1678
1677
Just look at <ahref="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>
0 commit comments