Skip to content

Commit 4189f50

Browse files
committed
Auto merge of #13809 - valadaptive:artifact-dir, r=epage
Rename --out-dir to --artifact-dir Progress towards unblocking #6790. Renames the experimental `--out-dir` argument to `--artifact-dir`, both to reflect that it's where the final build *artifacts* will be copied to, and to avoid confusion with the `OUT_DIR` environment variable which serves an entirely different purpose. For transition purposes, `--out-dir` argument and `out-dir` config key will still work with a deprecation message encouraging the use of the new arg and config key. ### Rationale A lot of people seem to be confused by the naming of the `--out-dir` argument, and are misled into thinking it serves the same purpose as the `OUT_DIR` environment variable: > [However, it doesn't seem that OUT_DIR environment variable is set to the value of --out-dir when build.rs is executed.](#6790 (comment)) > [I understand that the worry is that there could be confusion between --out-dir for cargo and the environment variable OUT_DIR for build.rs, but doesn't it mean exactly the same in both cases?](#6790 (comment)) > [--out-dir: Things will be built into $PWD/target as normal, but copies some of the artifacts into the directory specified by out-dir (not a profile specific subdirectory). Unstable flag, added in March 2018. cargo build --out-dir #5203 Ability to specify output artifact name #4875. **Mimicks the behavior of OUT_DIR.**](#6100 (comment)) > [I recently had a couple of people express an interest in --out-dir being stabilized and from my initial digging it seems like what they may actually want is to switch to OUT_DIR, which is already stable.](#6100 (comment))
2 parents a72ce7d + 0aac303 commit 4189f50

File tree

15 files changed

+149
-71
lines changed

15 files changed

+149
-71
lines changed

