From 0685e7a185d8687f2886af72b63965cbfdc2525e Mon Sep 17 00:00:00 2001 From: Alexander Bliskovsky Date: Mon, 23 Feb 2015 16:06:49 -0500 Subject: [PATCH 1/2] Added section on `cargo new` to "Hello Cargo!" chapter. --- src/doc/trpl/hello-cargo.md | 60 ++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 5eb6cd7c5cd3a..de2ce2d9edebf 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -18,6 +18,8 @@ the Cargo README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies) for specific instructions about installing it. +## Converting to Cargo + Let's convert Hello World to Cargo. To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` @@ -103,6 +105,62 @@ That's it! We've successfully built `hello_world` with Cargo. Even though our program is simple, it's using much of the real tooling that you'll use for the rest of your Rust career. +## A New Project + +You don't have to go through this whole process every time you want to start a new +project! Cargo has the ability to make a bare-bones project directory in which you +can start developing right away. + +To start a new project with Cargo, use `cargo new`: + +```{bash} +$ cargo new hello_world --bin +``` + +We're passing `--bin` because we're making a binary program: if we +were making a library, we'd leave it off. + +Let's check out what Cargo has generated for us: + +```{bash} +$ cd hello_world +$ tree . +. +├── Cargo.toml +└── src + └── main.rs + +1 directory, 2 files +``` + +If you don't have the `tree` command, you can probably get it from your distro's package +manager. It's not necessary, but it's certainly useful. + +This is all we need to get started. First, let's check out `Cargo.toml`: + +```{toml} +[package] + +name = "hello_world" +version = "0.0.1" +authors = ["Your Name "] +``` + +Cargo has populated this file with reasonable defaults based off the arguments +you gave it and your Git global config. You may notice that Cargo has also initialized +the `hello_world` directory as a Git repository. + +Here's what's in `src/main.rs`: + +```{rust} +fn main() { + println!("Hello, world!"); +} +``` + +Cargo has generated a "Hello World!" for us, and you're ready to start coding! A +much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide.html). + Now that you've got the tools down, let's actually learn more about the Rust language itself. These are the basics that will serve you well through the rest -of your time with Rust. +of your time with Rust. \ No newline at end of file From f49fd40f208827798ccd91394e3a3986c8bc6886 Mon Sep 17 00:00:00 2001 From: Alexander Bliskovsky Date: Mon, 23 Feb 2015 16:35:47 -0500 Subject: [PATCH 2/2] Removed `{}` and small wording fixes to "Hello Cargo!" chapter. --- src/doc/trpl/hello-cargo.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index de2ce2d9edebf..587da69d4a6f7 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -26,7 +26,7 @@ To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` configuration file, and put our source file in the right place. Let's do that part first: -```{bash} +```bash $ mkdir src $ mv main.rs src/main.rs ``` @@ -38,7 +38,7 @@ place for everything, and everything in its place. Next, our configuration file: -```{bash} +```bash $ editor Cargo.toml ``` @@ -75,7 +75,7 @@ well as what it is named. Once you have this file in place, we should be ready to build! Try this: -```{bash} +```bash $ cargo build Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world) $ ./target/hello_world @@ -113,7 +113,7 @@ can start developing right away. To start a new project with Cargo, use `cargo new`: -```{bash} +```bash $ cargo new hello_world --bin ``` @@ -122,7 +122,7 @@ were making a library, we'd leave it off. Let's check out what Cargo has generated for us: -```{bash} +```bash $ cd hello_world $ tree . . @@ -138,7 +138,7 @@ manager. It's not necessary, but it's certainly useful. This is all we need to get started. First, let's check out `Cargo.toml`: -```{toml} +```toml [package] name = "hello_world" @@ -146,13 +146,13 @@ version = "0.0.1" authors = ["Your Name "] ``` -Cargo has populated this file with reasonable defaults based off the arguments -you gave it and your Git global config. You may notice that Cargo has also initialized -the `hello_world` directory as a Git repository. +Cargo has populated this file with reasonable defaults based off the arguments you gave +it and your `git` global configuration. You may notice that Cargo has also initialized +the `hello_world` directory as a `git` repository. Here's what's in `src/main.rs`: -```{rust} +```rust fn main() { println!("Hello, world!"); }