Skip to content

Commit 655decc

Browse files
committed
Use --emit=metadata rather than --crate-type=metadata
Requires rust-lang/rust#38571
1 parent 71e996e commit 655decc

File tree

3 files changed

+39
-51
lines changed

3 files changed

+39
-51
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
146146
unit: &Unit<'a>,
147147
crate_types: &mut BTreeSet<String>)
148148
-> CargoResult<()> {
149-
if unit.profile.check {
150-
crate_types.insert("metadata".to_string());
151-
}
152149
for target in unit.pkg.manifest().targets() {
153150
crate_types.extend(target.rustc_crate_types().iter().map(|s| {
154151
if *s == "lib" {
@@ -180,11 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
180177
.env_remove("RUST_LOG");
181178

182179
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-
}
180+
process.arg("--crate-type").arg(crate_type);
188181
}
189182
if kind == Kind::Target {
190183
process.arg("--target").arg(&self.target_triple());
@@ -216,9 +209,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
216209
map.insert(crate_type.to_string(), None);
217210
continue;
218211
}
219-
if crate_type == "metadata" {
220-
continue;
221-
}
222212
let line = match lines.next() {
223213
Some(line) => line,
224214
None => bail!("malformed output when learning about \
@@ -235,12 +225,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
235225
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
236226
}
237227

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-
244228
let cfg = if has_cfg {
245229
Some(try!(lines.map(Cfg::from_str).collect()))
246230
} else {
@@ -502,32 +486,36 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
502486
let mut ret = Vec::new();
503487
let mut unsupported = Vec::new();
504488
{
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-
528489
if unit.profile.check {
529-
add("metadata", true)?;
490+
let filename = out_dir.join(format!("lib{}.rmeta", stem));
491+
let link_dst = link_stem.clone().map(|(ld, ls)| {
492+
ld.join(format!("lib{}.rmeta", ls))
493+
});
494+
ret.push((filename, link_dst, true));
530495
} else {
496+
let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
497+
let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
498+
match info.crate_types.get(crate_type) {
499+
Some(&Some((ref prefix, ref suffix))) => {
500+
let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
501+
let link_dst = link_stem.clone().map(|(ld, ls)| {
502+
ld.join(format!("{}{}{}", prefix, ls, suffix))
503+
});
504+
ret.push((filename, link_dst, linkable));
505+
Ok(())
506+
}
507+
// not supported, don't worry about it
508+
Some(&None) => {
509+
unsupported.push(crate_type.to_string());
510+
Ok(())
511+
}
512+
None => {
513+
bail!("failed to learn about crate-type `{}` early on",
514+
crate_type)
515+
}
516+
}
517+
};
518+
531519
match *unit.target.kind() {
532520
TargetKind::Example |
533521
TargetKind::Bin |

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 9 additions & 9 deletions
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,14 +565,18 @@ fn build_base_args(cx: &mut Context,
566565
cmd.arg("--error-format").arg("json");
567566
}
568567

569-
if check {
570-
cmd.arg("--crate-type").arg("metadata");
571-
} else if !test {
568+
if !test {
572569
for crate_type in crate_types.iter() {
573570
cmd.arg("--crate-type").arg(crate_type);
574571
}
575572
}
576573

574+
if check {
575+
cmd.arg("--emit=dep-info,metadata");
576+
} else {
577+
cmd.arg("--emit=dep-info,link");
578+
}
579+
577580
let prefer_dynamic = (unit.target.for_host() &&
578581
!unit.target.is_custom_build()) ||
579582
(crate_types.contains(&"dylib") &&
@@ -653,10 +656,9 @@ fn build_base_args(cx: &mut Context,
653656
if rpath {
654657
cmd.arg("-C").arg("rpath");
655658
}
656-
}
657659

660+
cmd.arg("--out-dir").arg(&cx.out_dir(unit));
658661

659-
fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
660662
fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str,
661663
val: Option<&OsStr>) {
662664
if let Some(val) = val {
@@ -666,9 +668,6 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
666668
}
667669
}
668670

669-
cmd.arg("--out-dir").arg(&cx.out_dir(unit));
670-
cmd.arg("--emit=dep-info,link");
671-
672671
if unit.kind == Kind::Target {
673672
opt(cmd, "--target", "", cx.requested_target().map(|s| s.as_ref()));
674673
}
@@ -677,6 +676,7 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
677676
opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
678677
}
679678

679+
680680
fn build_deps_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit)
681681
-> CargoResult<()> {
682682
cmd.arg("-L").arg(&{

src/cargo/util/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl FromStr for Cfg {
4444
let mut p = Parser::new(s);
4545
let e = p.cfg()?;
4646
if p.t.next().is_some() {
47-
bail!("malformed cfg value or key/value pair")
47+
bail!("malformed cfg value or key/value pair: `{}`", s)
4848
}
4949
Ok(e)
5050
}

0 commit comments

Comments
 (0)