|
| 1 | +--- |
| 2 | +source: src/lib.rs |
| 3 | +expression: content |
| 4 | +input_file: site/2014/11/20/Cargo.html |
| 5 | +snapshot_kind: text |
| 6 | +--- |
| 7 | +<!DOCTYPE html> |
| 8 | +<html lang="en"> |
| 9 | + <head> |
| 10 | + <meta charset="utf-8"> |
| 11 | + <title>Cargo: Rust's community crate host | Rust Blog</title> |
| 12 | + <meta name="viewport" content="width=device-width,initial-scale=1.0"> |
| 13 | +<meta name="description" content="Empowering everyone to build reliable and efficient software."> |
| 14 | + <!-- Twitter card --> |
| 15 | + <meta name="twitter:card" content="summary"> |
| 16 | + <meta name="twitter:site" content="@rustlang"> |
| 17 | + <meta name="twitter:creator" content="@rustlang"> |
| 18 | + <meta name="twitter:title" content="Cargo: Rust's community crate host | Rust Blog"> |
| 19 | + <meta name="twitter:description" content="Empowering everyone to build reliable and efficient software."> |
| 20 | + <meta name="twitter:image" content="https://www.rust-lang.org/static/images/rust-social.jpg"> |
| 21 | + |
| 22 | + <!-- Facebook OpenGraph --> |
| 23 | + <meta property="og:title" content="Cargo: Rust's community crate host | Rust Blog" /> |
| 24 | + <meta property="og:description" content="Empowering everyone to build reliable and efficient software."> |
| 25 | + <meta property="og:image" content="https://www.rust-lang.org/static/images/rust-social-wide.jpg" /> |
| 26 | + <meta property="og:type" content="website" /> |
| 27 | + <meta property="og:locale" content="en_US" /> |
| 28 | + |
| 29 | + <!-- styles --> |
| 30 | + <link rel="stylesheet" href="../../../styles/vendor.css"/> |
| 31 | + <link rel="stylesheet" href="../../../styles/fonts.css"/> |
| 32 | + <link rel="stylesheet" href="../../../styles/app.css"/> |
| 33 | + <link rel="stylesheet" href="../../../styles/highlight.css"/> |
| 34 | + |
| 35 | + <!-- stylesheet for user agents without js --> |
| 36 | + <noscript> |
| 37 | + <link rel="stylesheet" href="../../../styles/noscript.css"> |
| 38 | + </noscript> |
| 39 | + |
| 40 | + <!-- favicon --> |
| 41 | + <link rel="apple-touch-icon" sizes="180x180" href="../../../images/apple-touch-icon.png"> |
| 42 | + <link rel="icon" type="image/png" sizes="16x16" href="../../../images/favicon-16x16.png"> |
| 43 | + <link rel="icon" type="image/png" sizes="32x32" href="../../../images/favicon-32x32.png"> |
| 44 | + <link rel="icon" type="image/svg+xml" href="../../../images/favicon.svg"> |
| 45 | + <link rel="manifest" href="../../../images/site.webmanifest"> |
| 46 | + <link rel="mask-icon" href="../../../images/safari-pinned-tab.svg" color="#5bbad5"> |
| 47 | + <meta name="msapplication-TileColor" content="#00aba9"> |
| 48 | + <meta name="theme-color" content="#ffffff"> |
| 49 | + |
| 50 | + <!-- atom --> |
| 51 | + <link type="application/atom+xml" rel="alternate" href="https://blog.rust-lang.org/feed.xml" title="Rust Blog" /> |
| 52 | + |
| 53 | + <!-- theme switcher --> |
| 54 | + <script src="../../../scripts/theme-switch.js"></script> |
| 55 | + </head> |
| 56 | + <body> |
| 57 | + <nav class="flex flex-row justify-center justify-end-l items-center flex-wrap ph2 pl3-ns pr4-ns"> |
| 58 | + <div class="brand flex-auto w-100 w-auto-l self-start tc tl-l"> |
| 59 | + <a href="../../../"> |
| 60 | + <img class="v-mid ml0-l rust-logo" alt="Rust Logo" src="../../../images/rust-logo-blk.svg"> |
| 61 | + <span class="dib ml1 ml0-l">Rust Blog</span> |
| 62 | + </a> |
| 63 | + </div> |
| 64 | + |
| 65 | + <ul class="nav list w-100 w-auto-l flex flex-none flex-row flex-wrap justify-center justify-end-l items-center pv2 ph0 ph4-ns"> |
| 66 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org">Rust</a></li> |
| 67 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org/tools/install">Install</a></li> |
| 68 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org/learn">Learn</a></li> |
| 69 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org/tools">Tools</a></li> |
| 70 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org/governance">Governance</a></li> |
| 71 | + <li class="tc pv2 ph2 ph4-ns flex-20-s"><a href="https://www.rust-lang.org/community">Community</a></li> |
| 72 | + <button class="theme-icon" onclick="dropdown();">🖌 |
| 73 | + <ul id="theme-choice"> |
| 74 | + <li class="theme-item" onclick="changeThemeTo('light');">Light</li> |
| 75 | + <li class="theme-item" onclick="changeThemeTo('dark');">Dark</li> |
| 76 | + <li class="theme-item" onclick="changeThemeTo('system');">System</li> |
| 77 | + </ul> |
| 78 | + </button> |
| 79 | + <script src="../../../scripts/theme-switch-post.js"></script> |
| 80 | + </ul> |
| 81 | + </nav> |
| 82 | +<section id="Cargo: Rust's community crate host" class="white"> |
| 83 | + <div class="w-100 mw-none ph3 mw8-m mw8-l center f3"> |
| 84 | + <header> |
| 85 | + <h2>Cargo: Rust's community crate host</h2> |
| 86 | + <div class="highlight mt2 mb3"></div> |
| 87 | + </header> |
| 88 | + |
| 89 | + <div class="publish-date-author">Nov. 20, 2014 · Alex Crichton |
| 90 | + |
| 91 | + </div> |
| 92 | + |
| 93 | + <div class="post"> |
| 94 | + <p>Today it is my pleasure to announce that <a href="https://crates.io/">crates.io</a> is |
| 95 | +online and ready for action. The site is a central location to |
| 96 | +discover/download Rust crates, and Cargo is ready to start publishing to it |
| 97 | +today. For the next few months, we are asking that intrepid early adopters |
| 98 | +<a href="https://doc.crates.io/crates-io.html">help us</a> get the registry battle-tested.</p> |
| 99 | +<p>Until Rust itself is stable early next year, registry dependencies will need to |
| 100 | +be updated often. Production users may want to continue using git dependencies |
| 101 | +until then.</p> |
| 102 | +<h2><a href="#what-is-cargo" aria-hidden="true" class="anchor" id="what-is-cargo"></a>What is Cargo?</h2> |
| 103 | +<p>Cargo is a package manager <a href="https://www.rust-lang.org/">for Rust</a>, <a href="https://github.com/rust-lang/cargo">in |
| 104 | +Rust</a>. Managing dependencies is a |
| 105 | +fundamentally difficult problem, but fortunately over the last decade there's |
| 106 | +been a lot of progress in the design of package managers. Designed by Carl |
| 107 | +Lerche and Yehuda Katz, Cargo follows the tradition of successes like |
| 108 | +<a href="https://bundler.io/">Bundler</a> and <a href="https://www.npmjs.org/">NPM</a>:</p> |
| 109 | +<ol> |
| 110 | +<li> |
| 111 | +<p>Cargo leverages crates.io to foster a thriving community of crates that can |
| 112 | +easily interoperate with one another and last for years to come.</p> |
| 113 | +</li> |
| 114 | +<li> |
| 115 | +<p>Cargo releases developers from the worry of managing dependencies and ensures |
| 116 | +that all collaborators are building the same code.</p> |
| 117 | +</li> |
| 118 | +<li> |
| 119 | +<p>Cargo lets your dependencies say how they should be built, and manages the |
| 120 | +entire build process for you.</p> |
| 121 | +</li> |
| 122 | +</ol> |
| 123 | +<h2><a href="#a-community-on-cargo" aria-hidden="true" class="anchor" id="a-community-on-cargo"></a>A Community on Cargo</h2> |
| 124 | +<p>To get a feel for how Cargo achieves its goals, let's take a look at some of |
| 125 | +its core mechanics.</p> |
| 126 | +<h3><a href="#declaring-dependencies" aria-hidden="true" class="anchor" id="declaring-dependencies"></a>Declaring Dependencies</h3> |
| 127 | +<p>Cargo makes depending on third-party code as easy as depending on the standard |
| 128 | +library. When using Cargo, each crate will have an associated |
| 129 | +<a href="https://doc.crates.io/manifest.html">manifest</a> to describe itself and its |
| 130 | +dependencies. Adding a new dependency is now as simple as adding one line to the |
| 131 | +manifest, and this ease has allowed Cargo in just a few short months to enable a |
| 132 | +large and growing network of Rust projects and libraries which were simply |
| 133 | +infeasible before.</p> |
| 134 | +<p>Cargo alone, however, is not quite the entire solution. Discovering dependencies |
| 135 | +is still difficult, and ensuring that these dependencies are available for years |
| 136 | +to come is also not guaranteed.</p> |
| 137 | +<h3><a href="#cratesio" aria-hidden="true" class="anchor" id="cratesio"></a>crates.io</h3> |
| 138 | +<p>To pair with Cargo, the central crates.io site serves as a single location for |
| 139 | +publishing and discovering libraries. This repository serves as permanent |
| 140 | +storage for releases of crates over time to ensure that projects can always |
| 141 | +build with the exact same versions years later. Up until now, users of Cargo |
| 142 | +have largely just downloaded dependencies directly from the source GitHub |
| 143 | +repository, but the primary source will now be shifting to crates.io.</p> |
| 144 | +<p>Other programming language communities have been quite successful with this form |
| 145 | +of central repository. For example <a href="https://rubygems.org/">rubygems.org</a> is your |
| 146 | +one-stop-shop for <a href="https://bundler.io/">Bundler</a> dependencies and |
| 147 | +<a href="https://www.npmjs.org/">npmjs.org</a> has had over 600 million downloads in just |
| 148 | +this month alone! We intend for crates.io to serve a similar role for Rust as a |
| 149 | +critical piece of infrastructure for <a href="https://blog.rust-lang.org/2014/10/30/Stability.html">Rust's long-term stability story at |
| 150 | +1.0</a>.</p> |
| 151 | +<h2><a href="#versioning-and-reproducible-builds" aria-hidden="true" class="anchor" id="versioning-and-reproducible-builds"></a>Versioning and Reproducible Builds</h2> |
| 152 | +<p>Over the past few years, the concept of <a href="https://semver.org/">Semantic |
| 153 | +Versioning</a> has gained traction as a way for library |
| 154 | +developers to easily and clearly communicate with users when they make breaking |
| 155 | +changes. The core idea of semantic versioning is simple: each new release is |
| 156 | +categorized as a minor or major release, and only major releases can introduce |
| 157 | +breakage. Cargo allows you to specify version ranges for your dependencies, with |
| 158 | +the default meaning of "compatible with".</p> |
| 159 | +<p>When specifying a version range, applications often end up requesting |
| 160 | +multiple versions of a single crate, and Cargo solves this by selecting the |
| 161 | +highest version of each major version ("stable code") requested. This highly |
| 162 | +encourages using stable distributions while still allowing duplicates of |
| 163 | +unstable code (pre-1.0 and git for example).</p> |
| 164 | +<p>Once the set of dependencies and their versions have been calculated, Cargo |
| 165 | +generates a <a href="https://doc.crates.io/guide.html#cargo.toml-vs-cargo.lock"><code>Cargo.lock</code></a> to encode this information. This "lock file" is |
| 166 | +then distributed to collaborators of applications to ensure that the crates |
| 167 | +being built remain the same from one build to the next, across times, machines, |
| 168 | +and environments.</p> |
| 169 | +<h2><a href="#building-code" aria-hidden="true" class="anchor" id="building-code"></a>Building Code</h2> |
| 170 | +<p>Up to this point we've seen how Cargo facilitates discovery and reuse of |
| 171 | +community projects while managing what versions to use. Now Cargo just has to |
| 172 | +deal with the problem of actually compiling all this code!</p> |
| 173 | +<p>With a deep understanding of the Rust code that it is building, Cargo is able to |
| 174 | +provide some nice standard features as well as some Rust-specific features:</p> |
| 175 | +<ul> |
| 176 | +<li> |
| 177 | +<p>By default, Cargo builds as many crates in parallel as possible. This not only |
| 178 | +applies to upstream dependencies being built in parallel, but also items for |
| 179 | +the local crate such as test suites, binaries, and unit tests.</p> |
| 180 | +</li> |
| 181 | +<li> |
| 182 | +<p>Cargo supports unit testing out of the box both for crates themselves and in |
| 183 | +the form of integration tests. This even includes example programs to ensure |
| 184 | +they don't bitrot.</p> |
| 185 | +</li> |
| 186 | +<li> |
| 187 | +<p>Cargo generates documentation for all crates in a dependency graph, and it can |
| 188 | +even run <a href="https://doc.rust-lang.org/rustdoc.html#testing-the-documentation">Rust's documentation |
| 189 | +tests</a> to |
| 190 | +ensure examples in documentation stay up to date.</p> |
| 191 | +</li> |
| 192 | +<li> |
| 193 | +<p>Cargo can run a <a href="https://doc.crates.io/build-script.html">build script</a> before any crate is compiled to |
| 194 | +perform tasks such as code generation, compiling native dependencies, or |
| 195 | +detecting native dependencies on the local system.</p> |
| 196 | +</li> |
| 197 | +<li> |
| 198 | +<p>Cargo supports cross compilation out of the box. Cross compiling is done by |
| 199 | +simply specifying a <code>--target</code> options and Cargo will manage tasks such as |
| 200 | +compiling plugins and other build dependencies for the right platform.</p> |
| 201 | +</li> |
| 202 | +</ul> |
| 203 | +<h2><a href="#what-else-is-in-store" aria-hidden="true" class="anchor" id="what-else-is-in-store"></a>What else is in store?</h2> |
| 204 | +<p>The launch of crates.io is a key step in moving the Cargo ecosystem forward, |
| 205 | +but the story does not end here. Usage of crates.io is architected assuming a |
| 206 | +stable compiler, which should be <a href="https://blog.rust-lang.org/2014/09/15/Rust-1.0.html">coming soon</a>! There are also a |
| 207 | +number of extensions to crates.io such as a hosted documentation service or a CI |
| 208 | +build infrastructure hook which could be built out using the crates.io APIs.</p> |
| 209 | +<p>This is just the beginning for crates.io, and I'm excited to start finding all |
| 210 | +Rust crates from one location. I can't wait to see what the registry looks like |
| 211 | +at 1.0, and I can only fathom what it will look like after 1.0!</p> |
| 212 | + |
| 213 | + </div> |
| 214 | + </div> |
| 215 | +</section> |
| 216 | + <footer> |
| 217 | + <div class="w-100 mw-none ph3 mw8-m mw9-l center f3"> |
| 218 | + <div class="row"> |
| 219 | + <div class="four columns mt3 mt0-l" id="get-help"> |
| 220 | + <h4>Get help!</h4> |
| 221 | + <ul> |
| 222 | + <li><a href="https://doc.rust-lang.org" target="_blank" rel="noopener">Documentation</a></li> |
| 223 | + <li><a href="mailto:core-team@rust-lang.org">Contact the Rust Team</a></li> |
| 224 | + </ul> |
| 225 | + </div> |
| 226 | + <div class="four columns mt3 mt0-l"> |
| 227 | + <h4>Terms and policies</h4> |
| 228 | + <ul> |
| 229 | + <li><a href="https://www.rust-lang.org/policies/code-of-conduct">Code of Conduct</a></li> |
| 230 | + <li><a href="https://www.rust-lang.org/policies/licenses">Licenses</a></li> |
| 231 | + <li><a href="https://www.rust-lang.org/policies/media-guide">Logo Policy and Media Guide</a></li> |
| 232 | + <li><a href="https://www.rust-lang.org/policies/security">Security Disclosures</a></li> |
| 233 | + <li><a href="https://www.rust-lang.org/policies">All Policies</a></li> |
| 234 | + </ul> |
| 235 | + </div> |
| 236 | + <div class="four columns mt3 mt0-l"> |
| 237 | + <h4>Social</h4> |
| 238 | + <div class="flex flex-row flex-wrap"> |
| 239 | + <a rel="me" href="https://social.rust-lang.org/@rust" target="_blank" rel="noopener" alt="mastodon link"><img src="../../../images/mastodon.svg" alt="mastodon logo" title="Mastodon"/></a> |
| 240 | + <a href="https://twitter.com/rustlang" target="_blank" rel="noopener" alt="twitter link"><img src="../../../images/twitter.svg" alt="twitter logo" title="Twitter"/></a> |
| 241 | + <a href="https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA" target="_blank" rel="noopener" alt="youtube link"><img style="padding-top: 6px; padding-bottom:6px" src="../../../images/youtube.svg" alt="youtube logo" title="YouTube"/></a> |
| 242 | + <a href="https://discord.gg/rust-lang" target="_blank" rel="noopener" alt="discord link"><img src="../../../images/discord.svg" alt="discord logo" title="Discord"/></a> |
| 243 | + <a href="https://github.com/rust-lang" target="_blank" rel="noopener" alt="github link"><img src="../../../images/github.svg" alt="github logo" title="GitHub"/></a> |
| 244 | + </div> |
| 245 | + <h4 class="mt4 mb3">RSS</h4> |
| 246 | + <ul> |
| 247 | + <li><a href="../../../feed.xml">Main Blog</a></li> |
| 248 | + <li><a href="../../../inside-rust/feed.xml">"Inside Rust" Blog</a></li> |
| 249 | + </ul> |
| 250 | + </div> |
| 251 | + |
| 252 | + </div> |
| 253 | + <div class="attribution"> |
| 254 | + Maintained by the Rust Team. See a typo? |
| 255 | + <a href="https://github.com/rust-lang/blog.rust-lang.org" target="_blank" rel="noopener">Send a fix here</a>! |
| 256 | + </div> |
| 257 | + </div> |
| 258 | + </footer> |
| 259 | + |
| 260 | + <!-- scripts --> |
| 261 | + <script src="../../../scripts/highlight.js"></script> |
| 262 | + </body> |
| 263 | +</html> |
0 commit comments