Skip to content

Commit 2ad45a5

Browse files
committed
[doc] Sync back doc/book changes into old docs
1 parent 664f5a1 commit 2ad45a5

File tree

3 files changed

+29
-114
lines changed

3 files changed

+29
-114
lines changed

src/doc/book/src/guide/project-layout.md

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -33,107 +33,3 @@ Cargo project:
3333

3434
These are explained in more detail in the [manifest
3535
description](reference/manifest.html#the-project-layout).
36-
37-
## Cargo.toml vs Cargo.lock
38-
39-
`Cargo.toml` and `Cargo.lock` serve two different purposes. Before we talk
40-
about them, here’s a summary:
41-
42-
* `Cargo.toml` is about describing your dependencies in a broad sense, and is
43-
written by you.
44-
* `Cargo.lock` contains exact information about your dependencies. It is
45-
maintained by Cargo and should not be manually edited.
46-
47-
If you’re building a library that other projects will depend on, put
48-
`Cargo.lock` in your `.gitignore`. If you’re building an executable like a
49-
command-line tool or an application, check `Cargo.lock` into `git`. If you're
50-
curious about why that is, see ["Why do binaries have `Cargo.lock` in version
51-
control, but not libraries?" in the
52-
FAQ](faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries).
53-
54-
Let’s dig in a little bit more.
55-
56-
`Cargo.toml` is a **manifest** file in which we can specify a bunch of
57-
different metadata about our project. For example, we can say that we depend
58-
on another project:
59-
60-
```toml
61-
[package]
62-
name = "hello_world"
63-
version = "0.1.0"
64-
authors = ["Your Name <[email protected]>"]
65-
66-
[dependencies]
67-
rand = { git = "https://github.com/rust-lang-nursery/rand.git" }
68-
```
69-
70-
This project has a single dependency, on the `rand` library. We’ve stated in
71-
this case that we’re relying on a particular Git repository that lives on
72-
GitHub. Since we haven’t specified any other information, Cargo assumes that
73-
we intend to use the latest commit on the `master` branch to build our project.
74-
75-
Sound good? Well, there’s one problem: If you build this project today, and
76-
then you send a copy to me, and I build this project tomorrow, something bad
77-
could happen. There could be more commits to `rand` in the meantime, and my
78-
build would include new commits while yours would not. Therefore, we would
79-
get different builds. This would be bad because we want reproducible builds.
80-
81-
We could fix this problem by putting a `rev` line in our `Cargo.toml`:
82-
83-
```toml
84-
[dependencies]
85-
rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" }
86-
```
87-
88-
Now our builds will be the same. But there’s a big drawback: now we have to
89-
manually think about SHA-1s every time we want to update our library. This is
90-
both tedious and error prone.
91-
92-
Enter the `Cargo.lock`. Because of its existence, we don’t need to manually
93-
keep track of the exact revisions: Cargo will do it for us. When we have a
94-
manifest like this:
95-
96-
```toml
97-
[package]
98-
name = "hello_world"
99-
version = "0.1.0"
100-
authors = ["Your Name <[email protected]>"]
101-
102-
[dependencies]
103-
rand = { git = "https://github.com/rust-lang-nursery/rand.git" }
104-
```
105-
106-
Cargo will take the latest commit and write that information out into our
107-
`Cargo.lock` when we build for the first time. That file will look like this:
108-
109-
```toml
110-
[root]
111-
name = "hello_world"
112-
version = "0.1.0"
113-
dependencies = [
114-
"rand 0.1.0 (git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9)",
115-
]
116-
117-
[[package]]
118-
name = "rand"
119-
version = "0.1.0"
120-
source = "git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9"
121-
```
122-
123-
You can see that there’s a lot more information here, including the exact
124-
revision we used to build. Now when you give your project to someone else,
125-
they’ll use the exact same SHA, even though we didn’t specify it in our
126-
`Cargo.toml`.
127-
128-
When we’re ready to opt in to a new version of the library, Cargo can
129-
re-calculate the dependencies and update things for us:
130-
131-
```shell
132-
$ cargo update # updates all dependencies
133-
$ cargo update -p rand # updates just “rand”
134-
```
135-
136-
This will write out a new `Cargo.lock` with the new version information. Note
137-
that the argument to `cargo update` is actually a
138-
[Package ID Specification](reference/pkgid-spec.html) and `rand` is just a short
139-
specification.

src/doc/guide.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ needs to compile your project.
5757

5858
Here’s what’s in `src/main.rs`:
5959

60-
```
60+
```rust
6161
fn main() {
6262
println!("Hello, world!");
6363
}
@@ -201,7 +201,7 @@ we choose to `cargo update`.
201201

202202
You can now use the `regex` library using `extern crate` in `main.rs`.
203203

204-
```
204+
```rust
205205
extern crate regex;
206206

207207
use regex::Regex;
@@ -339,7 +339,6 @@ dependencies = [
339339
name = "rand"
340340
version = "0.1.0"
341341
source = "git+https://github.com/rust-lang-nursery/rand.git#9f35b8e439eeedd60b9414c58f389bdc6a3284f9"
342-
343342
```
344343

345344
You can see that there’s a lot more information here, including the exact

src/doc/index.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
% Cargo, Rust’s Package Manager
22

3-
# Installing
3+
### Install Stable Rust and Cargo
44

5-
The easiest way to get Cargo is to get the current stable release of Rust by
5+
The easiest way to get Cargo is to get the current stable release of [Rust] by
66
using the `rustup` script:
77

88
```shell
99
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
1010
```
1111

12-
This will get you the current stable release of Rust for your platform along
13-
with the latest Cargo.
12+
After this, you can use the `rustup` command to also install `beta` or `nightly`
13+
channels for Rust and Cargo.
1414

15-
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)
16-
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.
15+
### Install Nightly Cargo
1716

18-
Alternatively, you can build Cargo from source.
17+
To install just Cargo, the current recommended installation method is through
18+
the official nightly builds. Note that Cargo will also require that [Rust] is
19+
already installed on the system.
20+
21+
| Platform | 64-bit | 32-bit |
22+
|------------------|-------------------|-------------------|
23+
| Linux binaries | [tar.gz][linux64] | [tar.gz][linux32] |
24+
| MacOS binaries | [tar.gz][mac64] | [tar.gz][mac32] |
25+
| Windows binaries | [tar.gz][win64] | [tar.gz][win32] |
26+
27+
### Build and Install Cargo from Source
28+
29+
Alternatively, you can [build Cargo from source][compiling-from-source].
30+
31+
[rust]: https://www.rust-lang.org/
32+
[linux64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz
33+
[linux32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-unknown-linux-gnu.tar.gz
34+
[mac64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-apple-darwin.tar.gz
35+
[mac32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-apple-darwin.tar.gz
36+
[win64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-pc-windows-gnu.tar.gz
37+
[win32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-windows-gnu.tar.gz
38+
[compiling-from-source]: https://github.com/rust-lang/cargo#compiling-from-source
1939

2040
# Let’s get started
2141

0 commit comments

Comments
 (0)