diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs
index 308ce2ce6a71..26f7af316097 100644
--- a/src/bin/cargo/commands/build.rs
+++ b/src/bin/cargo/commands/build.rs
@@ -34,7 +34,7 @@ pub fn cli() -> Command {
.arg_parallel()
.arg_target_triple("Build for the target triple")
.arg_target_dir()
- .arg_out_dir()
+ .arg_artifact_dir()
.arg_build_plan()
.arg_unit_graph()
.arg_timings()
@@ -50,15 +50,32 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let mut compile_opts =
args.compile_options(gctx, CompileMode::Build, Some(&ws), ProfileChecking::Custom)?;
- if let Some(out_dir) = args.value_of_path("out-dir", gctx) {
- compile_opts.build_config.export_dir = Some(out_dir);
- } else if let Some(out_dir) = gctx.build_config()?.out_dir.as_ref() {
- let out_dir = out_dir.resolve_path(gctx);
- compile_opts.build_config.export_dir = Some(out_dir);
+ if let Some(artifact_dir) = args.value_of_path("artifact-dir", gctx) {
+ // If the user specifies `--artifact-dir`, use that
+ compile_opts.build_config.export_dir = Some(artifact_dir);
+ } else if let Some(artifact_dir) = args.value_of_path("out-dir", gctx) {
+ // `--out-dir` is deprecated, but still supported for now
+ gctx.shell()
+ .warn("the --out-dir flag has been changed to --artifact-dir")?;
+ compile_opts.build_config.export_dir = Some(artifact_dir);
+ } else if let Some(artifact_dir) = gctx.build_config()?.artifact_dir.as_ref() {
+ // If a CLI option is not specified for choosing the artifact dir, use the `artifact-dir` from the build config, if
+ // present
+ let artifact_dir = artifact_dir.resolve_path(gctx);
+ compile_opts.build_config.export_dir = Some(artifact_dir);
+ } else if let Some(artifact_dir) = gctx.build_config()?.out_dir.as_ref() {
+ // As a last priority, check `out-dir` in the build config
+ gctx.shell()
+ .warn("the out-dir config option has been changed to artifact-dir")?;
+ let artifact_dir = artifact_dir.resolve_path(gctx);
+ compile_opts.build_config.export_dir = Some(artifact_dir);
}
+
if compile_opts.build_config.export_dir.is_some() {
- gctx.cli_unstable().fail_if_stable_opt("--out-dir", 6790)?;
+ gctx.cli_unstable()
+ .fail_if_stable_opt("--artifact-dir", 6790)?;
}
+
ops::compile(&ws, &compile_opts)?;
Ok(())
}
diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs
index 9536e58be566..0f66d6dbbc66 100644
--- a/src/cargo/core/compiler/build_config.rs
+++ b/src/cargo/core/compiler/build_config.rs
@@ -36,11 +36,11 @@ pub struct BuildConfig {
/// A thread used by `cargo fix` to receive messages on a socket regarding
/// the success/failure of applying fixes.
pub rustfix_diagnostic_server: RcCARGO_TARGET_DIR
environment variable, or the
Defaults to target
in the root of the workspace.
---out-dir
directory--artifact-dir
directory
This option is unstable and available only on the
nightly channel
diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md
index fce26e146c54..5e871aca5ae5 100644
--- a/src/doc/src/reference/unstable.md
+++ b/src/doc/src/reference/unstable.md
@@ -28,9 +28,9 @@ how the feature works:
* New command-line flags, options, and subcommands require the `-Z
unstable-options` CLI option to also be included. For example, the new
- `--out-dir` option is only available on nightly:
+ `--artifact-dir` option is only available on nightly:
- ```cargo +nightly build --out-dir=out -Z unstable-options```
+ ```cargo +nightly build --artifact-dir=out -Z unstable-options```
* `-Z` command-line flags are used to enable new functionality that may not
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.
* [msrv-policy](#msrv-policy) --- MSRV-aware resolver and version selection
* [precise-pre-release](#precise-pre-release) --- Allows pre-release versions to be selected with `update --precise`
* Output behavior
- * [out-dir](#out-dir) --- Adds a directory where artifacts are copied to.
+ * [artifact-dir](#artifact-dir) --- Adds a directory where artifacts are copied to.
* [Different binary name](#different-binary-name) --- Assign a name to the built binary that is separate from the crate name.
* Compile behavior
* [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
Indirect dependencies are resolved as normal so as not to be blocked on their
minimal version validation.
-## out-dir
+## artifact-dir
* Original Issue: [#4875](https://github.com/rust-lang/cargo/issues/4875)
* Tracking Issue: [#6790](https://github.com/rust-lang/cargo/issues/6790)
-This feature allows you to specify the directory where artifacts will be
-copied to after they are built. Typically artifacts are only written to the
-`target/release` or `target/debug` directories. However, determining the
-exact filename can be tricky since you need to parse JSON output. The
-`--out-dir` flag makes it easier to predictably access the artifacts. Note
-that the artifacts are copied, so the originals are still in the `target`
-directory. Example:
+This feature allows you to specify the directory where artifacts will be copied
+to after they are built. Typically artifacts are only written to the
+`target/release` or `target/debug` directories. However, determining the exact
+filename can be tricky since you need to parse JSON output. The `--artifact-dir`
+flag makes it easier to predictably access the artifacts. Note that the
+artifacts are copied, so the originals are still in the `target` directory.
+Example:
```sh
-cargo +nightly build --out-dir=out -Z unstable-options
+cargo +nightly build --artifact-dir=out -Z unstable-options
```
This can also be specified in `.cargo/config.toml` files.
```toml
[build]
-out-dir = "out"
+artifact-dir = "out"
```
## doctest-xcompile
diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1
index 9b7a08e4ed1e..23e49a15e16a 100644
--- a/src/etc/man/cargo-build.1
+++ b/src/etc/man/cargo-build.1
@@ -222,7 +222,7 @@ specified with the \fBCARGO_TARGET_DIR\fR environment variable, or the
Defaults to \fBtarget\fR in the root of the workspace.
.RE
.sp
-\fB\-\-out\-dir\fR \fIdirectory\fR
+\fB\-\-artifact\-dir\fR \fIdirectory\fR
.RS 4
Copy final artifacts to this directory.
.sp
diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/artifact_dir.rs
similarity index 74%
rename from tests/testsuite/out_dir.rs
rename to tests/testsuite/artifact_dir.rs
index 1b3d4a64ad10..ff83a720913a 100644
--- a/tests/testsuite/out_dir.rs
+++ b/tests/testsuite/artifact_dir.rs
@@ -1,4 +1,4 @@
-//! Tests for --out-dir flag.
+//! Tests for --artifact-dir flag.
use cargo_test_support::sleep_ms;
use cargo_test_support::{basic_manifest, project};
@@ -12,8 +12,8 @@ fn binary_with_debug() {
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.enable_mac_dsym()
.run();
check_dir_contents(
@@ -49,8 +49,8 @@ fn static_library_with_debug() {
)
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.run();
check_dir_contents(
&p.root().join("out"),
@@ -85,8 +85,8 @@ fn dynamic_library_with_debug() {
)
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.enable_mac_dsym()
.run();
check_dir_contents(
@@ -121,8 +121,8 @@ fn rlib_with_debug() {
)
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.run();
check_dir_contents(
&p.root().join("out"),
@@ -165,8 +165,8 @@ fn include_only_the_binary_from_the_current_package() {
.file("utils/src/lib.rs", "")
.build();
- p.cargo("build -Z unstable-options --bin foo --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --bin foo --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.enable_mac_dsym()
.run();
check_dir_contents(
@@ -179,14 +179,14 @@ fn include_only_the_binary_from_the_current_package() {
}
#[cargo_test]
-fn out_dir_is_a_file() {
+fn artifact_dir_is_a_file() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.file("out", "")
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.with_status(101)
.with_stderr_contains("[ERROR] failed to create directory [..]")
.run();
@@ -198,8 +198,8 @@ fn replaces_artifacts() {
.file("src/main.rs", r#"fn main() { println!("foo") }"#)
.build();
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.run();
p.process(
&p.root()
@@ -211,8 +211,8 @@ fn replaces_artifacts() {
sleep_ms(1000);
p.change_file("src/main.rs", r#"fn main() { println!("bar") }"#);
- p.cargo("build -Z unstable-options --out-dir out")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.run();
p.process(
&p.root()
@@ -240,8 +240,8 @@ fn avoid_build_scripts() {
.file("b/build.rs", r#"fn main() { println!("hello-build-b"); }"#)
.build();
- p.cargo("build -Z unstable-options --out-dir out -vv")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ p.cargo("build -Z unstable-options --artifact-dir out -vv")
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.enable_mac_dsym()
.with_stdout_contains("[a 0.0.1] hello-build-a")
.with_stdout_contains("[b 0.0.1] hello-build-b")
@@ -256,20 +256,20 @@ fn avoid_build_scripts() {
}
#[cargo_test]
-fn cargo_build_out_dir() {
+fn cargo_build_artifact_dir() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.file(
".cargo/config.toml",
r#"
[build]
- out-dir = "out"
+ artifact-dir = "out"
"#,
)
.build();
p.cargo("build -Z unstable-options")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.enable_mac_dsym()
.run();
check_dir_contents(
@@ -282,18 +282,18 @@ fn cargo_build_out_dir() {
}
#[cargo_test]
-fn unsupported_short_out_dir_flag() {
+fn unsupported_short_artifact_dir_flag() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.build();
p.cargo("build -Z unstable-options -O")
- .masquerade_as_nightly_cargo(&["out-dir"])
+ .masquerade_as_nightly_cargo(&["artifact-dir"])
.with_stderr(
"\
error: unexpected argument '-O' found
- tip: a similar argument exists: '--out-dir'
+ tip: a similar argument exists: '--artifact-dir'
Usage: cargo[EXE] build [OPTIONS]
@@ -304,8 +304,57 @@ For more information, try '--help'.
.run();
}
+#[cargo_test]
+fn deprecated_out_dir() {
+ let p = project()
+ .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
+ .build();
+
+ p.cargo("build -Z unstable-options --out-dir out")
+ .masquerade_as_nightly_cargo(&["out-dir"])
+ .enable_mac_dsym()
+ .with_stderr_contains("[WARNING] the --out-dir flag has been changed to --artifact-dir")
+ .run();
+ check_dir_contents(
+ &p.root().join("out"),
+ &["foo"],
+ &["foo", "foo.dSYM"],
+ &["foo.exe", "foo.pdb"],
+ &["foo.exe"],
+ );
+}
+
+#[cargo_test]
+fn cargo_build_deprecated_out_dir() {
+ let p = project()
+ .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
+ .file(
+ ".cargo/config.toml",
+ r#"
+ [build]
+ out-dir = "out"
+ "#,
+ )
+ .build();
+
+ p.cargo("build -Z unstable-options")
+ .masquerade_as_nightly_cargo(&["out-dir"])
+ .enable_mac_dsym()
+ .with_stderr_contains(
+ "[WARNING] the out-dir config option has been changed to artifact-dir",
+ )
+ .run();
+ check_dir_contents(
+ &p.root().join("out"),
+ &["foo"],
+ &["foo", "foo.dSYM"],
+ &["foo.exe", "foo.pdb"],
+ &["foo.exe"],
+ );
+}
+
fn check_dir_contents(
- out_dir: &Path,
+ artifact_dir: &Path,
expected_linux: &[&str],
expected_mac: &[&str],
expected_win_msvc: &[&str],
@@ -323,7 +372,7 @@ fn check_dir_contents(
expected_linux
};
- let actual = list_dir(out_dir);
+ let actual = list_dir(artifact_dir);
let mut expected = expected.iter().map(|s| s.to_string()).collect::