Files
cargo_fmt
coverage_test_macros
git_rustfmt
rustc_apfloat
rustc_arena
rustc_ast
rustc_ast_lowering
rustc_ast_passes
rustc_ast_pretty
rustc_attr
rustc_borrowck
rustc_builtin_macros
rustc_codegen_llvm
rustc_codegen_ssa
rustc_const_eval
rustc_data_structures
rustc_driver
rustc_error_codes
rustc_errors
rustc_expand
rustc_feature
rustc_fs_util
rustc_graphviz
rustc_hir
rustc_hir_pretty
rustc_incremental
rustc_index
rustc_infer
rustc_interface
rustc_lexer
rustc_lint
rustc_lint_defs
rustc_llvm
rustc_macros
rustc_metadata
rustc_middle
rustc_mir_build
rustc_mir_dataflow
rustc_mir_transform
rustc_monomorphize
rustc_parse
rustc_parse_format
rustc_passes
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_query_system
rustc_resolve
rustc_save_analysis
rustc_serialize
rustc_session
rustc_span
rustc_symbol_mangling
rustc_target
abi
asm
spec
aarch64_apple_darwin.rsaarch64_apple_ios.rsaarch64_apple_ios_macabi.rsaarch64_apple_ios_sim.rsaarch64_apple_tvos.rsaarch64_be_unknown_linux_gnu.rsaarch64_be_unknown_linux_gnu_ilp32.rsaarch64_fuchsia.rsaarch64_kmc_solid_asp3.rsaarch64_linux_android.rsaarch64_pc_windows_msvc.rsaarch64_unknown_freebsd.rsaarch64_unknown_hermit.rsaarch64_unknown_linux_gnu.rsaarch64_unknown_linux_gnu_ilp32.rsaarch64_unknown_linux_musl.rsaarch64_unknown_netbsd.rsaarch64_unknown_none.rsaarch64_unknown_none_softfloat.rsaarch64_unknown_openbsd.rsaarch64_unknown_redox.rsaarch64_unknown_uefi.rsaarch64_uwp_windows_msvc.rsaarch64_wrs_vxworks.rsabi.rsandroid_base.rsapple_base.rsapple_sdk_base.rsarm_linux_androideabi.rsarm_unknown_linux_gnueabi.rsarm_unknown_linux_gnueabihf.rsarm_unknown_linux_musleabi.rsarm_unknown_linux_musleabihf.rsarmebv7r_none_eabi.rsarmebv7r_none_eabihf.rsarmv4t_unknown_linux_gnueabi.rsarmv5te_unknown_linux_gnueabi.rsarmv5te_unknown_linux_musleabi.rsarmv5te_unknown_linux_uclibceabi.rsarmv6_unknown_freebsd.rsarmv6_unknown_netbsd_eabihf.rsarmv6k_nintendo_3ds.rsarmv7_apple_ios.rsarmv7_linux_androideabi.rsarmv7_unknown_freebsd.rsarmv7_unknown_linux_gnueabi.rsarmv7_unknown_linux_gnueabihf.rsarmv7_unknown_linux_musleabi.rsarmv7_unknown_linux_musleabihf.rsarmv7_unknown_linux_uclibceabihf.rsarmv7_unknown_netbsd_eabihf.rsarmv7_wrs_vxworks_eabihf.rsarmv7a_kmc_solid_asp3_eabi.rsarmv7a_kmc_solid_asp3_eabihf.rsarmv7a_none_eabi.rsarmv7a_none_eabihf.rsarmv7r_none_eabi.rsarmv7r_none_eabihf.rsarmv7s_apple_ios.rsasmjs_unknown_emscripten.rsavr_gnu_base.rsavr_unknown_gnu_atmega328.rsbpf_base.rsbpfeb_unknown_none.rsbpfel_unknown_none.rscrt_objects.rsdragonfly_base.rsfreebsd_base.rsfuchsia_base.rshaiku_base.rshermit_base.rshermit_kernel_base.rshexagon_unknown_linux_musl.rsi386_apple_ios.rsi586_pc_windows_msvc.rsi586_unknown_linux_gnu.rsi586_unknown_linux_musl.rsi686_apple_darwin.rsi686_linux_android.rsi686_pc_windows_gnu.rsi686_pc_windows_msvc.rsi686_unknown_freebsd.rsi686_unknown_haiku.rsi686_unknown_linux_gnu.rsi686_unknown_linux_musl.rsi686_unknown_netbsd.rsi686_unknown_openbsd.rsi686_unknown_uefi.rsi686_uwp_windows_gnu.rsi686_uwp_windows_msvc.rsi686_wrs_vxworks.rsillumos_base.rsl4re_base.rslinux_base.rslinux_gnu_base.rslinux_kernel_base.rslinux_musl_base.rslinux_uclibc_base.rsm68k_unknown_linux_gnu.rsmips64_unknown_linux_gnuabi64.rsmips64_unknown_linux_muslabi64.rsmips64el_unknown_linux_gnuabi64.rsmips64el_unknown_linux_muslabi64.rsmips_unknown_linux_gnu.rsmips_unknown_linux_musl.rsmips_unknown_linux_uclibc.rsmipsel_sony_psp.rsmipsel_unknown_linux_gnu.rsmipsel_unknown_linux_musl.rsmipsel_unknown_linux_uclibc.rsmipsel_unknown_none.rsmipsisa32r6_unknown_linux_gnu.rsmipsisa32r6el_unknown_linux_gnu.rsmipsisa64r6_unknown_linux_gnuabi64.rsmipsisa64r6el_unknown_linux_gnuabi64.rsmod.rsmsp430_none_elf.rsmsvc_base.rsnetbsd_base.rsnvptx64_nvidia_cuda.rsopenbsd_base.rspowerpc64_unknown_freebsd.rspowerpc64_unknown_linux_gnu.rspowerpc64_unknown_linux_musl.rspowerpc64_wrs_vxworks.rspowerpc64le_unknown_freebsd.rspowerpc64le_unknown_linux_gnu.rspowerpc64le_unknown_linux_musl.rspowerpc_unknown_freebsd.rspowerpc_unknown_linux_gnu.rspowerpc_unknown_linux_gnuspe.rspowerpc_unknown_linux_musl.rspowerpc_unknown_netbsd.rspowerpc_unknown_openbsd.rspowerpc_wrs_vxworks.rspowerpc_wrs_vxworks_spe.rsredox_base.rsriscv32gc_unknown_linux_gnu.rsriscv32gc_unknown_linux_musl.rsriscv32i_unknown_none_elf.rsriscv32imac_unknown_none_elf.rsriscv32imc_esp_espidf.rsriscv32imc_unknown_none_elf.rsriscv64gc_unknown_linux_gnu.rsriscv64gc_unknown_linux_musl.rsriscv64gc_unknown_none_elf.rsriscv64imac_unknown_none_elf.rss390x_unknown_linux_gnu.rss390x_unknown_linux_musl.rssolaris_base.rssolid_base.rssparc64_unknown_linux_gnu.rssparc64_unknown_netbsd.rssparc64_unknown_openbsd.rssparc_unknown_linux_gnu.rssparcv9_sun_solaris.rsthumb_base.rsthumbv4t_none_eabi.rsthumbv6m_none_eabi.rsthumbv7a_pc_windows_msvc.rsthumbv7a_uwp_windows_msvc.rsthumbv7em_none_eabi.rsthumbv7em_none_eabihf.rsthumbv7m_none_eabi.rsthumbv7neon_linux_androideabi.rsthumbv7neon_unknown_linux_gnueabihf.rsthumbv7neon_unknown_linux_musleabihf.rsthumbv8m_base_none_eabi.rsthumbv8m_main_none_eabi.rsthumbv8m_main_none_eabihf.rsuefi_msvc_base.rsvxworks_base.rswasm32_unknown_emscripten.rswasm32_unknown_unknown.rswasm32_wasi.rswasm64_unknown_unknown.rswasm_base.rswindows_gnu_base.rswindows_msvc_base.rswindows_uwp_gnu_base.rswindows_uwp_msvc_base.rsx86_64_apple_darwin.rsx86_64_apple_ios.rsx86_64_apple_ios_macabi.rsx86_64_apple_tvos.rsx86_64_fortanix_unknown_sgx.rsx86_64_fuchsia.rsx86_64_linux_android.rsx86_64_pc_solaris.rsx86_64_pc_windows_gnu.rsx86_64_pc_windows_msvc.rsx86_64_sun_solaris.rsx86_64_unknown_dragonfly.rsx86_64_unknown_freebsd.rsx86_64_unknown_haiku.rsx86_64_unknown_hermit.rsx86_64_unknown_illumos.rsx86_64_unknown_l4re_uclibc.rsx86_64_unknown_linux_gnu.rsx86_64_unknown_linux_gnux32.rsx86_64_unknown_linux_musl.rsx86_64_unknown_netbsd.rsx86_64_unknown_none_hermitkernel.rsx86_64_unknown_none_linuxkernel.rsx86_64_unknown_openbsd.rsx86_64_unknown_redox.rsx86_64_unknown_uefi.rsx86_64_uwp_windows_gnu.rsx86_64_uwp_windows_msvc.rsx86_64_wrs_vxworks.rs
rustc_trait_selection
rustc_traits
rustc_ty_utils
rustc_type_ir
rustc_typeck
rustdoc
rustdoc_json_types
rustfmt
rustfmt_format_diff
rustfmt_nightly
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
use std::env;

