blob: f4cdd997f52919d885ea7d81a91db6bdbfe82a0b [file] [log] [blame]
Matthew Maurerbd398542019-09-05 16:25:08 -07001'\" t
2.\" Title: cargo-rustc
3.\" Author: [see the "AUTHOR(S)" section]
4.\" Generator: Asciidoctor 1.5.8
5.\" Date: 2019-04-16
6.\" Manual: \ \&
7.\" Source: \ \&
8.\" Language: English
9.\"
10.TH "CARGO\-RUSTC" "1" "2019-04-16" "\ \&" "\ \&"
11.ie \n(.g .ds Aq \(aq
12.el .ds Aq '
13.ss \n[.ss] 0
14.nh
15.ad l
16.de URL
17\fI\\$2\fP <\\$1>\\$3
18..
19.als MTO URL
20.if \n[.g] \{\
21. mso www.tmac
22. am URL
23. ad l
24. .
25. am MTO
26. ad l
27. .
28. LINKSTYLE blue R < >
29.\}
30.SH "NAME"
31cargo\-rustc \- Compile the current package, and pass extra options to the compiler
32.SH "SYNOPSIS"
33.sp
34\fBcargo rustc [\fIOPTIONS\fP] [\-\- \fIARGS\fP]\fP
35.SH "DESCRIPTION"
36.sp
37The specified target for the current package (or package specified by \fB\-p\fP if
38provided) will be compiled along with all of its dependencies. The specified
39\fIARGS\fP will all be passed to the final compiler invocation, not any of the
40dependencies. Note that the compiler will still unconditionally receive
41arguments such as \fB\-L\fP, \fB\-\-extern\fP, and \fB\-\-crate\-type\fP, and the specified
42\fIARGS\fP will simply be added to the compiler invocation.
43.sp
44See \c
45.URL "https://doc.rust\-lang.org/rustc/index.html" "" " "
46for documentation on rustc
47flags.
48.sp
49This command requires that only one target is being compiled when additional
50arguments are provided. If more than one target is available for the current
51package the filters of \fB\-\-lib\fP, \fB\-\-bin\fP, etc, must be used to select which
52target is compiled.
53To pass flags to all compiler processes spawned by Cargo, use the \fBRUSTFLAGS\fP
54environment variable or the \fBbuild.rustflags\fP
55.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
56.SH "OPTIONS"
57.SS "Package Selection"
58.sp
59By default, the package in the current working directory is selected. The \fB\-p\fP
60flag can be used to choose a different package in a workspace.
61.sp
62\fB\-p\fP \fISPEC\fP, \fB\-\-package\fP \fISPEC\fP
63.RS 4
64The package to build. See \fBcargo\-pkgid\fP(1) for
65the SPEC format.
66.RE
67.SS "Target Selection"
68.sp
69When no target selection options are given, \fBcargo rustc\fP will build all
70binary and library targets of the selected package.
71.sp
72Passing target selection flags will build only the
73specified targets.
74.sp
75\fB\-\-lib\fP
76.RS 4
77Build the package\(cqs library.
78.RE
79.sp
80\fB\-\-bin\fP \fINAME\fP...
81.RS 4
82Build the specified binary. This flag may be specified multiple times.
83.RE
84.sp
85\fB\-\-bins\fP
86.RS 4
87Build all binary targets.
88.RE
89.sp
90\fB\-\-example\fP \fINAME\fP...
91.RS 4
92Build the specified example. This flag may be specified multiple times.
93.RE
94.sp
95\fB\-\-examples\fP
96.RS 4
97Build all example targets.
98.RE
99.sp
100\fB\-\-test\fP \fINAME\fP...
101.RS 4
102Build the specified integration test. This flag may be specified multiple
103times.
104.RE
105.sp
106\fB\-\-tests\fP
107.RS 4
108Build all targets in test mode that have the \fBtest = true\fP manifest
109flag set. By default this includes the library and binaries built as
110unittests, and integration tests. Be aware that this will also build any
111required dependencies, so the lib target may be built twice (once as a
112unittest, and once as a dependency for binaries, integration tests, etc.).
113Targets may be enabled or disabled by setting the \fBtest\fP flag in the
114manifest settings for the target.
115.RE
116.sp
117\fB\-\-bench\fP \fINAME\fP...
118.RS 4
119Build the specified benchmark. This flag may be specified multiple times.
120.RE
121.sp
122\fB\-\-benches\fP
123.RS 4
124Build all targets in benchmark mode that have the \fBbench = true\fP
125manifest flag set. By default this includes the library and binaries built
126as benchmarks, and bench targets. Be aware that this will also build any
127required dependencies, so the lib target may be built twice (once as a
128benchmark, and once as a dependency for binaries, benchmarks, etc.).
129Targets may be enabled or disabled by setting the \fBbench\fP flag in the
130manifest settings for the target.
131.RE
132.sp
133\fB\-\-all\-targets\fP
134.RS 4
135Build all targets. This is equivalent to specifying \fB\-\-lib \-\-bins
136\-\-tests \-\-benches \-\-examples\fP.
137.RE
138.SS "Feature Selection"
139.sp
140When no feature options are given, the \fBdefault\fP feature is activated for
141every selected package.
142.sp
143\fB\-\-features\fP \fIFEATURES\fP
144.RS 4
145Space or comma separated list of features to activate. These features only
146apply to the current directory\(cqs package. Features of direct dependencies
147may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax.
148.RE
149.sp
150\fB\-\-all\-features\fP
151.RS 4
152Activate all available features of all selected packages.
153.RE
154.sp
155\fB\-\-no\-default\-features\fP
156.RS 4
157Do not activate the \fBdefault\fP feature of the current directory\(cqs
158package.
159.RE
160.SS "Compilation Options"
161.sp
162\fB\-\-target\fP \fITRIPLE\fP
163.RS 4
164Build for the given architecture. The default is the host
165architecture. The general format of the triple is
166\fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a
167list of supported targets.
168.sp
169This may also be specified with the \fBbuild.target\fP
170.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
171.RE
172.sp
173\fB\-\-release\fP
174.RS 4
175Build optimized artifacts with the \fBrelease\fP profile. See the
176PROFILES section for details on how this affects profile selection.
177.RE
178.SS "Output Options"
179.sp
180\fB\-\-target\-dir\fP \fIDIRECTORY\fP
181.RS 4
182Directory for all generated artifacts and intermediate files. May also be
183specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the
184\fBbuild.target\-dir\fP \c
185.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
186Defaults
187to \fBtarget\fP in the root of the workspace.
188.RE
189.SS "Display Options"
190.sp
191\fB\-v\fP, \fB\-\-verbose\fP
192.RS 4
193Use verbose output. May be specified twice for "very verbose" output which
194includes extra output such as dependency warnings and build script output.
195May also be specified with the \fBterm.verbose\fP
196.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
197.RE
198.sp
199\fB\-q\fP, \fB\-\-quiet\fP
200.RS 4
201No output printed to stdout.
202.RE
203.sp
204\fB\-\-color\fP \fIWHEN\fP
205.RS 4
206Control when colored output is used. Valid values:
207.sp
208.RS 4
209.ie n \{\
210\h'-04'\(bu\h'+03'\c
211.\}
212.el \{\
213. sp -1
214. IP \(bu 2.3
215.\}
216\fBauto\fP (default): Automatically detect if color support is available on the
217terminal.
218.RE
219.sp
220.RS 4
221.ie n \{\
222\h'-04'\(bu\h'+03'\c
223.\}
224.el \{\
225. sp -1
226. IP \(bu 2.3
227.\}
228\fBalways\fP: Always display colors.
229.RE
230.sp
231.RS 4
232.ie n \{\
233\h'-04'\(bu\h'+03'\c
234.\}
235.el \{\
236. sp -1
237. IP \(bu 2.3
238.\}
239\fBnever\fP: Never display colors.
240.RE
241.sp
242May also be specified with the \fBterm.color\fP
243.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
244.RE
245.sp
246\fB\-\-message\-format\fP \fIFMT\fP
247.RS 4
248The output format for diagnostic messages. Valid values:
249.sp
250.RS 4
251.ie n \{\
252\h'-04'\(bu\h'+03'\c
253.\}
254.el \{\
255. sp -1
256. IP \(bu 2.3
257.\}
258\fBhuman\fP (default): Display in a human\-readable text format.
259.RE
260.sp
261.RS 4
262.ie n \{\
263\h'-04'\(bu\h'+03'\c
264.\}
265.el \{\
266. sp -1
267. IP \(bu 2.3
268.\}
269\fBjson\fP: Emit JSON messages to stdout.
270.RE
271.sp
272.RS 4
273.ie n \{\
274\h'-04'\(bu\h'+03'\c
275.\}
276.el \{\
277. sp -1
278. IP \(bu 2.3
279.\}
280\fBshort\fP: Emit shorter, human\-readable text messages.
281.RE
282.RE
283.SS "Manifest Options"
284.sp
285\fB\-\-manifest\-path\fP \fIPATH\fP
286.RS 4
287Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current
288directory or any parent directory for the \fBCargo.toml\fP file.
289.RE
290.sp
291\fB\-\-frozen\fP, \fB\-\-locked\fP
292.RS 4
293Either of these flags requires that the \fBCargo.lock\fP file is
294up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will
295exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from
296attempting to access the network to determine if it is out\-of\-date.
297.sp
298These may be used in environments where you want to assert that the
299\fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network
300access.
301.RE
302.sp
303\fB\-\-offline\fP
304.RS 4
305Prevents Cargo from accessing the network for any reason. Without this
306flag, Cargo will stop with an error if it needs to access the network and
307the network is not available. With this flag, Cargo will attempt to
308proceed without the network if possible.
309.sp
310Beware that this may result in different dependency resolution than online
311mode. Cargo will restrict itself to crates that are downloaded locally, even
312if there might be a newer version as indicated in the local copy of the index.
313See the \fBcargo\-fetch\fP(1) command to download dependencies before going
314offline.
315.sp
316May also be specified with the \fBnet.offline\fP \c
317.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
318.RE
319.SS "Common Options"
320.sp
321\fB\-h\fP, \fB\-\-help\fP
322.RS 4
323Prints help information.
324.RE
325.sp
326\fB\-Z\fP \fIFLAG\fP...
327.RS 4
328Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for
329details.
330.RE
331.SS "Miscellaneous Options"
332.sp
333\fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP
334.RS 4
335Number of parallel jobs to run. May also be specified with the
336\fBbuild.jobs\fP \c
337.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
338Defaults to
339the number of CPUs.
340.RE
341.SH "PROFILES"
342.sp
343Profiles may be used to configure compiler options such as optimization levels
344and debug settings. See
345\c
346.URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference"
347for more details.
348.sp
349Profile selection depends on the target and crate being built. By default the
350\fBdev\fP or \fBtest\fP profiles are used. If the \fB\-\-release\fP flag is given, then the
351\fBrelease\fP or \fBbench\fP profiles are used.
352.TS
353allbox tab(:);
354lt lt lt.
355T{
356.sp
357Target
358T}:T{
359.sp
360Default Profile
361T}:T{
362.sp
363\fB\-\-release\fP Profile
364T}
365T{
366.sp
367lib, bin, example
368T}:T{
369.sp
370\fBdev\fP
371T}:T{
372.sp
373\fBrelease\fP
374T}
375T{
376.sp
377test, bench, or any target
378.br
379in "test" or "bench" mode
380T}:T{
381.sp
382\fBtest\fP
383T}:T{
384.sp
385\fBbench\fP
386T}
387.TE
388.sp
389.sp
390Dependencies use the \fBdev\fP/\fBrelease\fP profiles.
391.SH "ENVIRONMENT"
392.sp
393See \c
394.URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " "
395for
396details on environment variables that Cargo reads.
397.SH "EXIT STATUS"
398.sp
3990
400.RS 4
401Cargo succeeded.
402.RE
403.sp
404101
405.RS 4
406Cargo failed to complete.
407.RE
408.SH "EXAMPLES"
409.sp
410.RS 4
411.ie n \{\
412\h'-04' 1.\h'+01'\c
413.\}
414.el \{\
415. sp -1
416. IP " 1." 4.2
417.\}
418Check if your package (not including dependencies) uses unsafe code:
419.sp
420.if n .RS 4
421.nf
422cargo rustc \-\-lib \-\- \-D unsafe\-code
423.fi
424.if n .RE
425.RE
426.sp
427.RS 4
428.ie n \{\
429\h'-04' 2.\h'+01'\c
430.\}
431.el \{\
432. sp -1
433. IP " 2." 4.2
434.\}
435Try an experimental flag on the nightly compiler, such as this which prints
436the size of every type:
437.sp
438.if n .RS 4
439.nf
440cargo rustc \-\-lib \-\- \-Z print\-type\-sizes
441.fi
442.if n .RE
443.RE
444.SH "SEE ALSO"
445.sp
446\fBcargo\fP(1), \fBcargo\-build\fP(1), \fBrustc\fP(1)