rust/tests/run-make/target-specs/rmake.rs
Eric Huss 6de57ea1ec [beta] Revert destabilise target-spec-json
This reverts https://github.com/rust-lang/rust/pull/150151 in order to
deal with https://github.com/rust-lang/rust/issues/151729 where the
destabilization caused a problem with building rustc itself with JSON
target specs. There's a fix at
https://github.com/rust-lang/rust/pull/152677, but we would prefer to
not backport that, and instead give ourselves more time to work out the
kinks. Also, the destabilization was incomplete, and the rest of the
changes are in 1.95 (https://github.com/rust-lang/rust/pull/151534 and
https://github.com/rust-lang/cargo/pull/16557), so it would be nice to
keep all the changes together in one release.

This reverts commit a89683dd95, reversing
changes made to 2f1bd3f378.
2026-02-16 09:07:31 -08:00

78 lines
2.7 KiB
Rust

// Target-specific compilation in rustc used to have case-by-case peculiarities in 2014,
// with the compiler having redundant target types and unspecific names. An overarching rework
// in #16156 changed the way the target flag functions, and this test attempts compilation
// with the target flag's bundle of new features to check that compilation either succeeds while
// using them correctly, or fails with the right error message when using them improperly.
// See https://github.com/rust-lang/rust/pull/16156
//@ needs-llvm-components: x86
use run_make_support::{diff, rfs, rustc};
fn main() {
rustc()
.input("foo.rs")
.target("my-invalid-platform.json")
.run_fail()
.assert_stderr_contains("error loading target specification");
rustc()
.input("foo.rs")
.target("my-incomplete-platform.json")
.run_fail()
.assert_stderr_contains("missing field `llvm-target`");
rustc()
.env("RUST_TARGET_PATH", ".")
.input("foo.rs")
.target("my-awesome-platform")
.crate_type("lib")
.emit("asm")
.run();
rustc()
.env("RUST_TARGET_PATH", ".")
.input("foo.rs")
.target("my-x86_64-unknown-linux-gnu-platform")
.crate_type("lib")
.emit("asm")
.run();
let test_platform = rustc()
.arg("-Zunstable-options")
.target("my-awesome-platform.json")
.print("target-spec-json")
.run()
.stdout_utf8();
rfs::create_file("test-platform.json");
rfs::write("test-platform.json", test_platform.as_bytes());
let test_platform_2 = rustc()
.arg("-Zunstable-options")
.target("test-platform.json")
.print("target-spec-json")
.run()
.stdout_utf8();
diff()
.expected_file("test-platform.json")
.actual_text("test-platform-2", test_platform_2)
.run();
rustc()
.input("foo.rs")
.target("endianness-mismatch")
.run_fail()
.assert_stderr_contains(r#""data-layout" claims architecture is little-endian"#);
rustc()
.input("foo.rs")
.target("mismatching-data-layout")
.crate_type("lib")
.run_fail()
.assert_stderr_contains("data-layout for target");
rustc()
.input("foo.rs")
.target("require-explicit-cpu")
.crate_type("lib")
.run_fail()
.assert_stderr_contains("target requires explicitly specifying a cpu");
rustc()
.input("foo.rs")
.target("require-explicit-cpu")
.crate_type("lib")
.arg("-Ctarget-cpu=generic")
.run();
rustc().target("require-explicit-cpu").arg("--print=target-cpus").run();
}