Skip to content

Commit 9d19975

Browse files
committed
Auto merge of #3468 - nrc:metadata-emit, r=alexcrichton
cargo check: use --emit=metadata rather than --crate-type=metadata Requires rust-lang/rust#38571 (don't land before that does) r? @alexcrichton
2 parents 71e996e + 43af12a commit 9d19975

File tree

2 files changed

+38
-46
lines changed

2 files changed

+38
-46
lines changed

Diff for: src/cargo/ops/cargo_rustc/context.rs

+29-35
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
180180
.env_remove("RUST_LOG");
181181

182182
for crate_type in crate_types {
183-
// Here and below we'll skip the metadata crate-type because it is
184-
// not supported by older compilers. We'll do this one manually.
185-
if crate_type != "metadata" {
186-
process.arg("--crate-type").arg(crate_type);
187-
}
183+
process.arg("--crate-type").arg(crate_type);
188184
}
189185
if kind == Kind::Target {
190186
process.arg("--target").arg(&self.target_triple());
@@ -235,12 +231,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
235231
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
236232
}
237233

238-
// Manually handle the metadata case. If it is not supported by the
239-
// compiler we'll error out elsewhere.
240-
if crate_types.contains("metadata") {
241-
map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned())));
242-
}
243-
244234
let cfg = if has_cfg {
245235
Some(try!(lines.map(Cfg::from_str).collect()))
246236
} else {
@@ -502,32 +492,36 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
502492
let mut ret = Vec::new();
503493
let mut unsupported = Vec::new();
504494
{
505-
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
506-
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
507-
match info.crate_types.get(crate_type) {
508-
Some(&Some((ref prefix, ref suffix))) => {
509-
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
510-
let link_dst = link_stem.clone().map(|(ld, ls)| {
511-
ld.join(format!("{}{}{}", prefix, ls, suffix))
512-
});
513-
ret.push((filename, link_dst, linkable));
514-
Ok(())
515-
}
516-
// not supported, don't worry about it
517-
Some(&None) => {
518-
unsupported.push(crate_type.to_string());
519-
Ok(())
520-
}
521-
None => {
522-
bail!("failed to learn about crate-type `{}` early on",
523-
crate_type)
524-
}
525-
}
526-
};
527-
528495
if unit.profile.check {
529-
add("metadata", true)?;
496+
let filename = out_dir.join(format!("lib{}.rmeta", stem));
497+
let link_dst = link_stem.clone().map(|(ld, ls)| {
498+
ld.join(format!("lib{}.rmeta", ls))
499+
});
500+
ret.push((filename, link_dst, true));
530501
} else {
502+
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
503+
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
504+
match info.crate_types.get(crate_type) {
505+
Some(&Some((ref prefix, ref suffix))) => {
506+
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
507+
let link_dst = link_stem.clone().map(|(ld, ls)| {
508+
ld.join(format!("{}{}{}", prefix, ls, suffix))
509+
});
510+
ret.push((filename, link_dst, linkable));
511+
Ok(())
512+
}
513+
// not supported, don't worry about it
514+
Some(&None) => {
515+
unsupported.push(crate_type.to_string());
516+
Ok(())
517+
}
518+
None => {
519+
bail!("failed to learn about crate-type `{}` early on",
520+
crate_type)
521+
}
522+
}
523+
};
524+
531525
match *unit.target.kind() {
532526
TargetKind::Example |
533527
TargetKind::Bin |

Diff for: src/cargo/ops/cargo_rustc/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ fn prepare_rustc(cx: &mut Context,
460460
unit: &Unit) -> CargoResult<ProcessBuilder> {
461461
let mut base = cx.compilation.rustc_process(unit.pkg)?;
462462
build_base_args(cx, &mut base, unit, &crate_types);
463-
build_plugin_args(&mut base, cx, unit);
464463
build_deps_args(&mut base, cx, unit)?;
465464
Ok(base)
466465
}
@@ -566,12 +565,14 @@ fn build_base_args(cx: &mut Context,
566565
cmd.arg("--error-format").arg("json");
567566
}
568567

568+
for crate_type in crate_types.iter() {
569+
cmd.arg("--crate-type").arg(crate_type);
570+
}
571+
569572
if check {
570-
cmd.arg("--crate-type").arg("metadata");
571-
} else if !test {
572-
for crate_type in crate_types.iter() {
573-
cmd.arg("--crate-type").arg(crate_type);
574-
}
573+
cmd.arg("--emit=dep-info,metadata");
574+
} else {
575+
cmd.arg("--emit=dep-info,link");
575576
}
576577

577578
let prefer_dynamic = (unit.target.for_host() &&
@@ -653,10 +654,9 @@ fn build_base_args(cx: &mut Context,
653654
if rpath {
654655
cmd.arg("-C").arg("rpath");
655656
}
656-
}
657657

658+
cmd.arg("--out-dir").arg(&cx.out_dir(unit));
658659

659-
fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
660660
fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str,
661661
val: Option<&OsStr>) {
662662
if let Some(val) = val {
@@ -666,9 +666,6 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
666666
}
667667
}
668668

669-
cmd.arg("--out-dir").arg(&cx.out_dir(unit));
670-
cmd.arg("--emit=dep-info,link");
671-
672669
if unit.kind == Kind::Target {
673670
opt(cmd, "--target", "", cx.requested_target().map(|s| s.as_ref()));
674671
}
@@ -677,6 +674,7 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
677674
opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
678675
}
679676

677+
680678
fn build_deps_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit)
681679
-> CargoResult<()> {
682680
cmd.arg("-L").arg(&{

0 commit comments

Comments
 (0)