From b12bd383716bed76d47b657bc11200d7d9ddb1fa Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 16 Sep 2019 09:29:59 +0200 Subject: [PATCH 1/2] Parse `unsupported crate type` error more tightly This avoids issues when the target name contains the crate type, e.g. `bin` in `custom-bin-target.json`. --- src/cargo/core/compiler/build_context/target_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index b5b74fd9024..926a1ca9664 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -333,7 +333,7 @@ fn parse_crate_type( ) -> CargoResult> { let not_supported = error.lines().any(|line| { (line.contains("unsupported crate type") || line.contains("unknown crate type")) - && line.contains(crate_type) + && line.contains(&format!("crate type `{}`", crate_type)) }); if not_supported { return Ok(None); From a5edf21770fe7534e7f4205c98e6a79a12e34b63 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 16 Sep 2019 09:31:20 +0200 Subject: [PATCH 2/2] Add a test that uses a custom binary target The custom target name contains the crate type `bin`. --- tests/testsuite/custom_target.rs | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index 8c57e3da9ca..adcec16bb13 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -130,3 +130,50 @@ fn custom_target_dependency() { p.cargo("build --lib --target custom-target.json -v").run(); } + +#[cargo_test] +fn custom_bin_target() { + if !is_nightly() { + // Requires features no_core, lang_items + return; + } + let p = project() + .file( + "src/main.rs", + r#" + #![feature(no_core)] + #![feature(lang_items)] + #![no_core] + #![no_main] + + #[lang = "sized"] + pub trait Sized { + // Empty. + } + #[lang = "copy"] + pub trait Copy { + // Empty. + } + "#, + ) + .file( + "custom-bin-target.json", + r#" + { + "llvm-target": "x86_64-unknown-none-gnu", + "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "arch": "x86_64", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "executables": true + } + "#, + ) + .build(); + + p.cargo("build --target custom-bin-target.json -v").run(); +}