Skip to content

Commit 51aa551

Browse files
committed
Add a forced_custom_target test
1 parent 400ba55 commit 51aa551

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ pub fn resolve_std<'cfg>(
133133
})
134134
.collect();
135135

136-
Ok((pkg_set.unwrap(), ret?))
136+
let ret = ret?;
137+
138+
Ok((pkg_set.unwrap(), ret))
137139
}
138140

139141
/// Generate a list of root `Unit`s for the standard library.

tests/build-std/main.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ fn basic() {
9292
p.cargo("test").masquerade_as_nightly_cargo().run();
9393

9494
// Check for hack that removes dylibs.
95-
let deps_dir = Path::new("target")
96-
.join("debug")
97-
.join("deps");
95+
let deps_dir = Path::new("target").join("debug").join("deps");
9896
assert!(p.glob(deps_dir.join("*.rlib")).count() > 0);
9997
assert_eq!(p.glob(deps_dir.join("*.dylib")).count(), 0);
10098
}
@@ -212,3 +210,59 @@ fn custom_test_framework() {
212210
.env("PATH", new_path)
213211
.run();
214212
}
213+
214+
#[cargo_test(build_std)]
215+
fn forced_custom_target() {
216+
// Checks how per-package-targets interct with build-std.
217+
218+
let p = project()
219+
.file(
220+
"src/main.rs",
221+
"
222+
#![no_std]
223+
#![no_main]
224+
225+
#[panic_handler]
226+
fn panic(_info: &core::panic::PanicInfo) -> ! {
227+
loop {}
228+
}
229+
230+
pub fn foo() -> u8 { 42 }
231+
",
232+
)
233+
.file(
234+
"Cargo.toml",
235+
r#"
236+
cargo-features = ["build-std", "per-package-target"]
237+
[package]
238+
name = "foo"
239+
version = "0.1.0"
240+
edition = "2018"
241+
build-std = ["core"]
242+
forced-target = "custom-target.json"
243+
"#,
244+
)
245+
.file(
246+
"custom-target.json",
247+
r#"
248+
{
249+
"llvm-target": "x86_64-unknown-none-gnu",
250+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
251+
"arch": "x86_64",
252+
"target-endian": "little",
253+
"target-pointer-width": "64",
254+
"target-c-int-width": "32",
255+
"os": "none",
256+
"linker-flavor": "ld.lld",
257+
"linker": "rust-lld",
258+
"executables": true,
259+
"panic-strategy": "abort"
260+
}
261+
"#,
262+
)
263+
.build();
264+
265+
p.cargo("build").masquerade_as_nightly_cargo().run();
266+
267+
assert!(p.target_bin("custom-target", "foo").exists());
268+
}

0 commit comments

Comments
 (0)