Skip to content

Commit 1695b89

Browse files
committed
Merge branch 'master' into 7656-format-placeholder-code-when-generating-a-crate
2 parents 768b60a + 4fbd644 commit 1695b89

File tree

9 files changed

+102
-30
lines changed

9 files changed

+102
-30
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ atty = "0.2"
2323
bytesize = "1.0"
2424
cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" }
2525
crates-io = { path = "crates/crates-io", version = "0.31" }
26+
crossbeam-channel = "0.4"
2627
crossbeam-utils = "0.7"
2728
crypto-hash = "0.3.1"
2829
curl = { version = "0.4.23", features = ["http2"] }
2930
curl-sys = "0.4.22"
3031
env_logger = "0.7.0"
31-
pretty_env_logger = { version = "0.3", optional = true }
32+
pretty_env_logger = { version = "0.4", optional = true }
3233
anyhow = "1.0"
3334
filetime = "0.2"
3435
flate2 = { version = "1.0.3", features = ["zlib"] }

src/bin/cargo/commands/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6363
ProfileChecking::Checked,
6464
)?;
6565

66-
compile_opts.export_dir = args.value_of_path("out-dir", config);
66+
if let Some(out_dir) = args.value_of_path("out-dir", config) {
67+
compile_opts.export_dir = Some(out_dir);
68+
} else if let Some(out_dir) = config.build_config()?.out_dir.as_ref() {
69+
let out_dir = out_dir.resolve_path(config);
70+
compile_opts.export_dir = Some(out_dir);
71+
}
6772
if compile_opts.export_dir.is_some() {
6873
config
6974
.cli_unstable()

src/cargo/core/compiler/job_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ use std::collections::{BTreeMap, HashMap, HashSet};
5454
use std::io;
5555
use std::marker;
5656
use std::mem;
57-
use std::sync::mpsc::{channel, Receiver, Sender};
5857
use std::sync::Arc;
5958
use std::time::Duration;
6059

6160
use anyhow::format_err;
61+
use crossbeam_channel::{unbounded, Receiver, Sender};
6262
use crossbeam_utils::thread::Scope;
6363
use jobserver::{Acquired, Client, HelperThread};
6464
use log::{debug, info, trace};
@@ -341,7 +341,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
341341
let _p = profile::start("executing the job graph");
342342
self.queue.queue_finished();
343343

344-
let (tx, rx) = channel();
344+
let (tx, rx) = unbounded();
345345
let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
346346
let state = DrainState {
347347
total_units: self.queue.len(),

src/cargo/core/workspace.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ impl<'cfg> Workspace<'cfg> {
829829
}
830830
Ok(())
831831
}
832+
833+
pub fn set_target_dir(&mut self, target_dir: Filesystem) {
834+
self.target_dir = Some(target_dir);
835+
}
832836
}
833837

834838
impl<'cfg> Packages<'cfg> {

src/cargo/ops/cargo_install.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,35 @@ fn install_one(
200200
)?
201201
};
202202

