blob: d17249d00f7a4a4cfee99317833817fbac7ff8c7 [file] [log] [blame] [view] [edit]
% Cargo, Rusts Package Manager
# Installing
The easiest way to get Cargo is to get the current stable release of Rust by
using the `rustup` script:
```shell
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
```
This will get you the current stable release of Rust for your platform along
with the latest Cargo.
If you are on Windows, you can directly download the latest 32bit ([Rust](https://static.rust-lang.org/dist/rust-1.0.0-i686-pc-windows-gnu.msi)
and [Cargo](https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-windows-gnu.tar.gz)) or 64bit ([Rust](https://static.rust-lang.org/dist/rust-1.0.0-x86_64-pc-windows-gnu.msi) and [Cargo](https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-pc-windows-gnu.tar.gz)) Rust stable releases or Cargo nightlies.
Alternatively, you can build Cargo from source.
# Let’s get started
To start a new project with Cargo, use `cargo new`:
```shell
$ cargo new hello_world --bin
```
Were passing `--bin` because were making a binary program: if we
were making a library, wed leave it off.
Lets check out what Cargo has generated for us:
```shell
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
```
This is all we need to get started. First, lets check out `Cargo.toml`:
```toml
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
```
This is called a **manifest**, and it contains all of the metadata that Cargo
needs to compile your project.
Heres whats in `src/main.rs`:
```
fn main() {
println!("Hello, world!");
}
```
Cargo generated a hello world for us. Lets compile it:
<pre><code class="language-shell">$ cargo build
<span style="font-weight: bold"
class="s1"> Compiling</span> hello_world v0.1.0 (file:///path/to/project/hello_world)</code></pre>
And then run it:
```shell
$ ./target/debug/hello_world
Hello, world!
```
We can also use `cargo run` to compile and then run it, all in one step:
<pre><code class="language-shell">$ cargo run
<span style="font-weight: bold"
class="s1"> Fresh</span> hello_world v0.1.0 (file:///path/to/project/hello_world)
<span style="font-weight: bold"
class="s1"> Running</span> `target/hello_world`
Hello, world!</code></pre>
# Going further
For more details on using Cargo, check out the [Cargo Guide](guide.html)