Skip to content

Commit be01054

Browse files
committed
Auto merge of #7364 - phil-opp:fix-7363, r=alexcrichton
Parse `unsupported crate type` error more tightly Fixes #7363 Instead of adding a new test, we could also rename the target file in an existing custom target test if you prefer.
2 parents 59f50ab + a5edf21 commit be01054

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn parse_crate_type(
333333
) -> CargoResult<Option<(String, String)>> {
334334
let not_supported = error.lines().any(|line| {
335335
(line.contains("unsupported crate type") || line.contains("unknown crate type"))
336-
&& line.contains(crate_type)
336+
&& line.contains(&format!("crate type `{}`", crate_type))
337337
});
338338
if not_supported {
339339
return Ok(None);

tests/testsuite/custom_target.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,50 @@ fn custom_target_dependency() {
130130

131131
p.cargo("build --lib --target custom-target.json -v").run();
132132
}
133+
134+
#[cargo_test]
135+
fn custom_bin_target() {
136+
if !is_nightly() {
137+
// Requires features no_core, lang_items
138+
return;
139+
}
140+
let p = project()
141+
.file(
142+
"src/main.rs",
143+
r#"
144+
#![feature(no_core)]
145+
#![feature(lang_items)]
146+
#![no_core]
147+
#![no_main]
148+
149+
#[lang = "sized"]
150+
pub trait Sized {
151+
// Empty.
152+
}
153+
#[lang = "copy"]
154+
pub trait Copy {
155+
// Empty.
156+
}
157+
"#,
158+
)
159+
.file(
160+
"custom-bin-target.json",
161+
r#"
162+
{
163+
"llvm-target": "x86_64-unknown-none-gnu",
164+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
165+
"arch": "x86_64",
166+
"target-endian": "little",
167+
"target-pointer-width": "64",
168+
"target-c-int-width": "32",
169+
"os": "none",
170+
"linker-flavor": "ld.lld",
171+
"linker": "rust-lld",
172+
"executables": true
173+
}
174+
"#,
175+
)
176+
.build();
177+
178+
p.cargo("build --target custom-bin-target.json -v").run();
179+
}

0 commit comments

Comments
 (0)