use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};

pub fn opts(os: &str) -> TargetOptions {
    // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
    // either the linker will complain if it is used or the binary will end up
    // segfaulting at runtime when run on 10.6. Rust by default supports macOS
    // 10.7+, but there is a standard environment variable,
    // MACOSX_DEPLOYMENT_TARGET, which is used to signal targeting older
    // versions of macOS. For example compiling on 10.10 with
    // MACOSX_DEPLOYMENT_TARGET set to 10.6 will cause the linker to generate
    // warnings about the usage of ELF TLS.
    //
    // Here we detect what version is being requested, defaulting to 10.7. ELF
    // TLS is flagged as enabled if it looks to be supported.
    let version = macos_deployment_target();

    TargetOptions {
        os: os.to_string(),
        vendor: "apple".to_string(),
        // macOS has -dead_strip, which doesn't rely on function_sections
        function_sections: false,
        dynamic_linking: true,
        linker_is_gnu: false,
        executables: true,
        families: vec!["unix".to_string()],
        is_like_osx: true,
        dwarf_version: Some(2),
        frame_pointer: FramePointer::Always,
        has_rpath: true,
        dll_suffix: ".dylib".to_string(),
        archive_format: "darwin".to_string(),
        has_elf_tls: version >= (10, 7),
        abi_return_struct_as_int: true,
        emit_debug_gdb_scripts: false,
        eh_frame_header: false,
        lld_flavor: LldFlavor::Ld64,

        // The historical default for macOS targets is to run `dsymutil` which
        // generates a packed version of debuginfo split from the main file.
        split_debuginfo: SplitDebuginfo::Packed,

        // This environment variable is pretty magical but is intended for
        // producing deterministic builds. This was first discovered to be used
        // by the `ar` tool as a way to control whether or not mtime entries in
        // the archive headers were set to zero or not. It appears that
        // eventually the linker got updated to do the same thing and now reads
        // this environment variable too in recent versions.
        //
        // For some more info see the commentary on #47086
        link_env: vec![("ZERO_AR_DATE".to_string(), "1".to_string())],

        ..Default::default()
    }
}

fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
    let deployment_target = env::var(var_name).ok();
    deployment_target
        .as_ref()
        .and_then(|s| s.split_once('.'))
        .and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok())
}

fn macos_deployment_target() -> (u32, u32) {
    deployment_target("MACOSX_DEPLOYMENT_TARGET").unwrap_or((10, 7))
}

pub fn macos_llvm_target(arch: &str) -> String {
    let (major, minor) = macos_deployment_target();
    format!("{}-apple-macosx{}.{}.0", arch, major, minor)
}

pub fn macos_link_env_remove() -> Vec<String> {
    let mut env_remove = Vec::with_capacity(2);
    // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
    // may occur when we're linking a custom build script while targeting iOS for example.
    if let Ok(sdkroot) = env::var("SDKROOT") {
        if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") {
            env_remove.push("SDKROOT".to_string())
        }
    }
    // Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
    // "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
    // although this is apparently ignored when using the linker at "/usr/bin/ld".
    env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".to_string());
    env_remove
}

fn ios_deployment_target() -> (u32, u32) {
    deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
}

pub fn ios_llvm_target(arch: &str) -> String {
    // Modern iOS tooling extracts information about deployment target
    // from LC_BUILD_VERSION. This load command will only be emitted when
    // we build with a version specific `llvm_target`, with the version
    // set high enough. Luckily one LC_BUILD_VERSION is enough, for Xcode
    // to pick it up (since std and core are still built with the fallback
    // of version 7.0 and hence emit the old LC_IPHONE_MIN_VERSION).
    let (major, minor) = ios_deployment_target();
    format!("{}-apple-ios{}.{}.0", arch, major, minor)
}

pub fn ios_sim_llvm_target(arch: &str) -> String {
    let (major, minor) = ios_deployment_target();
    format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
}