Skip to content

Commit fd600f3

Browse files
committed
Auto merge of #8391 - bl2e:install-target-dir, r=alexcrichton
Enable "--target-dir" in "cargo install" Issue #8263
2 parents 78c1671 + 538d925 commit fd600f3

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn cli() -> App {
5757
"Install all examples",
5858
)
5959
.arg_target_triple("Build for the target triple")
60+
.arg_target_dir()
6061
.arg(opt("root", "Directory to install packages into").value_name("DIR"))
6162
.arg(
6263
opt("index", "Registry index to install from")

src/doc/man/cargo-install.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ include::options-features.adoc[]
143143

144144
include::options-target-triple.adoc[]
145145

146+
include::options-target-dir.adoc[]
147+
146148
*--debug*::
147149
Build with the `dev` profile instead the `release` profile.
148150

src/doc/man/generated/cargo-install.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ <h3 id="cargo_install_compilation_options">Compilation Options</h3>
258258
<a href="../guide/build-cache.html">build cache</a> documentation for more details.</p>
259259
</div>
260260
</dd>
261+
<dt class="hdlist1"><strong>--target-dir</strong> <em>DIRECTORY</em></dt>
262+
<dd>
263+
<p>Directory for all generated artifacts and intermediate files. May also be
264+
specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
265+
<code>build.target-dir</code> <a href="../reference/config.html">config value</a>. Defaults
266+
to <code>target</code> in the root of the workspace.</p>
267+
</dd>
261268
<dt class="hdlist1"><strong>--debug</strong></dt>
262269
<dd>
263270
<p>Build with the <code>dev</code> profile instead the <code>release</code> profile.</p>

src/etc/man/cargo-install.1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: cargo-install
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.10
5-
.\" Date: 2020-06-14
5+
.\" Date: 2020-06-20
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-INSTALL" "1" "2020-06-14" "\ \&" "\ \&"
10+
.TH "CARGO\-INSTALL" "1" "2020-06-20" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -345,6 +345,16 @@ target artifacts are placed in a separate directory. See the
345345
documentation for more details.
346346
.RE
347347
.sp
348+
\fB\-\-target\-dir\fP \fIDIRECTORY\fP
349+
.RS 4
350+
Directory for all generated artifacts and intermediate files. May also be
351+
specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the
352+
\fBbuild.target\-dir\fP \c
353+
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
354+
Defaults
355+
to \fBtarget\fP in the root of the workspace.
356+
.RE
357+
.sp
348358
\fB\-\-debug\fP
349359
.RS 4
350360
Build with the \fBdev\fP profile instead the \fBrelease\fP profile.

tests/testsuite/install.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,35 @@ fn install_path() {
308308
.run();
309309
}
310310

311+
#[cargo_test]
312+
fn install_target_dir() {
313+
let p = project().file("src/main.rs", "fn main() {}").build();
314+
315+
p.cargo("install --target-dir td_test")
316+
.with_stderr(
317+
"\
318+
[WARNING] Using `cargo install` [..]
319+
[INSTALLING] foo v0.0.1 [..]
320+
[COMPILING] foo v0.0.1 [..]
321+
[FINISHED] release [..]
322+
[INSTALLING] [..]foo[EXE]
323+
[INSTALLED] package `foo v0.0.1 [..]foo[..]` (executable `foo[EXE]`)
324+
[WARNING] be sure to add [..]
325+
",
326+
)
327+
.run();
328+
329+
let mut path = p.root();
330+
path.push("td_test");
331+
assert!(path.exists());
332+
333+
#[cfg(not(windows))]
334+
path.push("release/foo");
335+
#[cfg(windows)]
336+
path.push("release/foo.exe");
337+
assert!(path.exists());
338+
}
339+
311340
#[cargo_test]
312341
fn multiple_crates_error() {
313342
let p = git::repo(&paths::root().join("foo"))

0 commit comments

Comments
 (0)