Skip to content

Commit

Permalink
Auto merge of rust-lang#77729 - petrochenkov:mergetarg, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

rustc_target: Move some target options from `Target` to `TargetOptions`

The only reason for `Target` to `TargetOptions` to be separate structures is that options in `TargetOptions` have reasonable defaults and options in `Target` don't.
(Otherwise all the options logically belong to a single `Target` struct.)

This PR moves a number of options with reasonable defaults from `Target` to `TargetOptions`, so they no longer needs to be specified explicitly for majority of the targets.
The move also allows to inherit the options from `rustc_target/src/spec/*_base.rs` files in a nicer way.
I didn't change any specific option values here.

The moved options are `target_c_int_width` (defaults to `"32"`), `target_endian` (defaults to `"little"`), `target_os` (defaults to `"none"`), `target_env` (defaults to `""`), `target_vendor` (defaults to `"unknown"`) and `linker_flavor` (defaults to `LinkerFlavor::Gcc`).

Next steps (in later PRs):
- Find a way to merge `TargetOptions` into `Target`
- If not, always access `TargetOptions` fields through `Deref` making it a part of `Target` at least logically (`session.target.target.options.foo` -> `session.target.target.foo`)
- ~Eliminate `session::config::Config` and use `Target` instead (`session.target.target.foo` -> `session.target.foo`)~ Done in rust-lang#77943.
- Avoid tautologies in option names (`target.target_os` -> `target.os`)
- Resolve _ rust-lang#77730 (rustc_target: The differences between `target_os = "none"` and `target_os = "unknown"`, and `target_vendor = "unknown"` and `target_vendor = ""` are unclear) noticed during implementation of this PR.
  • Loading branch information
bors committed Nov 8, 2020
2 parents 771cc7f + c0c0597 commit f2ea2f6
Show file tree
Hide file tree
Showing 181 changed files with 322 additions and 1,061 deletions.
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::apple_base::opts();
let mut base = super::apple_base::opts("macos");
base.cpu = "apple-a12".to_string();
base.max_atomic_width = Some(128);
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]);
Expand All @@ -16,15 +16,9 @@ pub fn target() -> Target {

Target {
llvm_target,
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
arch: arch.to_string(),
target_os: "macos".to_string(),
target_env: String::new(),
target_vendor: "apple".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions { target_mcount: "\u{1}mcount".to_string(), ..base },
}
}
10 changes: 2 additions & 8 deletions compiler/rustc_target/src/spec/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let base = opts(Arch::Arm64);
let base = opts("ios", Arch::Arm64);
Target {
llvm_target: "arm64-apple-ios".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "ios".to_string(),
target_env: String::new(),
target_vendor: "apple".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".to_string(),
eliminate_frame_pointer: false,
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_target/src/spec/aarch64_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let base = opts(Arch::Arm64);
let base = opts("tvos", Arch::Arm64);
Target {
llvm_target: "arm64-apple-tvos".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "tvos".to_string(),
target_env: String::new(),
target_vendor: "apple".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".to_string(),
eliminate_frame_pointer: false,
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_fuchsia.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::fuchsia_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-fuchsia".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "fuchsia".to_string(),
target_env: String::new(),
target_vendor: String::new(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

// See https://developer.android.com/ndk/guides/abis.html#arm64-v8a
// for target ABI requirements.
Expand All @@ -11,15 +11,9 @@ pub fn target() -> Target {
base.features = "+neon,+fp-armv8".to_string();
Target {
llvm_target: "aarch64-linux-android".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "android".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::windows_msvc_base::opts();
Expand All @@ -8,15 +8,9 @@ pub fn target() -> Target {

Target {
llvm_target: "aarch64-pc-windows-msvc".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "windows".to_string(),
target_env: "msvc".to_string(),
target_vendor: "pc".to_string(),
linker_flavor: LinkerFlavor::Msvc,
options: base,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_cloudabi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::cloudabi_base::opts();
Expand All @@ -8,15 +8,9 @@ pub fn target() -> Target {

Target {
llvm_target: "aarch64-unknown-cloudabi".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "cloudabi".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::freebsd_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-freebsd".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "freebsd".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, LldFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::hermit_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-hermit".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "hermit".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: base,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
target_env: "gnu".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "linux".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions {
unsupported_abis: super::arm_base::unsupported_abis(),
target_mcount: "\u{1}_mcount".to_string(),
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_musl_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-linux-musl".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
target_env: "musl".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "linux".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions {
unsupported_abis: super::arm_base::unsupported_abis(),
target_mcount: "\u{1}_mcount".to_string(),
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_netbsd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::netbsd_base::opts();
Expand All @@ -7,15 +7,9 @@ pub fn target() -> Target {

Target {
llvm_target: "aarch64-unknown-netbsd".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "netbsd".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions { target_mcount: "__mcount".to_string(), ..base },
}
}
8 changes: 2 additions & 6 deletions compiler/rustc_target/src/spec/aarch64_unknown_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp

pub fn target() -> Target {
let opts = TargetOptions {
target_vendor: String::new(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
linker: Some("rust-lld".to_owned()),
features: "+strict-align,+neon,+fp-armv8".to_string(),
executables: true,
Expand All @@ -23,15 +25,9 @@ pub fn target() -> Target {
};
Target {
llvm_target: "aarch64-unknown-none".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
target_os: "none".to_string(),
target_env: String::new(),
target_vendor: String::new(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: opts,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp

pub fn target() -> Target {
let opts = TargetOptions {
target_vendor: String::new(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
linker: Some("rust-lld".to_owned()),
features: "+strict-align,-neon,-fp-armv8".to_string(),
executables: true,
Expand All @@ -23,15 +25,9 @@ pub fn target() -> Target {
};
Target {
llvm_target: "aarch64-unknown-none".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
target_os: "none".to_string(),
target_env: String::new(),
target_vendor: String::new(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: opts,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_openbsd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::openbsd_base::opts();
Expand All @@ -7,15 +7,9 @@ pub fn target() -> Target {

Target {
llvm_target: "aarch64-unknown-openbsd".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "openbsd".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_unknown_redox.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::spec::{LinkerFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::redox_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-redox".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "redox".to_string(),
target_env: "relibc".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
}
}
8 changes: 1 addition & 7 deletions compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, Target};
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::windows_uwp_msvc_base::opts();
Expand All @@ -7,15 +7,9 @@ pub fn target() -> Target {

Target {
llvm_target: "aarch64-pc-windows-msvc".to_string(),
target_endian: "little".to_string(),
pointer_width: 64,
target_c_int_width: "32".to_string(),
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "windows".to_string(),
target_env: "msvc".to_string(),
target_vendor: "uwp".to_string(),
linker_flavor: LinkerFlavor::Msvc,
options: base,
}
}
Loading

0 comments on commit f2ea2f6

Please sign in to comment.