Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Commit ec39032

Browse files
committed
More on compiler options
1 parent 76be98f commit ec39032

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

src/020-rustc-options.md

+60-17
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,81 @@
33
Most Rust code depends on compiler optimization for good performance. This is
44
true of many languages but it can be especially severe in Rust, which is
55
specifically designed to use safe high-level abstractions that can be
6-
optimized into efficient low-level code. Optimized Rust code very often runs
7-
10 to 50 times faster than the same code compiled without optimization.
6+
optimized into efficient low-level code. **Optimized Rust code often runs 10
7+
to 50 times faster than the same code compiled without optimization.**
88

9-
The compiler's optimization passes can take a long time to run. Building a
10-
Rust project with optimization enabled often takes more than twice as long as
11-
an unoptimized build. So the Rust toolchain makes it easy to do unoptimized
12-
builds during development (when fast build time is important) and optimized
13-
builds only when for measuring performance or deploying to production.
9+
Building a Rust project with optimization enabled often takes more than twice
10+
as long as an unoptimized build. Optimized code can also be harder to debug
11+
in a debugger. So the Rust toolchain makes it easy to use unoptimized builds
12+
during development (when rapid compilation and easy debugging are important)
13+
and optimized builds when measuring performance or deploying to production.
14+
15+
## Building optimized code
16+
17+
To build a Cargo project with optimization enabled, use the `--release` flag:
18+
19+
```sh
20+
cargo build --release
21+
```
22+
23+
Cargo will place the compiled output in the `target/release` directory, rather
24+
than the `target/debug` directory used for non-release builds.
25+
26+
You can use the `--release` flag again to run an optimized binary:
27+
28+
```sh
29+
cargo run --release
30+
```
31+
32+
This automatically compiles the program with optimization enabled (if it isn’t
33+
already compiled) and then runs it.
1434

1535
## Cargo profiles
1636

17-
Cargo uses different compiler options for different commands. You can
18-
customize thes options the [profile] sections of the `Cargo.toml` file. There
19-
are five profiles.
37+
Cargo uses different compiler options for different commands. These options
38+
are grouped into five *profiles*.
2039

21-
These profiles have optimization disabled by default:
40+
These commands compile **without** optimization by default:
2241

2342
```sh
24-
cargo build # uses the `dev` profile
25-
cargo test # uses the `test` profile
26-
cargo doc # uses the `doc` profile
43+
cargo build # uses `[profile.dev]`
44+
cargo test # uses `[profile.test]`
45+
cargo doc # uses `[profile.doc]`
2746
```
2847

29-
These profiles have optimization enabled by default:
48+
These commands compile **with** optimization by default:
3049

3150
```sh
32-
cargo build --release # uses the `release` profile
33-
cargo bench # uses the `bench` profile
51+
cargo build --release # uses `[profile.release]`
52+
cargo bench # uses `[profile.bench]`
3453
```
3554

55+
You can customize the compiler options for each command in the [profile]
56+
sections of the `Cargo.toml` file.
57+
3658
### opt-level
3759

60+
TODO
61+
62+
### opt-level
63+
64+
TODO
65+
66+
### codegen-units
67+
68+
TODO
69+
70+
### debug
71+
72+
TODO
73+
74+
### debug-assertions
75+
76+
TODO
77+
78+
### panic
79+
80+
TODO
3881

3982

4083
[profile]: http://doc.crates.io/manifest.html#the-profile-sections

0 commit comments

Comments
 (0)