target: fix destabilising target-spec-json

This commit is contained in:
David Wood
2026-01-23 11:06:57 +00:00
parent 165591238e
commit 76b6623267
5 changed files with 25 additions and 4 deletions
+3
View File
@@ -3352,6 +3352,9 @@ fn load_file(
Err(format!("could not find specification for target {target_tuple:?}"))
}
TargetTuple::TargetJson { ref contents, .. } if !unstable_options => {
Err("custom targets are unstable and require `-Zunstable-options`".to_string())
}
TargetTuple::TargetJson { ref contents, .. } => Target::from_json(contents),
}
}
@@ -15,7 +15,11 @@ fn main() {
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
// the linker to display its version number with a link-arg.
assert_rustc_uses_lld(
rustc().crate_type("cdylib").target("custom-target.json").input("lib.rs"),
rustc()
.crate_type("cdylib")
.target("custom-target.json")
.arg("-Zunstable-options")
.input("lib.rs"),
);
// But it can also be disabled via linker features.
@@ -5,8 +5,14 @@
fn main() {
let out_dir = "rustdoc-target-spec-json-path";
rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run();
rustc()
.arg("-Zunstable-options")
.crate_type("lib")
.input("dummy_core.rs")
.target("target.json")
.run();
rustdoc()
.arg("-Zunstable-options")
.input("my_crate.rs")
.out_dir(out_dir)
.library_search_path(cwd())
+8 -1
View File
@@ -20,13 +20,20 @@ fn main() {
.target("my-incomplete-platform.json")
.run_fail()
.assert_stderr_contains("missing field `llvm-target`");
let test_platform = rustc()
let _ = rustc()
.input("foo.rs")
.target("my-x86_64-unknown-linux-gnu-platform")
.crate_type("lib")
.emit("asm")
.run_fail()
.assert_stderr_contains("custom targets are unstable and require `-Zunstable-options`");
let _ = rustc()
.input("foo.rs")
.target("my-awesome-platform.json")
.crate_type("lib")
.emit("asm")
.run_fail()
.assert_stderr_contains("custom targets are unstable and require `-Zunstable-options`");
rustc()
.arg("-Zunstable-options")
.env("RUST_TARGET_PATH", ".")
+2 -1
View File
@@ -4,7 +4,8 @@
//@ check-pass
//@ no-auto-check-cfg
//@ needs-llvm-components: x86
//@ compile-flags: --crate-type=lib --check-cfg=cfg() --target={{src-base}}/check-cfg/my-awesome-platform.json
//@ compile-flags: --crate-type=lib --check-cfg=cfg()
//@ compile-flags: -Zunstable-options --target={{src-base}}/check-cfg/my-awesome-platform.json
//@ ignore-backends: gcc
#![feature(lang_items, no_core, auto_traits, rustc_attrs)]