Skip to content

Commit 7155c65

Browse files
Rollup merge of #132565 - bjorn3:less_target_name_dependence, r=workingjubilee
Reduce dependence on the target name The target name can be anything with custom target specs. Matching on fields inside the target spec is much more robust than matching on the target name. Also remove the unused is_builtin target spec field.
2 parents 3313e76 + 775aad8 commit 7155c65

File tree

8 files changed

+18
-50
lines changed

8 files changed

+18
-50
lines changed

compiler/rustc_codegen_gcc/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
146146

147147
// Wasm statics with custom link sections get special treatment as they
148148
// go into custom sections of the wasm executable.
149-
if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") {
149+
if self.tcx.sess.target.is_like_wasm {
150150
if let Some(_section) = attrs.link_section {
151151
unimplemented!();
152152
}

compiler/rustc_codegen_llvm/src/back/write.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -945,23 +945,10 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
945945
asm
946946
}
947947

948-
fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
949-
let triple = cgcx.opts.target_triple.tuple();
950-
triple.contains("-ios")
951-
|| triple.contains("-darwin")
952-
|| triple.contains("-tvos")
953-
|| triple.contains("-watchos")
954-
|| triple.contains("-visionos")
955-
}
956-
957-
fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
958-
cgcx.opts.target_triple.tuple().contains("-aix")
959-
}
960-
961948
pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr {
962-
if target_is_apple(cgcx) {
949+
if cgcx.target_is_like_osx {
963950
c"__LLVM,__bitcode"
964-
} else if target_is_aix(cgcx) {
951+
} else if cgcx.target_is_like_aix {
965952
c".ipa"
966953
} else {
967954
c".llvmbc"
@@ -1028,10 +1015,12 @@ unsafe fn embed_bitcode(
10281015
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
10291016
// and COFF we emit the sections using module level inline assembly for that
10301017
// reason (see issue #90326 for historical background).
1031-
let is_aix = target_is_aix(cgcx);
1032-
let is_apple = target_is_apple(cgcx);
10331018
unsafe {
1034-
if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") {
1019+
if cgcx.target_is_like_osx
1020+
|| cgcx.target_is_like_aix
1021+
|| cgcx.target_arch == "wasm32"
1022+
|| cgcx.target_arch == "wasm64"
1023+
{
10351024
// We don't need custom section flags, create LLVM globals.
10361025
let llconst = common::bytes_in_context(llcx, bitcode);
10371026
let llglobal = llvm::LLVMAddGlobal(
@@ -1052,9 +1041,9 @@ unsafe fn embed_bitcode(
10521041
c"rustc.embedded.cmdline".as_ptr(),
10531042
);
10541043
llvm::LLVMSetInitializer(llglobal, llconst);
1055-
let section = if is_apple {
1044+
let section = if cgcx.target_is_like_osx {
10561045
c"__LLVM,__cmdline"
1057-
} else if is_aix {
1046+
} else if cgcx.target_is_like_aix {
10581047
c".info"
10591048
} else {
10601049
c".llvmcmd"

compiler/rustc_codegen_ssa/src/back/link.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ pub fn link_binary(
8585
}
8686

8787
if invalid_output_for_target(sess, crate_type) {
88-
bug!(
89-
"invalid output type `{:?}` for target os `{}`",
90-
crate_type,
91-
sess.opts.target_triple
92-
);
88+
bug!("invalid output type `{:?}` for target `{}`", crate_type, sess.opts.target_triple);
9389
}
9490

9591
sess.time("link_binary_check_files_are_writeable", || {
@@ -996,6 +992,7 @@ fn link_natively(
996992
&& (code < 1000 || code > 9999)
997993
{
998994
let is_vs_installed = windows_registry::find_vs_version().is_ok();
995+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
999996
let has_linker = windows_registry::find_tool(
1000997
sess.opts.target_triple.tuple(),
1001998
"link.exe",

compiler/rustc_codegen_ssa/src/back/linker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) fn get_linker<'a>(
4747
self_contained: bool,
4848
target_cpu: &'a str,
4949
) -> Box<dyn Linker + 'a> {
50+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
5051
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");
5152

5253
// If our linker looks like a batch script on Windows then to execute this

compiler/rustc_codegen_ssa/src/back/write.rs

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ pub struct CodegenContext<B: WriteBackendMethods> {
345345
pub is_pe_coff: bool,
346346
pub target_can_use_split_dwarf: bool,
347347
pub target_arch: String,
348+
pub target_is_like_osx: bool,
349+
pub target_is_like_aix: bool,
348350
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
349351
pub split_dwarf_kind: rustc_session::config::SplitDwarfKind,
350352

@@ -1195,6 +1197,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
11951197
is_pe_coff: tcx.sess.target.is_like_windows,
11961198
target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(),
11971199
target_arch: tcx.sess.target.arch.to_string(),
1200+
target_is_like_osx: tcx.sess.target.is_like_osx,
1201+
target_is_like_aix: tcx.sess.target.is_like_aix,
11981202
split_debuginfo: tcx.sess.split_debuginfo(),
11991203
split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind,
12001204
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,

compiler/rustc_target/src/spec/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -1595,11 +1595,10 @@ macro_rules! supported_targets {
15951595
pub const TARGETS: &[&str] = &[$($tuple),+];
15961596

15971597
fn load_builtin(target: &str) -> Option<Target> {
1598-
let mut t = match target {
1598+
let t = match target {
15991599
$( $tuple => targets::$module::target(), )+
16001600
_ => return None,
16011601
};
1602-
t.is_builtin = true;
16031602
debug!("got builtin target: {:?}", t);
16041603
Some(t)
16051604
}
@@ -2128,9 +2127,6 @@ type StaticCow<T> = Cow<'static, T>;
21282127
/// through `Deref` impls.
21292128
#[derive(PartialEq, Clone, Debug)]
21302129
pub struct TargetOptions {
2131-
/// Whether the target is built-in or loaded from a custom target specification.
2132-
pub is_builtin: bool,
2133-
21342130
/// Used as the `target_endian` `cfg` variable. Defaults to little endian.
21352131
pub endian: Endian,
21362132
/// Width of c_int type. Defaults to "32".
@@ -2606,7 +2602,6 @@ impl Default for TargetOptions {
26062602
/// incomplete, and if used for compilation, will certainly not work.
26072603
fn default() -> TargetOptions {
26082604
TargetOptions {
2609-
is_builtin: false,
26102605
endian: Endian::Little,
26112606
c_int_width: "32".into(),
26122607
os: "none".into(),
@@ -3349,7 +3344,6 @@ impl Target {
33493344
}
33503345
}
33513346

3352-
key!(is_builtin, bool);
33533347
key!(c_int_width = "target-c-int-width");
33543348
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
33553349
key!(os);
@@ -3462,10 +3456,6 @@ impl Target {
34623456
key!(entry_abi, Conv)?;
34633457
key!(supports_xray, bool);
34643458

3465-
if base.is_builtin {
3466-
// This can cause unfortunate ICEs later down the line.
3467-
return Err("may not set is_builtin for targets not built-in".into());
3468-
}
34693459
base.update_from_cli();
34703460

34713461
// Each field should have been read using `Json::remove` so any keys remaining are unused.
@@ -3635,7 +3625,6 @@ impl ToJson for Target {
36353625
target_val!(arch);
36363626
target_val!(data_layout);
36373627

3638-
target_option_val!(is_builtin);
36393628
target_option_val!(endian, "target-endian");
36403629
target_option_val!(c_int_width, "target-c-int-width");
36413630
target_option_val!(os);

tests/run-make/target-specs/definitely-not-builtin-target.json

-7
This file was deleted.

tests/run-make/target-specs/rmake.rs

-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ fn main() {
5252
.expected_file("test-platform.json")
5353
.actual_text("test-platform-2", test_platform_2)
5454
.run();
55-
rustc()
56-
.input("foo.rs")
57-
.target("definitely-not-builtin-target")
58-
.run_fail()
59-
.assert_stderr_contains("may not set is_builtin");
6055
rustc()
6156
.input("foo.rs")
6257
.target("endianness-mismatch")

0 commit comments

Comments
 (0)