Skip to content

Commit

Permalink
Auto merge of #7810 - giraffate:support_out_dir_in_build_section, r=a…
Browse files Browse the repository at this point in the history
…lexcrichton

Support out-dir in build section of Cargo configuration file

Fixed #7555.
  • Loading branch information
bors committed Jan 27, 2020
2 parents 328b7d6 + 4a1ba1c commit c326fcb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
ProfileChecking::Checked,
)?;

compile_opts.export_dir = args.value_of_path("out-dir", config);
if let Some(out_dir) = args.value_of_path("out-dir", config) {
compile_opts.export_dir = Some(out_dir);
} else if let Some(out_dir) = config.build_config()?.out_dir.as_ref() {
let out_dir = out_dir.resolve_path(config);
compile_opts.export_dir = Some(out_dir);
}
if compile_opts.export_dir.is_some() {
config
.cli_unstable()
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,7 @@ pub struct CargoBuildConfig {
pub rustc_wrapper: Option<PathBuf>,
pub rustc: Option<PathBuf>,
pub rustdoc: Option<PathBuf>,
pub out_dir: Option<ConfigRelativePath>,
}

/// A type to deserialize a list of strings from a toml file.
Expand Down
7 changes: 7 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ directory. Example:
cargo +nightly build --out-dir=out -Z unstable-options
```

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

```toml
[build]
out-dir = "out"
```

### doctest-xcompile
* Tracking Issue: [#7040](https://github.com/rust-lang/cargo/issues/7040)
* Tracking Rustc Issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/out_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,30 @@ fn avoid_build_scripts() {
);
}

#[cargo_test]
fn cargo_build_out_dir() {
let p = project()
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
.file(
".cargo/config",
r#"
[build]
out-dir = "out"
"#,
)
.build();

p.cargo("build -Z unstable-options")
.masquerade_as_nightly_cargo()
.run();
check_dir_contents(
&p.root().join("out"),
&["foo"],
&["foo", "foo.dSYM"],
&["foo.exe", "foo.pdb"],
);
}

fn check_dir_contents(
out_dir: &Path,
expected_linux: &[&str],
Expand Down

0 comments on commit c326fcb

Please sign in to comment.