203-
let mut td_opt = None;
204-
let mut needs_cleanup = false;
205-
let overidden_target_dir = if source_id.is_path() {
206-
None
207-
} else if let Some(dir) = config.target_dir()? {
208-
Some(dir)
209-
} else if let Ok(td) = TempFileBuilder::new().prefix("cargo-install").tempdir() {
210-
let p = td.path().to_owned();
211-
td_opt = Some(td);
212-
Some(Filesystem::new(p))
203+
let (mut ws, git_package) = if source_id.is_git() {
204+
// Don't use ws.current() in order to keep the package source as a git source so that
205+
// install tracking uses the correct source.
206+
(Workspace::new(pkg.manifest_path(), config)?, Some(&pkg))
207+
} else if source_id.is_path() {
208+
(Workspace::new(pkg.manifest_path(), config)?, None)
213209
} else {
214-
needs_cleanup = true;
215-
Some(Filesystem::new(config.cwd().join("target-install")))
216-
};
217-
218-
let mut ws = match overidden_target_dir {
219-
Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
220-
None => {
221-
let mut ws = Workspace::new(pkg.manifest_path(), config)?;
222-
ws.set_require_optional_deps(false);
223-
ws
224-
}
210+
(Workspace::ephemeral(pkg, config, None, false)?, None)
225211
};
226212
ws.set_ignore_lock(config.lock_update_allowed());
227-
let pkg = ws.current()?;
213+
ws.set_require_optional_deps(false);
214+
215+
let mut td_opt = None;
216+
let mut needs_cleanup = false;
217+
if !source_id.is_path() {
218+
let target_dir = if let Some(dir) = config.target_dir()? {
219+
dir
220+
} else if let Ok(td) = TempFileBuilder::new().prefix("cargo-install").tempdir() {
221+
let p = td.path().to_owned();
222+
td_opt = Some(td);
223+
Filesystem::new(p)
224+
} else {
225+
needs_cleanup = true;
226+
Filesystem::new(config.cwd().join("target-install"))
227+
};
228+
ws.set_target_dir(target_dir);
229+
}
230+
231+
let pkg = git_package.map_or_else(|| ws.current(), |pkg| Ok(pkg))?;
228232

229233
if from_cwd {
230234
if pkg.manifest().edition() == Edition::Edition2015 {

src/cargo/util/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ pub struct CargoBuildConfig {
16431643
pub rustc_wrapper: Option<PathBuf>,
16441644
pub rustc: Option<PathBuf>,
16451645
pub rustdoc: Option<PathBuf>,
1646+
pub out_dir: Option<ConfigRelativePath>,
16461647
}
16471648

16481649
/// A type to deserialize a list of strings from a toml file.

src/doc/src/reference/unstable.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ directory. Example:
7676
cargo +nightly build --out-dir=out -Z unstable-options
7777
```
7878

79+
This can also be specified in `.cargo/config` files.
80+
81+
```toml
82+
[build]
83+
out-dir = "out"
84+
```
85+
7986
### doctest-xcompile
8087
* Tracking Issue: [#7040](https://github.com/rust-lang/cargo/issues/7040)
8188
* Tracking Rustc Issue: [#64245](https://github.com/rust-lang/rust/issues/64245)

tests/testsuite/install.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ fn multiple_crates_git_all() {
316316
let p = git::repo(&paths::root().join("foo"))
317317
.file(
318318
"Cargo.toml",
319-
r#"\
320-
[workspace]
321-
members = ["bin1", "bin2"]
322-
"#,
319+
r#"
320+
[workspace]
321+
members = ["bin1", "bin2"]
322+
"#,
323323
)
324324
.file("bin1/Cargo.toml", &basic_manifest("bin1", "0.1.0"))
325325
.file("bin2/Cargo.toml", &basic_manifest("bin2", "0.1.0"))
@@ -1422,3 +1422,29 @@ fn install_version_req() {
14221422
.with_stderr_contains("[INSTALLING] foo v0.0.3")
14231423
.run();
14241424
}
1425+
1426+
#[cargo_test]
1427+
fn git_install_reads_workspace_manifest() {
1428+
let p = git::repo(&paths::root().join("foo"))
1429+
.file(
1430+
"Cargo.toml",
1431+
r#"
1432+
[workspace]
1433+
members = ["bin1"]
1434+
1435+
[profile.release]
1436+
incremental = 3
1437+
"#,
1438+
)
1439+
.file("bin1/Cargo.toml", &basic_manifest("bin1", "0.1.0"))
1440+
.file(
1441+
"bin1/src/main.rs",
1442+
r#"fn main() { println!("Hello, world!"); }"#,
1443+
)
1444+
.build();
1445+
1446+
cargo_process(&format!("install --git {}", p.url().to_string()))
1447+
.with_status(101)
1448+
.with_stderr_contains(" invalid type: integer `3`[..]")
1449+
.run();
1450+
}

tests/testsuite/out_dir.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ fn avoid_build_scripts() {
246246
);
247247
}
248248

249+
#[cargo_test]
250+
fn cargo_build_out_dir() {
251+
let p = project()
252+
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
253+
.file(
254+
".cargo/config",
255+
r#"
256+
[build]
257+
out-dir = "out"
258+
"#,
259+
)
260+
.build();
261+
262+
p.cargo("build -Z unstable-options")
263+
.masquerade_as_nightly_cargo()
264+
.run();
265+
check_dir_contents(
266+
&p.root().join("out"),
267+
&["foo"],
268+
&["foo", "foo.dSYM"],
269+
&["foo.exe", "foo.pdb"],
270+
);
271+
}
272+
249273
fn check_dir_contents(
250274
out_dir: &Path,
251275
expected_linux: &[&str],

0 commit comments

Comments
 (0)