src/bin/cargo/commands/build.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn cli() -> Command {
3434
.arg_parallel()
3535
.arg_target_triple("Build for the target triple")
3636
.arg_target_dir()
37-
.arg_out_dir()
37+
.arg_artifact_dir()
3838
.arg_build_plan()
3939
.arg_unit_graph()
4040
.arg_timings()
@@ -50,15 +50,32 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
5050
let mut compile_opts =
5151
args.compile_options(gctx, CompileMode::Build, Some(&ws), ProfileChecking::Custom)?;
5252

53-
if let Some(out_dir) = args.value_of_path("out-dir", gctx) {
54-
compile_opts.build_config.export_dir = Some(out_dir);
55-
} else if let Some(out_dir) = gctx.build_config()?.out_dir.as_ref() {
56-
let out_dir = out_dir.resolve_path(gctx);
57-
compile_opts.build_config.export_dir = Some(out_dir);
53+
if let Some(artifact_dir) = args.value_of_path("artifact-dir", gctx) {
54+
// If the user specifies `--artifact-dir`, use that
55+
compile_opts.build_config.export_dir = Some(artifact_dir);
56+
} else if let Some(artifact_dir) = args.value_of_path("out-dir", gctx) {
57+
// `--out-dir` is deprecated, but still supported for now
58+
gctx.shell()
59+
.warn("the --out-dir flag has been changed to --artifact-dir")?;
60+
compile_opts.build_config.export_dir = Some(artifact_dir);
61+
} else if let Some(artifact_dir) = gctx.build_config()?.artifact_dir.as_ref() {
62+
// If a CLI option is not specified for choosing the artifact dir, use the `artifact-dir` from the build config, if
63+
// present
64+
let artifact_dir = artifact_dir.resolve_path(gctx);
65+
compile_opts.build_config.export_dir = Some(artifact_dir);
66+
} else if let Some(artifact_dir) = gctx.build_config()?.out_dir.as_ref() {
67+
// As a last priority, check `out-dir` in the build config
68+
gctx.shell()
69+
.warn("the out-dir config option has been changed to artifact-dir")?;
70+
let artifact_dir = artifact_dir.resolve_path(gctx);
71+
compile_opts.build_config.export_dir = Some(artifact_dir);
5872
}
73+
5974
if compile_opts.build_config.export_dir.is_some() {
60-
gctx.cli_unstable().fail_if_stable_opt("--out-dir", 6790)?;
75+
gctx.cli_unstable()
76+
.fail_if_stable_opt("--artifact-dir", 6790)?;
6177
}
78+
6279
ops::compile(&ws, &compile_opts)?;
6380
Ok(())
6481
}

src/cargo/core/compiler/build_config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ pub struct BuildConfig {
3636
/// A thread used by `cargo fix` to receive messages on a socket regarding
3737
/// the success/failure of applying fixes.
3838
pub rustfix_diagnostic_server: Rc<RefCell<Option<RustfixDiagnosticServer>>>,
39-
/// The directory to copy final artifacts to. Note that even if `out_dir` is
40-
/// set, a copy of artifacts still could be found a `target/(debug\release)`
41-
/// as usual.
42-
// Note that, although the cmd-line flag name is `out-dir`, in code we use
43-
// `export_dir`, to avoid confusion with out dir at `target/debug/deps`.
39+
/// The directory to copy final artifacts to. Note that even if
40+
/// `artifact-dir` is set, a copy of artifacts still can be found at
41+
/// `target/(debug\release)` as usual.
42+
/// Named `export_dir` to avoid confusion with
43+
/// `CompilationFiles::artifact_dir`.
4444
pub export_dir: Option<PathBuf>,
4545
/// `true` to output a future incompatibility report at the end of the build
4646
pub future_incompat_report: bool,

src/cargo/core/compiler/build_runner/compilation_files.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct OutputFile {
121121
/// If it should be linked into `target`, and what it should be called
122122
/// (e.g., without metadata).
123123
pub hardlink: Option<PathBuf>,
124-
/// If `--out-dir` is specified, the absolute path to the exported file.
124+
/// If `--artifact-dir` is specified, the absolute path to the exported file.
125125
pub export_path: Option<PathBuf>,
126126
/// Type of the file (library / debug symbol / else).
127127
pub flavor: FileFlavor,
@@ -213,7 +213,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
213213
}
214214
}
215215

216-
/// Additional export directory from `--out-dir`.
216+
/// Additional export directory from `--artifact-dir`.
217217
pub fn export_dir(&self) -> Option<PathBuf> {
218218
self.export_dir.clone()
219219
}

src/cargo/core/compiler/build_runner/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
574574
if let Some(ref export_path) = output.export_path {
575575
if let Some(other_unit) = output_collisions.insert(export_path.clone(), unit) {
576576
self.bcx.gctx.shell().warn(format!(
577-
"`--out-dir` filename collision.\n\
577+
"`--artifact-dir` filename collision.\n\
578578
{}\
579579
The exported filenames should be unique.\n\
580580
{}",

src/cargo/util/command_prelude.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,35 @@ pub trait CommandExt: Sized {
393393
)
394394
}
395395

396-
fn arg_out_dir(self) -> Self {
396+
fn arg_artifact_dir(self) -> Self {
397397
let unsupported_short_arg = {
398-
let value_parser = UnknownArgumentValueParser::suggest_arg("--out-dir");
399-
Arg::new("unsupported-short-out-dir-flag")
398+
let value_parser = UnknownArgumentValueParser::suggest_arg("--artifact-dir");
399+
Arg::new("unsupported-short-artifact-dir-flag")
400400
.help("")
401401
.short('O')
402402
.value_parser(value_parser)
403403
.action(ArgAction::SetTrue)
404404
.hide(true)
405405
};
406+
406407
self._arg(
407408
opt(
408-
"out-dir",
409+
"artifact-dir",
409410
"Copy final artifacts to this directory (unstable)",
410411
)
411412
.value_name("PATH")
412413
.help_heading(heading::COMPILATION_OPTIONS),
413414
)
414415
._arg(unsupported_short_arg)
416+
._arg(
417+
opt(
418+
"out-dir",
419+
"Copy final artifacts to this directory (deprecated; use --artifact-dir instead)",
420+
)
421+
.value_name("PATH")
422+
.conflicts_with("artifact-dir")
423+
.hide(true),
424+
)
415425
}
416426
}
417427

src/cargo/util/context/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,9 @@ pub struct CargoBuildConfig {
26092609
pub rustc_workspace_wrapper: Option<ConfigRelativePath>,
26102610
pub rustc: Option<ConfigRelativePath>,
26112611
pub rustdoc: Option<ConfigRelativePath>,
2612+
// deprecated alias for artifact-dir
26122613
pub out_dir: Option<ConfigRelativePath>,
2614+
pub artifact_dir: Option<ConfigRelativePath>,
26132615
}
26142616

26152617
/// Configuration for `build.target`.

src/doc/man/cargo-build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ they have `required-features` that are missing.
5050
{{#options}}
5151
{{> options-target-dir }}
5252

53-
{{#option "`--out-dir` _directory_" }}
53+
{{#option "`--artifact-dir` _directory_" }}
5454
Copy final artifacts to this directory.
5555

5656
This option is unstable and available only on the

src/doc/man/generated_txt/cargo-build.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ OPTIONS
188188
<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
189189
target in the root of the workspace.
190190

191-
--out-dir directory
191+
--artifact-dir directory
192192
Copy final artifacts to this directory.
193193

194194
This option is unstable and available only on the nightly channel

src/doc/src/commands/cargo-build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
222222
Defaults to <code>target</code> in the root of the workspace.</dd>
223223

224224

225-
<dt class="option-term" id="option-cargo-build---out-dir"><a class="option-anchor" href="#option-cargo-build---out-dir"></a><code>--out-dir</code> <em>directory</em></dt>
225+
<dt class="option-term" id="option-cargo-build---artifact-dir"><a class="option-anchor" href="#option-cargo-build---artifact-dir"></a><code>--artifact-dir</code> <em>directory</em></dt>
226226
<dd class="option-desc">Copy final artifacts to this directory.</p>
227227
<p>This option is unstable and available only on the
228228
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>

src/doc/src/reference/unstable.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ how the feature works:
2828

2929
* New command-line flags, options, and subcommands require the `-Z
3030
unstable-options` CLI option to also be included. For example, the new
31-
`--out-dir` option is only available on nightly:
31+
`--artifact-dir` option is only available on nightly:
3232

33-
```cargo +nightly build --out-dir=out -Z unstable-options```
33+
```cargo +nightly build --artifact-dir=out -Z unstable-options```
3434

3535
* `-Z` command-line flags are used to enable new functionality that may not
3636
have an interface, or the interface has not yet been designed, or for more
@@ -74,7 +74,7 @@ For the latest nightly, see the [nightly version] of this page.
7474
* [msrv-policy](#msrv-policy) --- MSRV-aware resolver and version selection
7575
* [precise-pre-release](#precise-pre-release) --- Allows pre-release versions to be selected with `update --precise`
7676
* Output behavior
77-
* [out-dir](#out-dir) --- Adds a directory where artifacts are copied to.
77+
* [artifact-dir](#artifact-dir) --- Adds a directory where artifacts are copied to.
7878
* [Different binary name](#different-binary-name) --- Assign a name to the built binary that is separate from the crate name.
7979
* Compile behavior
8080
* [mtime-on-use](#mtime-on-use) --- Updates the last-modified timestamp on every dependency every time it is used, to provide a mechanism to delete unused artifacts.
@@ -206,27 +206,27 @@ minimum versions that you are actually using. That is, if Cargo.toml says
206206
Indirect dependencies are resolved as normal so as not to be blocked on their
207207
minimal version validation.
208208

209-
## out-dir
209+
## artifact-dir
210210
* Original Issue: [#4875](https://github.com/rust-lang/cargo/issues/4875)
211211
* Tracking Issue: [#6790](https://github.com/rust-lang/cargo/issues/6790)
212212

213-
This feature allows you to specify the directory where artifacts will be
214-
copied to after they are built. Typically artifacts are only written to the
215-
`target/release` or `target/debug` directories. However, determining the
216-
exact filename can be tricky since you need to parse JSON output. The
217-
`--out-dir` flag makes it easier to predictably access the artifacts. Note
218-
that the artifacts are copied, so the originals are still in the `target`
219-
directory. Example:
213+
This feature allows you to specify the directory where artifacts will be copied
214+
to after they are built. Typically artifacts are only written to the
215+
`target/release` or `target/debug` directories. However, determining the exact
216+
filename can be tricky since you need to parse JSON output. The `--artifact-dir`
217+
flag makes it easier to predictably access the artifacts. Note that the
218+
artifacts are copied, so the originals are still in the `target` directory.
219+
Example:
220220

221221
```sh
222-
cargo +nightly build --out-dir=out -Z unstable-options
222+
cargo +nightly build --artifact-dir=out -Z unstable-options
223223
```
224224

225225
This can also be specified in `.cargo/config.toml` files.
226226

227227
```toml
228228
[build]
229-
out-dir = "out"
229+
artifact-dir = "out"
230230
```
231231

232232
## doctest-xcompile

src/etc/man/cargo-build.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ specified with the \fBCARGO_TARGET_DIR\fR environment variable, or the
222222
Defaults to \fBtarget\fR in the root of the workspace.
223223
.RE
224224
.sp
225-
\fB\-\-out\-dir\fR \fIdirectory\fR
225+
\fB\-\-artifact\-dir\fR \fIdirectory\fR
226226
.RS 4
227227
Copy final artifacts to this directory.
228228
.sp

0 commit comments

Comments
 (0)