Auto merge of #148851 - Zalathar:rollup-4y7ywyd, r=Zalathar

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#146627 (Simplify `jemalloc` setup)
 - rust-lang/rust#147753 (Suggest add bounding value for RangeTo)
 - rust-lang/rust#147832 (rustdoc: Don't pass `RenderOptions` to `DocContext`)
 - rust-lang/rust#147974 (Improve diagnostics for buffer reuse with borrowed references)
 - rust-lang/rust#148080 ([rustdoc] Fix invalid jump to def macro link generation)
 - rust-lang/rust#148465 (Adjust spans into the `for` loops context before creating the new desugaring spans.)
 - rust-lang/rust#148500 (Update git index before running diff-index)
 - rust-lang/rust#148531 (rustc_target: introduce Abi, Env, Os)
 - rust-lang/rust#148536 (cmse: add test for `async` and `const` functions)
 - rust-lang/rust#148770 (implement `feature(c_variadic_naked_functions)`)
 - rust-lang/rust#148780 (fix filecheck typos in tests)
 - rust-lang/rust#148819 (Remove specialized warning for removed target)
 - rust-lang/rust#148830 (miri subtree update)
 - rust-lang/rust#148833 (Update rustbook dependencies)
 - rust-lang/rust#148834 (fix(rustdoc): Color doctest errors)
 - rust-lang/rust#148841 (Remove more `#[must_use]` from portable-simd)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-11-12 01:28:30 +00:00
commit 0b329f801a
351 changed files with 3452 additions and 2101 deletions

View file

@ -600,6 +600,7 @@ dependencies = [
"serde_json",
"tempfile",
"termize",
"tikv-jemalloc-sys",
"toml 0.9.7",
"ui_test",
"walkdir",
@ -4806,6 +4807,7 @@ dependencies = [
"stringdex",
"tempfile",
"threadpool",
"tikv-jemalloc-sys",
"tracing",
"tracing-subscriber",
"tracing-tree",
@ -5537,9 +5539,9 @@ version = "0.1.0"
[[package]]
name = "tikv-jemalloc-sys"
version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b"
dependencies = [
"cc",
"libc",

View file

@ -21,9 +21,9 @@ rustc_public_bridge = { path = "../rustc_public_bridge" }
# tidy-alphabetical-end
[dependencies.tikv-jemalloc-sys]
version = "0.6.0"
version = "0.6.1"
optional = true
features = ['unprefixed_malloc_on_supported_platforms']
features = ['override_allocator_on_supported_platforms']
[features]
# tidy-alphabetical-start

View file

@ -7,26 +7,25 @@
// distribution. The obvious way to do this is with the `#[global_allocator]`
// mechanism. However, for complicated reasons (see
// https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001 for some
// details) that mechanism doesn't work here. Also, we must use a consistent
// allocator across the rustc <-> llvm boundary, and `#[global_allocator]`
// wouldn't provide that.
// details) that mechanism doesn't work here. Also, we'd like to use a
// consistent allocator across the rustc <-> llvm boundary, and
// `#[global_allocator]` wouldn't provide that.
//
// Instead, we use a lower-level mechanism. rustc is linked with jemalloc in a
// way such that jemalloc's implementation of `malloc`, `free`, etc., override
// the libc allocator's implementation. This means that Rust's `System`
// allocator, which calls `libc::malloc()` et al., is actually calling into
// jemalloc.
// Instead, we use a lower-level mechanism, namely the
// `"override_allocator_on_supported_platforms"` Cargo feature of jemalloc-sys.
//
// This makes jemalloc-sys override the libc/system allocator's implementation
// of `malloc`, `free`, etc.. This means that Rust's `System` allocator, which
// calls `libc::malloc()` et al., is actually calling into jemalloc.
//
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
// provides an impl of that trait, which is called `Jemalloc`) is that we
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
// It's unclear how much performance is lost because of this.
//
// As for the symbol overrides in `main` below: we're pulling in a static copy
// of jemalloc. We need to actually reference its symbols for it to get linked.
// The two crates we link to here, `std` and `rustc_driver`, are both dynamic
// libraries. So we must reference jemalloc symbols one way or another, because
// this file is the only object code in the rustc executable.
// NOTE: Even though Cargo passes `--extern` with `tikv_jemalloc_sys`, we still need to `use` the
// crate for the compiler to see the `#[used]`, see https://github.com/rust-lang/rust/issues/64402.
// This is similarly required if we used a crate with `#[global_allocator]`.
//
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
@ -36,43 +35,9 @@
// to compare their performance, see
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
// for an example of how to do so.
#[cfg(feature = "jemalloc")]
use tikv_jemalloc_sys as _;
fn main() {
// See the comment at the top of this file for an explanation of this.
#[cfg(feature = "jemalloc")]
{
use std::os::raw::{c_int, c_void};
use tikv_jemalloc_sys as jemalloc_sys;
#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
// On OSX, jemalloc doesn't directly override malloc/free, but instead
// registers itself with the allocator's zone APIs in a ctor. However,
// the linker doesn't seem to consider ctors as "used" when statically
// linking, so we need to explicitly depend on the function.
#[cfg(target_os = "macos")]
{
unsafe extern "C" {
fn _rjem_je_zone_register();
}
#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
}
}
rustc_driver::main()
}

View file

@ -645,8 +645,9 @@ macro_rules! common_visitor_and_walkers {
fn visit_fn(
&mut self,
fk: FnKind<$($lt)? $(${ignore($mut)} '_)?>,
_: &AttrVec,
_: Span,
_: NodeId
_: NodeId,
) -> Self::Result {
walk_fn(self, fk)
}
@ -740,6 +741,7 @@ macro_rules! common_visitor_and_walkers {
type Ctxt;
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
&$($lt)? $($mut)? self,
attrs: &AttrVec,
span: Span,
id: NodeId,
visibility: &$($lt)? $($mut)? Visibility,
@ -773,7 +775,7 @@ macro_rules! common_visitor_and_walkers {
) -> V::Result {
let Item { attrs, id, kind, vis, span, tokens: _ } = item;
visit_visitable!($($mut)? visitor, id, attrs, vis);
try_visit!(kind.walk(*span, *id, vis, ctxt, visitor));
try_visit!(kind.walk(attrs, *span, *id, vis, ctxt, visitor));
visit_visitable!($($mut)? visitor, span);
V::Result::output()
}
@ -799,6 +801,7 @@ macro_rules! common_visitor_and_walkers {
type Ctxt = ();
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
&$($lt)? $($mut)? self,
attrs: &AttrVec,
span: Span,
id: NodeId,
visibility: &$($lt)? $($mut)? Visibility,
@ -808,7 +811,7 @@ macro_rules! common_visitor_and_walkers {
match self {
ItemKind::Fn(func) => {
let kind = FnKind::Fn(FnCtxt::Free, visibility, &$($mut)? *func);
try_visit!(vis.visit_fn(kind, span, id));
try_visit!(vis.visit_fn(kind, attrs, span, id));
}
ItemKind::ExternCrate(orig_name, ident) =>
visit_visitable!($($mut)? vis, orig_name, ident),
@ -856,6 +859,7 @@ macro_rules! common_visitor_and_walkers {
type Ctxt = AssocCtxt;
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
&$($lt)? $($mut)? self,
attrs: &AttrVec,
span: Span,
id: NodeId,
visibility: &$($lt)? $($mut)? Visibility,
@ -867,7 +871,7 @@ macro_rules! common_visitor_and_walkers {
visit_visitable!($($mut)? vis, item),
AssocItemKind::Fn(func) => {
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), visibility, &$($mut)? *func);
try_visit!(vis.visit_fn(kind, span, id))
try_visit!(vis.visit_fn(kind, attrs, span, id))
}
AssocItemKind::Type(alias) =>
visit_visitable!($($mut)? vis, alias),
@ -886,6 +890,7 @@ macro_rules! common_visitor_and_walkers {
type Ctxt = ();
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
&$($lt)? $($mut)? self,
attrs: &AttrVec,
span: Span,
id: NodeId,
visibility: &$($lt)? $($mut)? Visibility,
@ -897,7 +902,7 @@ macro_rules! common_visitor_and_walkers {
visit_visitable!($($mut)? vis, item),
ForeignItemKind::Fn(func) => {
let kind = FnKind::Fn(FnCtxt::Foreign, visibility, &$($mut)?*func);
try_visit!(vis.visit_fn(kind, span, id))
try_visit!(vis.visit_fn(kind, attrs, span, id))
}
ForeignItemKind::TyAlias(alias) =>
visit_visitable!($($mut)? vis, alias),
@ -999,7 +1004,7 @@ macro_rules! common_visitor_and_walkers {
}) => {
visit_visitable!($($mut)? vis, constness, movability, capture_clause);
let kind = FnKind::Closure(binder, coroutine_kind, fn_decl, body);
try_visit!(vis.visit_fn(kind, *span, *id));
try_visit!(vis.visit_fn(kind, attrs, *span, *id));
visit_visitable!($($mut)? vis, fn_decl_span, fn_arg_span);
}
ExprKind::Block(block, opt_label) =>

View file

@ -1771,8 +1771,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
let pat = self.lower_pat(pat);
let for_span =
self.mark_span_with_reason(DesugaringKind::ForLoop, self.lower_span(e.span), None);
let head_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
let pat_span = self.mark_span_with_reason(DesugaringKind::ForLoop, pat.span, None);
let for_ctxt = for_span.ctxt();
// Try to point both the head and pat spans to their position in the for loop
// rather than inside a macro.
let head_span =
head.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(head.span).with_ctxt(for_ctxt);
let pat_span =
pat.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(pat.span).with_ctxt(for_ctxt);
let loop_hir_id = self.lower_node_id(e.id);
let label = self.lower_label(opt_label, e.id, loop_hir_id);

View file

@ -68,6 +68,10 @@ ast_passes_c_variadic_bad_extern = `...` is not supported for `extern "{$abi}"`
.label = `extern "{$abi}"` because of this
.help = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
ast_passes_c_variadic_bad_naked_extern = `...` is not supported for `extern "{$abi}"` naked functions
.label = `extern "{$abi}"` because of this
.help = C-variadic function must have a compatible calling convention
ast_passes_c_variadic_must_be_unsafe =
functions with a C variable argument list must be unsafe
.suggestion = add the `unsafe` keyword to this definition

View file

@ -21,7 +21,7 @@ use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use itertools::{Either, Itertools};
use rustc_abi::{CanonAbi, ExternAbi, InterruptKind};
use rustc_abi::{CVariadicStatus, CanonAbi, ExternAbi, InterruptKind};
use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, walk_list};
use rustc_ast::*;
use rustc_ast_pretty::pprust::{self, State};
@ -35,6 +35,7 @@ use rustc_session::lint::builtin::{
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
PATTERNS_IN_FNS_WITHOUT_BODY,
};
use rustc_session::parse::feature_err;
use rustc_span::{Ident, Span, kw, sym};
use rustc_target::spec::{AbiMap, AbiMapping};
use thin_vec::thin_vec;
@ -661,7 +662,7 @@ impl<'a> AstValidator<'a> {
/// C-variadics must be:
/// - Non-const
/// - Either foreign, or free and `unsafe extern "C"` semantically
fn check_c_variadic_type(&self, fk: FnKind<'a>) {
fn check_c_variadic_type(&self, fk: FnKind<'a>, attrs: &'a AttrVec) {
// `...` is already rejected when it is not the final parameter.
let variadic_param = match fk.decl().inputs.last() {
Some(param) if matches!(param.ty.kind, TyKind::CVarArgs) => param,
@ -693,36 +694,92 @@ impl<'a> AstValidator<'a> {
match fn_ctxt {
FnCtxt::Foreign => return,
FnCtxt::Free | FnCtxt::Assoc(_) => match sig.header.ext {
Extern::Implicit(_) => {
if !matches!(sig.header.safety, Safety::Unsafe(_)) {
self.dcx().emit_err(errors::CVariadicMustBeUnsafe {
span: variadic_param.span,
unsafe_span: sig.safety_span(),
});
FnCtxt::Free | FnCtxt::Assoc(_) => {
match sig.header.ext {
Extern::Implicit(_) => {
if !matches!(sig.header.safety, Safety::Unsafe(_)) {
self.dcx().emit_err(errors::CVariadicMustBeUnsafe {
span: variadic_param.span,
unsafe_span: sig.safety_span(),
});
}
}
Extern::Explicit(StrLit { symbol_unescaped, .. }, _) => {
// Just bail if the ABI is not even recognized.
let Ok(abi) = ExternAbi::from_str(symbol_unescaped.as_str()) else {
return;
};
self.check_c_variadic_abi(abi, attrs, variadic_param.span, sig);
if !matches!(sig.header.safety, Safety::Unsafe(_)) {
self.dcx().emit_err(errors::CVariadicMustBeUnsafe {
span: variadic_param.span,
unsafe_span: sig.safety_span(),
});
}
}
Extern::None => {
let err = errors::CVariadicNoExtern { span: variadic_param.span };
self.dcx().emit_err(err);
}
}
Extern::Explicit(StrLit { symbol_unescaped, .. }, _) => {
if !matches!(symbol_unescaped, sym::C | sym::C_dash_unwind) {
self.dcx().emit_err(errors::CVariadicBadExtern {
span: variadic_param.span,
abi: symbol_unescaped,
extern_span: sig.extern_span(),
});
}
}
}
fn check_c_variadic_abi(
&self,
abi: ExternAbi,
attrs: &'a AttrVec,
dotdotdot_span: Span,
sig: &FnSig,
) {
// For naked functions we accept any ABI that is accepted on c-variadic
// foreign functions, if the c_variadic_naked_functions feature is enabled.
if attr::contains_name(attrs, sym::naked) {
match abi.supports_c_variadic() {
CVariadicStatus::Stable if let ExternAbi::C { .. } = abi => {
// With `c_variadic` naked c-variadic `extern "C"` functions are allowed.
}
CVariadicStatus::Stable => {
// For e.g. aapcs or sysv64 `c_variadic_naked_functions` must also be enabled.
if !self.features.enabled(sym::c_variadic_naked_functions) {
let msg = format!("Naked c-variadic `extern {abi}` functions are unstable");
feature_err(&self.sess, sym::c_variadic_naked_functions, sig.span, msg)
.emit();
}
}
CVariadicStatus::Unstable { feature } => {
// Some ABIs need additional features.
if !self.features.enabled(sym::c_variadic_naked_functions) {
let msg = format!("Naked c-variadic `extern {abi}` functions are unstable");
feature_err(&self.sess, sym::c_variadic_naked_functions, sig.span, msg)
.emit();
}
if !matches!(sig.header.safety, Safety::Unsafe(_)) {
self.dcx().emit_err(errors::CVariadicMustBeUnsafe {
span: variadic_param.span,
unsafe_span: sig.safety_span(),
});
if !self.features.enabled(feature) {
let msg = format!(
"C-variadic functions with the {abi} calling convention are unstable"
);
feature_err(&self.sess, feature, sig.span, msg).emit();
}
}
Extern::None => {
let err = errors::CVariadicNoExtern { span: variadic_param.span };
self.dcx().emit_err(err);
CVariadicStatus::NotSupported => {
// Some ABIs, e.g. `extern "Rust"`, never support c-variadic functions.
self.dcx().emit_err(errors::CVariadicBadNakedExtern {
span: dotdotdot_span,
abi: abi.as_str(),
extern_span: sig.extern_span(),
});
}
},
}
} else if !matches!(abi, ExternAbi::C { .. }) {
self.dcx().emit_err(errors::CVariadicBadExtern {
span: dotdotdot_span,
abi: abi.as_str(),
extern_span: sig.extern_span(),
});
}
}
@ -1106,7 +1163,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
let kind = FnKind::Fn(FnCtxt::Free, &item.vis, &*func);
self.visit_fn(kind, item.span, item.id);
self.visit_fn(kind, &item.attrs, item.span, item.id);
}
ItemKind::ForeignMod(ForeignMod { extern_span, abi, safety, .. }) => {
let old_item = mem::replace(&mut self.extern_mod_span, Some(item.span));
@ -1473,7 +1530,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
visit::walk_param_bound(self, bound)
}
fn visit_fn(&mut self, fk: FnKind<'a>, span: Span, id: NodeId) {
fn visit_fn(&mut self, fk: FnKind<'a>, attrs: &AttrVec, span: Span, id: NodeId) {
// Only associated `fn`s can have `self` parameters.
let self_semantic = match fk.ctxt() {
Some(FnCtxt::Assoc(_)) => SelfSemantic::Yes,
@ -1492,7 +1549,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.check_extern_fn_signature(abi, ctxt, &fun.ident, &fun.sig);
}
self.check_c_variadic_type(fk);
self.check_c_variadic_type(fk, attrs);
// Functions cannot both be `const async` or `const gen`
if let Some(&FnHeader {
@ -1643,7 +1700,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
{
self.visit_attrs_vis_ident(&item.attrs, &item.vis, &func.ident);
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), &item.vis, &*func);
self.visit_fn(kind, item.span, item.id);
self.visit_fn(kind, &item.attrs, item.span, item.id);
}
AssocItemKind::Type(_) => {
let disallowed = (!parent_is_const).then(|| match self.outer_trait_or_trait_impl {

View file

@ -347,7 +347,18 @@ pub(crate) struct CVariadicMustBeUnsafe {
pub(crate) struct CVariadicBadExtern {
#[primary_span]
pub span: Span,
pub abi: Symbol,
pub abi: &'static str,
#[label]
pub extern_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_bad_naked_extern)]
#[help]
pub(crate) struct CVariadicBadNakedExtern {
#[primary_span]
pub span: Span,
pub abi: &'static str,
#[label]
pub extern_span: Span,
}

View file

@ -1,6 +1,5 @@
use rustc_ast as ast;
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{NodeId, PatKind, attr, token};
use rustc_ast::{self as ast, AttrVec, NodeId, PatKind, attr, token};
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features};
use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_warn};
@ -392,7 +391,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_poly_trait_ref(self, t);
}
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
if let Some(_header) = fn_kind.header() {
// Stability of const fn methods are covered in `visit_assoc_item` below.
}

View file

@ -3087,6 +3087,39 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
});
explanation.add_explanation_to_diagnostic(&self, &mut err, "", Some(borrow_span), None);
// Detect buffer reuse pattern
if let BorrowExplanation::UsedLater(_dropped_local, _, _, _) = explanation {
// Check all locals at the borrow location to find Vec<&T> types
for (local, local_decl) in self.body.local_decls.iter_enumerated() {
if let ty::Adt(adt_def, args) = local_decl.ty.kind()
&& self.infcx.tcx.is_diagnostic_item(sym::Vec, adt_def.did())
&& args.len() > 0
{
let vec_inner_ty = args.type_at(0);
// Check if Vec contains references
if vec_inner_ty.is_ref() {
let local_place = local.into();
if let Some(local_name) = self.describe_place(local_place) {
err.span_label(
local_decl.source_info.span,
format!("variable `{local_name}` declared here"),
);
err.note(
format!(
"`{local_name}` is a collection that stores borrowed references, \
but {name} does not live long enough to be stored in it"
)
);
err.help(
"buffer reuse with borrowed references requires unsafe code or restructuring"
);
break;
}
}
}
}
}
}
err

View file

@ -49,7 +49,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::Session;
use rustc_session::config::OutputFilenames;
use rustc_span::{Symbol, sym};
use rustc_target::spec::Arch;
use rustc_target::spec::{Abi, Arch, Env, Os};
pub use crate::config::*;
use crate::prelude::*;
@ -163,15 +163,15 @@ impl CodegenBackend for CraneliftCodegenBackend {
fn target_config(&self, sess: &Session) -> TargetConfig {
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
let target_features = match sess.target.arch {
Arch::X86_64 if sess.target.os != "none" => {
Arch::X86_64 if sess.target.os != Os::None => {
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
vec![sym::fxsr, sym::sse, sym::sse2, Symbol::intern("x87")]
}
Arch::AArch64 => match &*sess.target.os {
"none" => vec![],
Arch::AArch64 => match &sess.target.os {
Os::None => vec![],
// On macOS the aes, sha2 and sha3 features are enabled by default and ring
// fails to compile on macOS when they are not present.
"macos" => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
Os::MacOs => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
// AArch64 mandates Neon support
_ => vec![sym::neon],
},
@ -184,9 +184,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
// targets due to GCC using a different ABI than LLVM. Therefore `f16` and `f128`
// won't be available when using a LLVM-built sysroot.
let has_reliable_f16_f128 = !(sess.target.arch == Arch::X86_64
&& sess.target.os == "windows"
&& sess.target.env == "gnu"
&& sess.target.abi != "llvm");
&& sess.target.os == Os::Windows
&& sess.target.env == Env::Gnu
&& sess.target.abi != Abi::Llvm);
TargetConfig {
target_features,

View file

@ -7,7 +7,7 @@
use rustc_codegen_ssa::common;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv};
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
use rustc_target::spec::Arch;
use rustc_target::spec::{Arch, Env};
use tracing::debug;
use crate::context::CodegenCx;
@ -145,7 +145,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
if cx.use_dll_storage_attrs
&& let Some(library) = tcx.native_library(instance_def_id)
&& library.kind.is_dllimport()
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
&& !matches!(tcx.sess.target.env, Env::Gnu | Env::Uclibc)
{
llvm::set_dllimport_storage_class(llfn);
}

View file

@ -29,7 +29,7 @@ use rustc_span::source_map::Spanned;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::{
Arch, HasTargetSpec, RelocModel, SmallDataThresholdSupport, Target, TlsModel,
Abi, Arch, Env, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel,
};
use smallvec::SmallVec;
@ -335,9 +335,9 @@ pub(crate) unsafe fn create_module<'ll>(
// Control Flow Guard is currently only supported by MSVC and LLVM on Windows.
if sess.target.is_like_msvc
|| (sess.target.options.os == "windows"
&& sess.target.options.env == "gnu"
&& sess.target.options.abi == "llvm")
|| (sess.target.options.os == Os::Windows
&& sess.target.options.env == Env::Gnu
&& sess.target.options.abi == Abi::Llvm)
{
match sess.opts.cg.control_flow_guard {
CFGuard::Disabled => {}
@ -669,7 +669,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
/// This corresponds to the `-fobjc-abi-version=` flag in Clang / GCC.
pub(crate) fn objc_abi_version(&self) -> u32 {
assert!(self.tcx.sess.target.is_like_darwin);
if self.tcx.sess.target.arch == Arch::X86 && self.tcx.sess.target.os == "macos" {
if self.tcx.sess.target.arch == Arch::X86 && self.tcx.sess.target.os == Os::MacOs {
// 32-bit x86 macOS uses ABI version 1 (a.k.a. the "fragile ABI").
1
} else {
@ -710,7 +710,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
},
);
if self.tcx.sess.target.env == "sim" {
if self.tcx.sess.target.env == Env::Sim {
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Error,
@ -963,7 +963,7 @@ impl<'ll> CodegenCx<'ll, '_> {
return eh_catch_typeinfo;
}
let tcx = self.tcx;
assert!(self.sess().target.os == "emscripten");
assert!(self.sess().target.os == Os::Emscripten);
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
Some(def_id) => self.get_static(def_id),
_ => {

View file

@ -18,6 +18,7 @@ use rustc_middle::{bug, span_bug};
use rustc_span::{Span, Symbol, sym};
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
use rustc_target::callconv::PassMode;
use rustc_target::spec::Os;
use tracing::debug;
use crate::abi::FnAbiLlvmExt;
@ -681,7 +682,7 @@ fn catch_unwind_intrinsic<'ll, 'tcx>(
codegen_msvc_try(bx, try_func, data, catch_func, dest);
} else if wants_wasm_eh(bx.sess()) {
codegen_wasm_try(bx, try_func, data, catch_func, dest);
} else if bx.sess().target.os == "emscripten" {
} else if bx.sess().target.os == Os::Emscripten {
codegen_emcc_try(bx, try_func, data, catch_func, dest);
} else {
codegen_gnu_try(bx, try_func, data, catch_func, dest);

View file

@ -15,7 +15,9 @@ use rustc_fs_util::path_to_c_string;
use rustc_middle::bug;
use rustc_session::Session;
use rustc_session::config::{PrintKind, PrintRequest};
use rustc_target::spec::{Arch, MergeFunctions, PanicStrategy, SmallDataThresholdSupport};
use rustc_target::spec::{
Abi, Arch, Env, MergeFunctions, Os, PanicStrategy, SmallDataThresholdSupport,
};
use smallvec::{SmallVec, smallvec};
use crate::back::write::create_informational_target_machine;
@ -104,7 +106,7 @@ unsafe fn configure_llvm(sess: &Session) {
add("-wasm-enable-eh", false);
}
if sess.target.os == "emscripten"
if sess.target.os == Os::Emscripten
&& !sess.opts.unstable_opts.emscripten_wasm_eh
&& sess.panic_strategy().unwinds()
{
@ -351,9 +353,9 @@ pub(crate) fn target_config(sess: &Session) -> TargetConfig {
/// Determine whether or not experimental float types are reliable based on known bugs.
fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
let target_arch = &sess.target.arch;
let target_os = sess.target.options.os.as_ref();
let target_env = sess.target.options.env.as_ref();
let target_abi = sess.target.options.abi.as_ref();
let target_os = &sess.target.options.os;
let target_env = &sess.target.options.env;
let target_abi = &sess.target.options.abi;
let target_pointer_width = sess.target.pointer_width;
let version = get_version();
let lt_20_1_1 = version < (20, 1, 1);
@ -371,7 +373,7 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
// Selection failure <https://github.com/llvm/llvm-project/issues/50374> (fixed in llvm21)
(Arch::S390x, _) if lt_21_0_0 => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
(Arch::X86_64, "windows") if target_env == "gnu" && target_abi != "llvm" => false,
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
(Arch::CSky, _) => false,
(Arch::Hexagon, _) if lt_21_0_0 => false, // (fixed in llvm21)
@ -403,7 +405,7 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
// not fail if our compiler-builtins is linked. (fixed in llvm21)
(Arch::X86, _) if lt_21_0_0 => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
(Arch::X86_64, "windows") if target_env == "gnu" && target_abi != "llvm" => false,
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
// There are no known problems on other platforms, so the only requirement is that symbols
// are available. `compiler-builtins` provides all symbols required for core `f128`
// support, so this should work for everything else.
@ -424,9 +426,9 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
// (ld is 80-bit extended precision).
//
// musl does not implement the symbols required for f128 math at all.
_ if target_env == "musl" => false,
_ if *target_env == Env::Musl => false,
(Arch::X86_64, _) => false,
(_, "linux") if target_pointer_width == 64 => true,
(_, Os::Linux) if target_pointer_width == 64 => true,
_ => false,
} && cfg.has_reliable_f128;
}

View file

@ -7,7 +7,7 @@ use rustc_codegen_ssa::traits::{
};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
use rustc_target::spec::Arch;
use rustc_target::spec::{Abi, Arch};
use crate::builder::Builder;
use crate::llvm::{Type, Value};
@ -270,7 +270,7 @@ fn emit_powerpc_va_arg<'ll, 'tcx>(
// Rust does not currently support any powerpc softfloat targets.
let target = &bx.cx.tcx.sess.target;
let is_soft_float_abi = target.abi == "softfloat";
let is_soft_float_abi = target.abi == Abi::SoftFloat;
assert!(!is_soft_float_abi);
// All instances of VaArgSafe are passed directly.

View file

@ -6,7 +6,7 @@ use itertools::Itertools;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
use rustc_session::Session;
pub(super) use rustc_target::spec::apple::OSVersion;
use rustc_target::spec::{Arch, Target};
use rustc_target::spec::{Arch, Env, Os, Target};
use tracing::debug;
use crate::errors::{XcrunError, XcrunSdkPathWarning};
@ -17,35 +17,35 @@ mod tests;
/// The canonical name of the desired SDK for a given target.
pub(super) fn sdk_name(target: &Target) -> &'static str {
match (&*target.os, &*target.env) {
("macos", "") => "MacOSX",
("ios", "") => "iPhoneOS",
("ios", "sim") => "iPhoneSimulator",
match (&target.os, &target.env) {
(Os::MacOs, Env::Unspecified) => "MacOSX",
(Os::IOs, Env::Unspecified) => "iPhoneOS",
(Os::IOs, Env::Sim) => "iPhoneSimulator",
// Mac Catalyst uses the macOS SDK
("ios", "macabi") => "MacOSX",
("tvos", "") => "AppleTVOS",
("tvos", "sim") => "AppleTVSimulator",
("visionos", "") => "XROS",
("visionos", "sim") => "XRSimulator",
("watchos", "") => "WatchOS",
("watchos", "sim") => "WatchSimulator",
(Os::IOs, Env::MacAbi) => "MacOSX",
(Os::TvOs, Env::Unspecified) => "AppleTVOS",
(Os::TvOs, Env::Sim) => "AppleTVSimulator",
(Os::VisionOs, Env::Unspecified) => "XROS",
(Os::VisionOs, Env::Sim) => "XRSimulator",
(Os::WatchOs, Env::Unspecified) => "WatchOS",
(Os::WatchOs, Env::Sim) => "WatchSimulator",
(os, abi) => unreachable!("invalid os '{os}' / abi '{abi}' combination for Apple target"),
}
}
pub(super) fn macho_platform(target: &Target) -> u32 {
match (&*target.os, &*target.env) {
("macos", _) => object::macho::PLATFORM_MACOS,
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,
("ios", _) => object::macho::PLATFORM_IOS,
("watchos", "sim") => object::macho::PLATFORM_WATCHOSSIMULATOR,
("watchos", _) => object::macho::PLATFORM_WATCHOS,
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
("tvos", _) => object::macho::PLATFORM_TVOS,
("visionos", "sim") => object::macho::PLATFORM_XROSSIMULATOR,
("visionos", _) => object::macho::PLATFORM_XROS,
_ => unreachable!("tried to get Mach-O platform for non-Apple target"),
match (&target.os, &target.env) {
(Os::MacOs, _) => object::macho::PLATFORM_MACOS,
(Os::IOs, Env::MacAbi) => object::macho::PLATFORM_MACCATALYST,
(Os::IOs, Env::Sim) => object::macho::PLATFORM_IOSSIMULATOR,
(Os::IOs, _) => object::macho::PLATFORM_IOS,
(Os::WatchOs, Env::Sim) => object::macho::PLATFORM_WATCHOSSIMULATOR,
(Os::WatchOs, _) => object::macho::PLATFORM_WATCHOS,
(Os::TvOs, Env::Sim) => object::macho::PLATFORM_TVOSSIMULATOR,
(Os::TvOs, _) => object::macho::PLATFORM_TVOS,
(Os::VisionOs, Env::Sim) => object::macho::PLATFORM_XROSSIMULATOR,
(Os::VisionOs, _) => object::macho::PLATFORM_XROS,
(os, env) => unreachable!("invalid os '{os}' / env '{env}' combination for Apple target"),
}
}

View file

@ -46,9 +46,9 @@ use rustc_session::{Session, filesearch};
use rustc_span::Symbol;
use rustc_target::spec::crt_objects::CrtObjects;
use rustc_target::spec::{
BinaryFormat, Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault,
LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, RelocModel, RelroLevel, SanitizerSet,
SplitDebuginfo,
Abi, BinaryFormat, Cc, Env, LinkOutputKind, LinkSelfContainedComponents,
LinkSelfContainedDefault, LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, Os, RelocModel,
RelroLevel, SanitizerSet, SplitDebuginfo,
};
use tracing::{debug, info, warn};
@ -1407,11 +1407,9 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
Some(LinkerFlavorCli::Llbc) => Some(LinkerFlavor::Llbc),
Some(LinkerFlavorCli::Ptx) => Some(LinkerFlavor::Ptx),
// The linker flavors that corresponds to targets needs logic that keeps the base LinkerFlavor
_ => sess
.opts
.cg
.linker_flavor
.map(|flavor| sess.target.linker_flavor.with_cli_hints(flavor)),
linker_flavor => {
linker_flavor.map(|flavor| sess.target.linker_flavor.with_cli_hints(flavor))
}
};
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), linker_flavor, features) {
return ret;
@ -1819,7 +1817,7 @@ fn self_contained_components(
LinkSelfContainedDefault::InferredForMusl => sess.crt_static(Some(crate_type)),
LinkSelfContainedDefault::InferredForMingw => {
sess.host == sess.target
&& sess.target.abi != "uwp"
&& sess.target.abi != Abi::Uwp
&& detect_self_contained_mingw(sess, linker)
}
}
@ -1845,7 +1843,7 @@ fn add_pre_link_objects(
let empty = Default::default();
let objects = if self_contained {
&opts.pre_link_objects_self_contained
} else if !(sess.target.os == "fuchsia" && matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))) {
} else if !(sess.target.os == Os::Fuchsia && matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))) {
&opts.pre_link_objects
} else {
&empty
@ -2496,7 +2494,7 @@ fn add_order_independent_options(
let apple_sdk_root = add_apple_sdk(cmd, sess, flavor);
if sess.target.os == "fuchsia"
if sess.target.os == Os::Fuchsia
&& crate_type == CrateType::Executable
&& !matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))
{
@ -2515,7 +2513,7 @@ fn add_order_independent_options(
cmd.no_crt_objects();
}
if sess.target.os == "emscripten" {
if sess.target.os == Os::Emscripten {
cmd.cc_arg(if sess.opts.unstable_opts.emscripten_wasm_eh {
"-fwasm-exceptions"
} else if sess.panic_strategy().unwinds() {
@ -3070,8 +3068,8 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
// `sess.target.arch` (`target_arch`) is not detailed enough.
let llvm_arch = sess.target.llvm_target.split_once('-').expect("LLVM target must have arch").0;
let target_os = &*sess.target.os;
let target_env = &*sess.target.env;
let target_os = &sess.target.os;
let target_env = &sess.target.env;
// The architecture name to forward to the linker.
//
@ -3123,12 +3121,12 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
// > - xros-simulator
// > - driverkit
let platform_name = match (target_os, target_env) {
(os, "") => os,
("ios", "macabi") => "mac-catalyst",
("ios", "sim") => "ios-simulator",
("tvos", "sim") => "tvos-simulator",
("watchos", "sim") => "watchos-simulator",
("visionos", "sim") => "visionos-simulator",
(os, Env::Unspecified) => os.desc(),
(Os::IOs, Env::MacAbi) => "mac-catalyst",
(Os::IOs, Env::Sim) => "ios-simulator",
(Os::TvOs, Env::Sim) => "tvos-simulator",
(Os::WatchOs, Env::Sim) => "watchos-simulator",
(Os::VisionOs, Env::Sim) => "visionos-simulator",
_ => bug!("invalid OS/env combination for Apple target: {target_os}, {target_env}"),
};
@ -3192,7 +3190,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
// fairly safely use `-target`. See also the following, where it is
// made explicit that the recommendation by LLVM developers is to use
// `-target`: <https://github.com/llvm/llvm-project/issues/88271>
if target_os == "macos" {
if *target_os == Os::MacOs {
// `-arch` communicates the architecture.
//
// CC forwards the `-arch` to the linker, so we use the same value

View file

@ -17,7 +17,7 @@ use rustc_middle::middle::exported_symbols::{
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
use rustc_target::spec::{Arch, Cc, LinkOutputKind, LinkerFlavor, Lld};
use rustc_target::spec::{Abi, Arch, Cc, LinkOutputKind, LinkerFlavor, Lld, Os};
use tracing::{debug, warn};
use super::command::Command;
@ -83,7 +83,7 @@ pub(crate) fn get_linker<'a>(
// To comply with the Windows App Certification Kit,
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
let t = &sess.target;
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.abi == "uwp" {
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.abi == Abi::Uwp {
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
@ -134,12 +134,12 @@ pub(crate) fn get_linker<'a>(
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
// to the linker args construction.
assert!(cmd.get_args().is_empty() || sess.target.abi == "uwp");
assert!(cmd.get_args().is_empty() || sess.target.abi == Abi::Uwp);
match flavor {
LinkerFlavor::Unix(Cc::No) if sess.target.os == "l4re" => {
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::L4Re => {
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
}
LinkerFlavor::Unix(Cc::No) if sess.target.os == "aix" => {
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::Aix => {
Box::new(AixLinker::new(cmd, sess)) as Box<dyn Linker>
}
LinkerFlavor::WasmLld(Cc::No) => Box::new(WasmLd::new(cmd, sess)) as Box<dyn Linker>,
@ -573,7 +573,7 @@ impl<'a> Linker for GccLinker<'a> {
// any `#[link]` attributes in the `libc` crate, see #72782 for details.
// FIXME: Switch to using `#[link]` attributes in the `libc` crate
// similarly to other targets.
if self.sess.target.os == "vxworks"
if self.sess.target.os == Os::VxWorks
&& matches!(
output_kind,
LinkOutputKind::StaticNoPicExe
@ -595,7 +595,7 @@ impl<'a> Linker for GccLinker<'a> {
}
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, as_needed: bool) {
if self.sess.target.os == "illumos" && name == "c" {
if self.sess.target.os == Os::Illumos && name == "c" {
// libc will be added via late_link_args on illumos so that it will
// appear last in the library search order.
// FIXME: This should be replaced by a more complete and generic
@ -1439,7 +1439,7 @@ impl<'a> Linker for WasmLd<'a> {
// symbols explicitly passed via the `--export` flags above and hides all
// others. Various bits and pieces of wasm32-unknown-unknown tooling use
// this, so be sure these symbols make their way out of the linker as well.
if self.sess.target.os == "unknown" || self.sess.target.os == "none" {
if matches!(self.sess.target.os, Os::Unknown | Os::None) {
self.link_args(&["--export=__heap_base", "--export=__data_end"]);
}
}

View file

@ -20,7 +20,7 @@ use rustc_metadata::fs::METADATA_FILENAME;
use rustc_middle::bug;
use rustc_session::Session;
use rustc_span::sym;
use rustc_target::spec::{RelocModel, Target, ef_avr_arch};
use rustc_target::spec::{Abi, Os, RelocModel, Target, ef_avr_arch};
use tracing::debug;
use super::apple;
@ -260,10 +260,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
}
pub(super) fn elf_os_abi(sess: &Session) -> u8 {
match sess.target.options.os.as_ref() {
"hermit" => elf::ELFOSABI_STANDALONE,
"freebsd" => elf::ELFOSABI_FREEBSD,
"solaris" => elf::ELFOSABI_SOLARIS,
match sess.target.options.os {
Os::Hermit => elf::ELFOSABI_STANDALONE,
Os::FreeBsd => elf::ELFOSABI_FREEBSD,
Os::Solaris => elf::ELFOSABI_SOLARIS,
_ => elf::ELFOSABI_NONE,
}
}
@ -379,11 +379,11 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
}
}
Architecture::Csky => {
let e_flags = match sess.target.options.abi.as_ref() {
"abiv2" => elf::EF_CSKY_ABIV2,
_ => elf::EF_CSKY_ABIV1,
};
e_flags
if matches!(sess.target.options.abi, Abi::AbiV2) {
elf::EF_CSKY_ABIV2
} else {
elf::EF_CSKY_ABIV1
}
}
Architecture::PowerPc64 => {
const EF_PPC64_ABI_UNKNOWN: u32 = 0;

View file

@ -17,7 +17,7 @@ use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolNam
use rustc_middle::util::Providers;
use rustc_session::config::{CrateType, OomStrategy};
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::{Arch, TlsModel};
use rustc_target::spec::{Arch, Os, TlsModel};
use tracing::debug;
use crate::back::symbol_export;
@ -711,7 +711,7 @@ pub(crate) fn extend_exported_symbols<'tcx>(
) {
let (callconv, _) = calling_convention_for_symbol(tcx, symbol);
if callconv != CanonAbi::GpuKernel || tcx.sess.target.os != "amdhsa" {
if callconv != CanonAbi::GpuKernel || tcx.sess.target.os != Os::AmdHsa {
return;
}

View file

@ -33,7 +33,7 @@ use rustc_session::Session;
use rustc_session::config::{self, CrateType, EntryFnType};
use rustc_span::{DUMMY_SP, Symbol, sym};
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::Arch;
use rustc_target::spec::{Arch, Os};
use rustc_trait_selection::infer::{BoundRegionConversionTime, TyCtxtInferExt};
use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
use tracing::{debug, info};
@ -366,7 +366,7 @@ pub(crate) fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// us
pub fn wants_wasm_eh(sess: &Session) -> bool {
sess.target.is_like_wasm
&& (sess.target.os != "emscripten" || sess.opts.unstable_opts.emscripten_wasm_eh)
&& (sess.target.os != Os::Emscripten || sess.opts.unstable_opts.emscripten_wasm_eh)
}
/// Returns `true` if this session's target will use SEH-based unwinding.
@ -500,7 +500,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
) -> Bx::Function {
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or
// `usize efi_main(void *handle, void *system_table)` depending on the target.
let llfty = if cx.sess().target.os.contains("uefi") {
let llfty = if cx.sess().target.os == Os::Uefi {
cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize())
} else if cx.sess().target.main_needs_argc_argv {
cx.type_func(&[cx.type_int(), cx.type_ptr()], cx.type_int())
@ -562,7 +562,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
};
let result = bx.call(start_ty, None, None, start_fn, &args, None, instance);
if cx.sess().target.os.contains("uefi") {
if cx.sess().target.os == Os::Uefi {
bx.ret(result);
} else {
let cast = bx.intcast(result, cx.type_int(), true);
@ -576,7 +576,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
/// Obtain the `argc` and `argv` values to pass to the rust start function
/// (i.e., the "start" lang item).
fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(bx: &mut Bx) -> (Bx::Value, Bx::Value) {
if bx.cx().sess().target.os.contains("uefi") {
if bx.cx().sess().target.os == Os::Uefi {
// Params for UEFI
let param_handle = bx.get_param(0);
let param_system_table = bx.get_param(1);

View file

@ -16,6 +16,7 @@ use rustc_middle::ty::{self as ty, TyCtxt};
use rustc_session::lint;
use rustc_session::parse::feature_err;
use rustc_span::{Ident, Span, sym};
use rustc_target::spec::Os;
use crate::errors;
use crate::target_features::{
@ -258,7 +259,7 @@ fn process_builtin_attrs(
UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
UsedBy::Default => {
let used_form = if tcx.sess.target.os == "illumos" {
let used_form = if tcx.sess.target.os == Os::Illumos {
// illumos' `ld` doesn't support a section header that would represent
// `#[used(linker)]`, see
// https://github.com/rust-lang/rust/issues/146169. For that target,

View file

@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Instance, TyCtxt};
use rustc_middle::{bug, mir, span_bug};
use rustc_session::cstore::{DllCallingConvention, DllImport};
use rustc_span::Span;
use rustc_target::spec::Target;
use rustc_target::spec::{Abi, Env, Os, Target};
use crate::traits::*;
@ -171,7 +171,7 @@ pub fn asm_const_to_str<'tcx>(
}
pub fn is_mingw_gnu_toolchain(target: &Target) -> bool {
target.os == "windows" && target.env == "gnu" && target.abi.is_empty()
target.os == Os::Windows && target.env == Env::Gnu && target.abi == Abi::Unspecified
}
pub fn i686_decorated_name(

View file

@ -3466,14 +3466,9 @@ impl Drop for Buffy {
pub fn stderr_destination(color: ColorConfig) -> Destination {
let buffer_writer = std::io::stderr();
let choice = color.to_color_choice();
// We need to resolve `ColorChoice::Auto` before `Box`ing since
// `ColorChoice::Auto` on `dyn Write` will always resolve to `Never`
let choice = if matches!(choice, ColorChoice::Auto) {
AutoStream::choice(&buffer_writer)
} else {
choice
};
let choice = get_stderr_color_choice(color, &buffer_writer);
// On Windows we'll be performing global synchronization on the entire
// system for emitting rustc errors, so there's no need to buffer
// anything.
@ -3488,6 +3483,11 @@ pub fn stderr_destination(color: ColorConfig) -> Destination {
}
}
pub fn get_stderr_color_choice(color: ColorConfig, stderr: &std::io::Stderr) -> ColorChoice {
let choice = color.to_color_choice();
if matches!(choice, ColorChoice::Auto) { AutoStream::choice(stderr) } else { choice }
}
/// On Windows, BRIGHT_BLUE is hard to read on black. Use cyan instead.
///
/// See #36178.

View file

@ -410,6 +410,9 @@ declare_features! (
(unstable, avx10_target_feature, "1.88.0", Some(138843)),
/// Allows using C-variadics.
(unstable, c_variadic, "1.34.0", Some(44930)),
/// Allows defining c-variadic naked functions with any extern ABI that is allowed
/// on c-variadic foreign functions.
(unstable, c_variadic_naked_functions, "CURRENT_RUSTC_VERSION", Some(148767)),
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
(unstable, cfg_contract_checks, "1.86.0", Some(128044)),
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.

View file

@ -1079,6 +1079,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
self.note_derefed_ty_has_method(&mut err, source, rcvr_ty, item_ident, expected);
self.suggest_bounds_for_range_to_method(&mut err, source, item_ident);
err.emit()
}
@ -3260,6 +3261,71 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
fn suggest_bounds_for_range_to_method(
&self,
err: &mut Diag<'_>,
source: SelfSource<'tcx>,
item_ident: Ident,
) {
let SelfSource::MethodCall(rcvr_expr) = source else { return };
let hir::ExprKind::Struct(qpath, fields, _) = rcvr_expr.kind else { return };
let Some(lang_item) = self.tcx.qpath_lang_item(*qpath) else {
return;
};
let is_inclusive = match lang_item {
hir::LangItem::RangeTo => false,
hir::LangItem::RangeToInclusive | hir::LangItem::RangeInclusiveCopy => true,
_ => return,
};
let Some(iterator_trait) = self.tcx.get_diagnostic_item(sym::Iterator) else { return };
let Some(_) = self
.tcx
.associated_items(iterator_trait)
.filter_by_name_unhygienic(item_ident.name)
.next()
else {
return;
};
let source_map = self.tcx.sess.source_map();
let range_type = if is_inclusive { "RangeInclusive" } else { "Range" };
let Some(end_field) = fields.iter().find(|f| f.ident.name == rustc_span::sym::end) else {
return;
};
let element_ty = self.typeck_results.borrow().expr_ty_opt(end_field.expr);
let is_integral = element_ty.is_some_and(|ty| ty.is_integral());
let end_is_negative = is_integral
&& matches!(end_field.expr.kind, hir::ExprKind::Unary(rustc_ast::UnOp::Neg, _));
let Ok(snippet) = source_map.span_to_snippet(rcvr_expr.span) else { return };
let offset = snippet
.chars()
.take_while(|&c| c == '(' || c.is_whitespace())
.map(|c| c.len_utf8())
.sum::<usize>();
let insert_span = rcvr_expr
.span
.with_lo(rcvr_expr.span.lo() + rustc_span::BytePos(offset as u32))
.shrink_to_lo();
let (value, appl) = if is_integral && !end_is_negative {
("0", Applicability::MachineApplicable)
} else {
("/* start */", Applicability::HasPlaceholders)
};
err.span_suggestion_verbose(
insert_span,
format!("consider using a bounded `{range_type}` by adding a concrete starting value"),
value,
appl,
);
}
/// Print out the type for use in value namespace.
fn ty_to_value_string(&self, ty: Ty<'tcx>) -> String {
match ty.kind() {

View file

@ -5,7 +5,7 @@
//! syntactical lints.
use rustc_ast::visit::{self as ast_visit, Visitor, walk_list};
use rustc_ast::{self as ast, HasAttrs};
use rustc_ast::{self as ast, AttrVec, HasAttrs};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
use rustc_feature::Features;
@ -135,7 +135,7 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
});
}
fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, span: Span, id: ast::NodeId) {
fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, _: &AttrVec, span: Span, id: ast::NodeId) {
lint_callback!(self, check_fn, fk, span, id);
ast_visit::walk_fn(self, fk);
}

View file

@ -16,6 +16,7 @@ use rustc_middle::ty::{
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::def_id::LocalDefId;
use rustc_span::{Span, sym};
use rustc_target::spec::Os;
use tracing::debug;
use super::repr_nullable_ptr;
@ -177,7 +178,7 @@ fn variant_has_complex_ctor(variant: &ty::VariantDef) -> bool {
/// the Power alignment Rule (see the `check_struct_for_power_alignment` function).
fn check_arg_for_power_alignment<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
let tcx = cx.tcx;
assert!(tcx.sess.target.os == "aix");
assert!(tcx.sess.target.os == Os::Aix);
// Structs (under repr(C)) follow the power alignment rule if:
// - the first field of the struct is a floating-point type that
// is greater than 4-bytes, or
@ -222,7 +223,7 @@ fn check_struct_for_power_alignment<'tcx>(
let tcx = cx.tcx;
// Only consider structs (not enums or unions) on AIX.
if tcx.sess.target.os != "aix" || !adt_def.is_struct() {
if tcx.sess.target.os != Os::Aix || !adt_def.is_struct() {
return;
}

View file

@ -15,7 +15,7 @@ use rustc_session::cstore::{DllCallingConvention, DllImport, ForeignModule, Nati
use rustc_session::search_paths::PathKind;
use rustc_span::Symbol;
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_target::spec::{Arch, BinaryFormat, LinkSelfContainedComponents};
use rustc_target::spec::{Abi, Arch, BinaryFormat, Env, LinkSelfContainedComponents, Os};
use crate::errors;
@ -67,9 +67,9 @@ pub fn walk_native_lib_search_dirs<R>(
// FIXME: On AIX this also has the side-effect of making the list of library search paths
// non-empty, which is needed or the linker may decide to record the LIBPATH env, if
// defined, as the search path instead of appending the default search paths.
if sess.target.abi == "fortanix"
|| sess.target.os == "linux"
|| sess.target.os == "fuchsia"
if sess.target.abi == Abi::Fortanix
|| sess.target.os == Os::Linux
|| sess.target.os == Os::Fuchsia
|| sess.target.is_like_aix
|| sess.target.is_like_darwin && !sess.sanitizers().is_empty()
{
@ -79,7 +79,7 @@ pub fn walk_native_lib_search_dirs<R>(
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
// we must have the support library stubs in the library search path (#121430).
if let Some(sdk_root) = apple_sdk_root
&& sess.target.env == "macabi"
&& sess.target.env == Env::MacAbi
{
f(&sdk_root.join("System/iOSSupport/usr/lib"), false)?;
f(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"), true)?;

View file

@ -3,7 +3,7 @@
// completely accurate (some things might be counted twice, others missed).
use rustc_ast::visit::BoundKind;
use rustc_ast::{self as ast, NodeId, visit as ast_visit};
use rustc_ast::{self as ast, AttrVec, NodeId, visit as ast_visit};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::thousands::usize_with_underscores;
use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit};
@ -709,7 +709,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
ast_visit::walk_where_predicate(self, p)
}
fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, _: Span, _: NodeId) {
fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, _: &AttrVec, _: Span, _: NodeId) {
self.record("FnDecl", None, fk.decl());
ast_visit::walk_fn(self, fk)
}

View file

@ -8,6 +8,7 @@ use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
use rustc_middle::middle::lang_items::required;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::CrateType;
use rustc_target::spec::Os;
use crate::errors::{
MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd, UnknownExternLangItem,
@ -26,7 +27,7 @@ pub(crate) fn check_crate(
if items.eh_personality().is_none() {
items.missing.push(LangItem::EhPersonality);
}
if tcx.sess.target.os == "emscripten"
if tcx.sess.target.os == Os::Emscripten
&& items.eh_catch_typeinfo().is_none()
&& !tcx.sess.opts.unstable_opts.emscripten_wasm_eh
{

View file

@ -1358,7 +1358,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
// Visit attributes after items for backward compatibility.
// This way they can use `macro_rules` defined later.
self.visit_vis(&item.vis);
item.kind.walk(item.span, item.id, &item.vis, (), self);
item.kind.walk(&item.attrs, item.span, item.id, &item.vis, (), self);
visit::walk_list!(self, visit_attribute, &item.attrs);
}
_ => visit::walk_item(self, item),

View file

@ -193,7 +193,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
});
}
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
match fn_kind {
FnKind::Fn(
_ctxt,

View file

@ -1034,7 +1034,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
}
}
}
fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, fn_id: NodeId) {
fn visit_fn(&mut self, fn_kind: FnKind<'ast>, _: &AttrVec, sp: Span, fn_id: NodeId) {
let previous_value = self.diag_metadata.current_function;
match fn_kind {
// Bail if the function is foreign, and thus cannot validly have

View file

@ -239,10 +239,10 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
ins_none!(sym::sanitizer_cfi_normalize_integers);
}
ins_str!(sym::target_abi, &sess.target.abi);
ins_sym!(sym::target_abi, sess.target.abi.desc_symbol());
ins_sym!(sym::target_arch, sess.target.arch.desc_symbol());
ins_str!(sym::target_endian, sess.target.endian.as_str());
ins_str!(sym::target_env, &sess.target.env);
ins_sym!(sym::target_env, sess.target.env.desc_symbol());
for family in sess.target.families.as_ref() {
ins_str!(sym::target_family, family);
@ -291,7 +291,7 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
}
}
ins_str!(sym::target_os, &sess.target.os);
ins_sym!(sym::target_os, sess.target.os.desc_symbol());
ins_sym!(sym::target_pointer_width, sym::integer(sess.target.pointer_width));
if sess.opts.unstable_opts.has_thread_local.unwrap_or(sess.target.has_thread_local) {
@ -447,14 +447,14 @@ impl CheckCfg {
};
for target in Target::builtins().chain(iter::once(current_target.clone())) {
values_target_abi.insert(Symbol::intern(&target.options.abi));
values_target_abi.insert(target.options.abi.desc_symbol());
values_target_arch.insert(target.arch.desc_symbol());
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));
values_target_env.insert(Symbol::intern(&target.options.env));
values_target_env.insert(target.options.env.desc_symbol());
values_target_family.extend(
target.options.families.iter().map(|family| Symbol::intern(family)),
);
values_target_os.insert(Symbol::intern(&target.options.os));
values_target_os.insert(target.options.os.desc_symbol());
values_target_pointer_width.insert(sym::integer(target.pointer_width));
values_target_vendor.insert(target.vendor_symbol());
}

View file

@ -32,7 +32,7 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::{FileNameDisplayPreference, RealFileName, Span, Symbol};
use rustc_target::asm::InlineAsmArch;
use rustc_target::spec::{
Arch, CodeModel, DebuginfoKind, PanicStrategy, RelocModel, RelroLevel, SanitizerSet,
Arch, CodeModel, DebuginfoKind, Os, PanicStrategy, RelocModel, RelroLevel, SanitizerSet,
SmallDataThresholdSupport, SplitDebuginfo, StackProtector, SymbolVisibility, Target,
TargetTuple, TlsModel, apple,
};
@ -382,7 +382,7 @@ impl Session {
}
pub fn is_wasi_reactor(&self) -> bool {
self.target.options.os == "wasi"
self.target.options.os == Os::Wasi
&& matches!(
self.opts.unstable_opts.wasi_exec_model,
Some(config::WasiExecModel::Reactor)

View file

@ -612,6 +612,7 @@ symbols! {
c_str_literals,
c_unwind,
c_variadic,
c_variadic_naked_functions,
c_void,
call,
call_mut,

View file

@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_span::{Symbol, sym};
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
use crate::spec::{RelocModel, Target};
use crate::spec::{Env, Os, RelocModel, Target};
def_reg_class! {
AArch64 AArch64InlineAsmRegClass {
@ -75,9 +75,9 @@ pub(crate) fn target_reserves_x18(target: &Target, target_features: &FxIndexSet<
// See isX18ReservedByDefault in LLVM for targets reserve x18 by default:
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/AArch64TargetParser.cpp#L102-L105
// Note that +reserve-x18 is currently not set for the above targets.
target.os == "android"
|| target.os == "fuchsia"
|| target.env == "ohos"
target.os == Os::Android
|| target.os == Os::Fuchsia
|| target.env == Env::Ohos
|| target.is_like_darwin
|| target.is_like_windows
|| target_features.contains(&sym::reserve_x18)

View file

@ -273,7 +273,7 @@ impl InlineAsmArch {
Arch::Msp430 => Some(Self::Msp430),
Arch::M68k => Some(Self::M68k),
Arch::CSky => Some(Self::CSKY),
Arch::AmdGpu | Arch::Xtensa | Arch::Unknown(_) => None,
Arch::AmdGpu | Arch::Xtensa | Arch::Other(_) => None,
}
}
}

View file

@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_span::Symbol;
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
use crate::spec::{RelocModel, Target};
use crate::spec::{Abi, RelocModel, Target};
def_reg_class! {
PowerPC PowerPCInlineAsmRegClass {
@ -104,10 +104,10 @@ fn reserved_v20to31(
_is_clobber: bool,
) -> Result<(), &'static str> {
if target.is_like_aix {
match &*target.options.abi {
"vec-default" => Err("v20-v31 (vs52-vs63) are reserved on vec-default ABI"),
"vec-extabi" => Ok(()),
_ => unreachable!("unrecognized AIX ABI"),
match &target.options.abi {
Abi::VecDefault => Err("v20-v31 (vs52-vs63) are reserved on vec-default ABI"),
Abi::VecExtAbi => Ok(()),
abi => unreachable!("unrecognized AIX ABI: {abi}"),
}
} else {
Ok(())

View file

@ -3,7 +3,7 @@ use std::iter;
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface};
use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::spec::{HasTargetSpec, Target};
use crate::spec::{Abi, HasTargetSpec, Target};
/// Indicates the variant of the AArch64 ABI we are compiling for.
/// Used to accommodate Apple and Microsoft's deviations from the usual AAPCS ABI.
@ -33,7 +33,7 @@ where
RegKind::Integer => false,
// The softfloat ABI treats floats like integers, so they
// do not get homogeneous aggregate treatment.
RegKind::Float => cx.target_spec().abi != "softfloat",
RegKind::Float => cx.target_spec().abi != Abi::SoftFloat,
RegKind::Vector => size.bits() == 64 || size.bits() == 128,
};
@ -42,7 +42,7 @@ where
}
fn softfloat_float_abi<Ty>(target: &Target, arg: &mut ArgAbi<'_, Ty>) {
if target.abi != "softfloat" {
if target.abi != Abi::SoftFloat {
return;
}
// Do *not* use the float registers for passing arguments, as that would make LLVM pick the ABI

View file

@ -702,7 +702,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
Arch::RiscV32 | Arch::RiscV64 => riscv::compute_abi_info(cx, self),
Arch::Wasm32 | Arch::Wasm64 => wasm::compute_abi_info(cx, self),
Arch::Bpf => bpf::compute_abi_info(cx, self),
arch @ (Arch::PowerPC64LE | Arch::SpirV | Arch::Unknown(_)) => {
arch @ (Arch::PowerPC64LE | Arch::SpirV | Arch::Other(_)) => {
panic!("no lowering implemented for {arch}")
}
}

View file

@ -1,7 +1,7 @@
use rustc_abi::TyAbiInterface;
use crate::callconv::{ArgAbi, FnAbi};
use crate::spec::HasTargetSpec;
use crate::spec::{Env, HasTargetSpec, Os};
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if ret.layout.is_aggregate() {
@ -17,8 +17,8 @@ where
{
if arg.is_ignore() {
// powerpc-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
if cx.target_spec().os == "linux"
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc")
if cx.target_spec().os == Os::Linux
&& matches!(cx.target_spec().env, Env::Gnu | Env::Musl | Env::Uclibc)
&& arg.layout.is_zst()
{
arg.make_indirect_from_ignore();

View file

@ -5,7 +5,7 @@
use rustc_abi::{Endian, HasDataLayout, TyAbiInterface};
use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::spec::HasTargetSpec;
use crate::spec::{Env, HasTargetSpec, Os};
#[derive(Debug, Clone, Copy, PartialEq)]
enum ABI {
@ -106,9 +106,9 @@ where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec,
{
let abi = if cx.target_spec().env == "musl" || cx.target_spec().os == "freebsd" {
let abi = if cx.target_spec().env == Env::Musl || cx.target_spec().os == Os::FreeBsd {
ELFv2
} else if cx.target_spec().os == "aix" {
} else if cx.target_spec().os == Os::Aix {
AIX
} else {
match cx.data_layout().endian {

View file

@ -4,7 +4,7 @@
use rustc_abi::{BackendRepr, HasDataLayout, TyAbiInterface};
use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind};
use crate::spec::HasTargetSpec;
use crate::spec::{Env, HasTargetSpec, Os};
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
let size = ret.layout.size;
@ -29,8 +29,8 @@ where
}
if arg.is_ignore() {
// s390x-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
if cx.target_spec().os == "linux"
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc")
if cx.target_spec().os == Os::Linux
&& matches!(cx.target_spec().env, Env::Gnu | Env::Musl | Env::Uclibc)
&& arg.layout.is_zst()
{
arg.make_indirect_from_ignore();

View file

@ -6,7 +6,7 @@ use rustc_abi::{
};
use crate::callconv::{ArgAbi, ArgAttribute, CastTarget, FnAbi, Uniform};
use crate::spec::HasTargetSpec;
use crate::spec::{Env, HasTargetSpec, Os};
#[derive(Clone, Debug)]
struct Sdata {
@ -223,8 +223,8 @@ where
for arg in fn_abi.args.iter_mut() {
if arg.is_ignore() {
// sparc64-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
if cx.target_spec().os == "linux"
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc")
if cx.target_spec().os == Os::Linux
&& matches!(cx.target_spec().env, Env::Gnu | Env::Musl | Env::Uclibc)
&& arg.layout.is_zst()
{
arg.make_indirect_from_ignore();

View file

@ -137,6 +137,14 @@ macro_rules! target_spec_enum {
$( #[$variant_attr:meta] )*
$Variant,
)*
/// The vast majority of the time, the compiler deals with a fixed
/// set of values, so it is convenient for them to be represented in
/// an enum. However, it is possible to have arbitrary values in a
/// target JSON file (which can be parsed when `--target` is
/// specified). This might occur, for example, for an out-of-tree
/// codegen backend that supports a value (e.g. architecture or OS)
/// that rustc currently doesn't know about. This variant exists as
/// an escape hatch for such cases.
$( #[$other_variant_attr] )*
$OtherVariant(crate::spec::StaticCow<str>),
}

View file

@ -1,15 +1,16 @@
use rustc_abi::Endian;
use crate::spec::{
BinaryFormat, Cc, CodeModel, LinkOutputKind, LinkerFlavor, TargetOptions, crt_objects, cvs,
Abi, BinaryFormat, Cc, CodeModel, LinkOutputKind, LinkerFlavor, Os, TargetOptions, crt_objects,
cvs,
};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
abi: "vec-extabi".into(),
abi: Abi::VecExtAbi,
code_model: Some(CodeModel::Large),
cpu: "pwr7".into(),
os: "aix".into(),
os: Os::Aix,
vendor: "ibm".into(),
dynamic_linking: true,
endian: Endian::Big,

View file

@ -1,8 +1,8 @@
use crate::spec::{SanitizerSet, TargetOptions, TlsModel, base};
use crate::spec::{Os, SanitizerSet, TargetOptions, TlsModel, base};
pub(crate) fn opts() -> TargetOptions {
let mut base = base::linux::opts();
base.os = "android".into();
base.os = Os::Android;
base.is_like_android = true;
base.default_dwarf_version = 2;
base.tls_model = TlsModel::Emulated;

View file

@ -4,8 +4,8 @@ use std::num::ParseIntError;
use std::str::FromStr;
use crate::spec::{
BinaryFormat, Cc, DebuginfoKind, FloatAbi, FramePointer, LinkerFlavor, Lld, RustcAbi,
SplitDebuginfo, StackProbeType, StaticCow, Target, TargetOptions, cvs,
Abi, BinaryFormat, Cc, DebuginfoKind, Env, FloatAbi, FramePointer, LinkerFlavor, Lld, Os,
RustcAbi, SplitDebuginfo, StackProbeType, StaticCow, Target, TargetOptions, cvs,
};
#[cfg(test)]
@ -94,11 +94,25 @@ pub(crate) enum TargetEnv {
}
impl TargetEnv {
fn target_env(self) -> &'static str {
fn target_env(self) -> Env {
match self {
Self::Normal => "",
Self::MacCatalyst => "macabi",
Self::Simulator => "sim",
Self::Normal => Env::Unspecified,
Self::MacCatalyst => Env::MacAbi,
Self::Simulator => Env::Sim,
}
}
// NOTE: We originally set `cfg(target_abi = "macabi")` / `cfg(target_abi = "sim")`,
// before it was discovered that those are actually environments:
// https://github.com/rust-lang/rust/issues/133331
//
// But let's continue setting them for backwards compatibility.
// FIXME(madsmtm): Warn about using these in the future.
fn target_abi(self) -> Abi {
match self {
Self::Normal => Abi::Unspecified,
Self::MacCatalyst => Abi::MacAbi,
Self::Simulator => Abi::Sim,
}
}
}
@ -106,23 +120,19 @@ impl TargetEnv {
/// Get the base target options, unversioned LLVM target and `target_arch` from the three
/// things that uniquely identify Rust's Apple targets: The OS, the architecture, and the ABI.
pub(crate) fn base(
os: &'static str,
os: Os,
arch: Arch,
env: TargetEnv,
) -> (TargetOptions, StaticCow<str>, crate::spec::Arch) {
let link_env_remove = link_env_remove(&os);
let unversioned_llvm_target = unversioned_llvm_target(&os, arch, env);
let mut opts = TargetOptions {
llvm_floatabi: Some(FloatAbi::Hard),
os: os.into(),
env: env.target_env().into(),
// NOTE: We originally set `cfg(target_abi = "macabi")` / `cfg(target_abi = "sim")`,
// before it was discovered that those are actually environments:
// https://github.com/rust-lang/rust/issues/133331
//
// But let's continue setting them for backwards compatibility.
// FIXME(madsmtm): Warn about using these in the future.
abi: env.target_env().into(),
os,
env: env.target_env(),
abi: env.target_abi(),
cpu: arch.target_cpu(env).into(),
link_env_remove: link_env_remove(os),
link_env_remove,
vendor: "apple".into(),
linker_flavor: LinkerFlavor::Darwin(Cc::Yes, Lld::No),
// macOS has -dead_strip, which doesn't rely on function_sections
@ -189,23 +199,23 @@ pub(crate) fn base(
// All Apple x86-32 targets have SSE2.
opts.rustc_abi = Some(RustcAbi::X86Sse2);
}
(opts, unversioned_llvm_target(os, arch, env), arch.target_arch())
(opts, unversioned_llvm_target, arch.target_arch())
}
/// Generate part of the LLVM target triple.
///
/// See `rustc_codegen_ssa::back::versioned_llvm_target` for the full triple passed to LLVM and
/// Clang.
fn unversioned_llvm_target(os: &str, arch: Arch, env: TargetEnv) -> StaticCow<str> {
fn unversioned_llvm_target(os: &Os, arch: Arch, env: TargetEnv) -> StaticCow<str> {
let arch = arch.target_name();
// Convert to the "canonical" OS name used by LLVM:
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L236-L282
let os = match os {
"macos" => "macosx",
"ios" => "ios",
"watchos" => "watchos",
"tvos" => "tvos",
"visionos" => "xros",
Os::MacOs => "macosx",
Os::IOs => "ios",
Os::WatchOs => "watchos",
Os::TvOs => "tvos",
Os::VisionOs => "xros",
_ => unreachable!("tried to get LLVM target OS for non-Apple platform"),
};
let environment = match env {
@ -216,13 +226,13 @@ fn unversioned_llvm_target(os: &str, arch: Arch, env: TargetEnv) -> StaticCow<st
format!("{arch}-apple-{os}{environment}").into()
}
fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
fn link_env_remove(os: &Os) -> StaticCow<[StaticCow<str>]> {
// Apple platforms only officially support macOS as a host for any compilation.
//
// If building for macOS, we go ahead and remove any erroneous environment state
// that's only applicable to cross-OS compilation. Always leave anything for the
// host OS alone though.
if os == "macos" {
if *os == Os::MacOs {
// `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".
@ -284,7 +294,7 @@ impl OSVersion {
}
/// Minimum operating system versions currently supported by `rustc`.
pub fn os_minimum_deployment_target(os: &str) -> Self {
pub fn os_minimum_deployment_target(os: &Os) -> Self {
// When bumping a version in here, remember to update the platform-support docs too.
//
// NOTE: The defaults may change in future `rustc` versions, so if you are looking for the
@ -293,12 +303,14 @@ impl OSVersion {
// $ rustc --print deployment-target
// ```
let (major, minor, patch) = match os {
"macos" => (10, 12, 0),
"ios" => (10, 0, 0),
"tvos" => (10, 0, 0),
"watchos" => (5, 0, 0),
"visionos" => (1, 0, 0),
_ => unreachable!("tried to get deployment target for non-Apple platform"),
Os::MacOs => (10, 12, 0),
Os::IOs => (10, 0, 0),
Os::TvOs => (10, 0, 0),
Os::WatchOs => (5, 0, 0),
Os::VisionOs => (1, 0, 0),
other => {
unreachable!("tried to get deployment target for non-Apple platform: {:?}", other)
}
};
Self { major, minor, patch }
}
@ -311,36 +323,36 @@ impl OSVersion {
/// This matches what LLVM does, see in part:
/// <https://github.com/llvm/llvm-project/blob/llvmorg-21.1.3/llvm/lib/TargetParser/Triple.cpp#L2140-L2175>
pub fn minimum_deployment_target(target: &Target) -> Self {
let (major, minor, patch) = match (&*target.os, &target.arch, &*target.env) {
("macos", crate::spec::Arch::AArch64, _) => (11, 0, 0),
("ios", crate::spec::Arch::AArch64, "macabi") => (14, 0, 0),
("ios", crate::spec::Arch::AArch64, "sim") => (14, 0, 0),
("ios", _, _) if target.llvm_target.starts_with("arm64e") => (14, 0, 0),
let (major, minor, patch) = match (&target.os, &target.arch, &target.env) {
(Os::MacOs, crate::spec::Arch::AArch64, _) => (11, 0, 0),
(Os::IOs, crate::spec::Arch::AArch64, Env::MacAbi) => (14, 0, 0),
(Os::IOs, crate::spec::Arch::AArch64, Env::Sim) => (14, 0, 0),
(Os::IOs, _, _) if target.llvm_target.starts_with("arm64e") => (14, 0, 0),
// Mac Catalyst defaults to 13.1 in Clang.
("ios", _, "macabi") => (13, 1, 0),
("tvos", crate::spec::Arch::AArch64, "sim") => (14, 0, 0),
("watchos", crate::spec::Arch::AArch64, "sim") => (7, 0, 0),
(Os::IOs, _, Env::MacAbi) => (13, 1, 0),
(Os::TvOs, crate::spec::Arch::AArch64, Env::Sim) => (14, 0, 0),
(Os::WatchOs, crate::spec::Arch::AArch64, Env::Sim) => (7, 0, 0),
// True Aarch64 on watchOS (instead of their Aarch64 Ilp32 called `arm64_32`) has been
// available since Xcode 14, but it's only actually used more recently in watchOS 26.
("watchos", crate::spec::Arch::AArch64, "")
(Os::WatchOs, crate::spec::Arch::AArch64, Env::Unspecified)
if !target.llvm_target.starts_with("arm64_32") =>
{
(26, 0, 0)
}
(os, _, _) => return Self::os_minimum_deployment_target(os),
_ => return Self::os_minimum_deployment_target(&target.os),
};
Self { major, minor, patch }
}
}
/// Name of the environment variable used to fetch the deployment target on the given OS.
pub fn deployment_target_env_var(os: &str) -> &'static str {
pub fn deployment_target_env_var(os: &Os) -> &'static str {
match os {
"macos" => "MACOSX_DEPLOYMENT_TARGET",
"ios" => "IPHONEOS_DEPLOYMENT_TARGET",
"watchos" => "WATCHOS_DEPLOYMENT_TARGET",
"tvos" => "TVOS_DEPLOYMENT_TARGET",
"visionos" => "XROS_DEPLOYMENT_TARGET",
Os::MacOs => "MACOSX_DEPLOYMENT_TARGET",
Os::IOs => "IPHONEOS_DEPLOYMENT_TARGET",
Os::WatchOs => "WATCHOS_DEPLOYMENT_TARGET",
Os::TvOs => "TVOS_DEPLOYMENT_TARGET",
Os::VisionOs => "XROS_DEPLOYMENT_TARGET",
_ => unreachable!("tried to get deployment target env var for non-Apple platform"),
}
}

View file

@ -4,6 +4,7 @@ use crate::spec::targets::{
aarch64_apple_watchos_sim, i686_apple_darwin, x86_64_apple_darwin, x86_64_apple_ios,
x86_64_apple_tvos, x86_64_apple_watchos_sim,
};
use crate::spec::{Abi, Env};
#[test]
fn simulator_targets_set_env() {
@ -18,9 +19,9 @@ fn simulator_targets_set_env() {
];
for target in &all_sim_targets {
assert_eq!(target.env, "sim");
assert_eq!(target.env, Env::Sim);
// Ensure backwards compat
assert_eq!(target.abi, "sim");
assert_eq!(target.abi, Abi::Sim);
}
}

View file

@ -1,8 +1,8 @@
use std::borrow::Cow;
use crate::spec::{
BinaryFormat, Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions, TlsModel,
cvs,
BinaryFormat, Cc, DebuginfoKind, LinkerFlavor, Lld, Os, SplitDebuginfo, TargetOptions,
TlsModel, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -24,7 +24,7 @@ pub(crate) fn opts() -> TargetOptions {
cygwin_libs,
);
TargetOptions {
os: "cygwin".into(),
os: Os::Cygwin,
vendor: "pc".into(),
// FIXME(#13846) this should be enabled for cygwin
function_sections: false,

View file

@ -1,8 +1,8 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "dragonfly".into(),
os: Os::Dragonfly,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,8 +1,8 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "freebsd".into(),
os: Os::FreeBsd,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,5 +1,5 @@
use crate::spec::{
Cc, FramePointer, LinkOutputKind, LinkerFlavor, Lld, TargetOptions, crt_objects, cvs,
Cc, FramePointer, LinkOutputKind, LinkerFlavor, Lld, Os, TargetOptions, crt_objects, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -30,7 +30,7 @@ pub(crate) fn opts() -> TargetOptions {
);
TargetOptions {
os: "fuchsia".into(),
os: Os::Fuchsia,
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
dynamic_linking: true,

View file

@ -1,8 +1,8 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "haiku".into(),
os: Os::Haiku,
dynamic_linking: true,
families: cvs!["unix"],
relro_level: RelroLevel::Full,

View file

@ -1,8 +1,8 @@
use crate::spec::{PanicStrategy, RelroLevel, StackProbeType, TargetOptions};
use crate::spec::{Os, PanicStrategy, RelroLevel, StackProbeType, TargetOptions};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "helenos".into(),
os: Os::HelenOs,
dynamic_linking: true,
// we need the linker to keep libgcc and friends

View file

@ -1,8 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, TargetOptions, TlsModel};
use crate::spec::{Cc, LinkerFlavor, Lld, Os, PanicStrategy, TargetOptions, TlsModel};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "hermit".into(),
os: Os::Hermit,
linker: Some("rust-lld".into()),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
tls_model: TlsModel::InitialExec,

View file

@ -1,8 +1,8 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "hurd".into(),
os: Os::Hurd,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,5 +1,5 @@
use crate::spec::{TargetOptions, base};
use crate::spec::{Env, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
TargetOptions { env: "gnu".into(), ..base::hurd::opts() }
TargetOptions { env: Env::Gnu, ..base::hurd::opts() }
}

View file

@ -1,4 +1,4 @@
use crate::spec::{Cc, FramePointer, LinkerFlavor, TargetOptions, cvs};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Os, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
let late_link_args = TargetOptions::link_args(
@ -25,7 +25,7 @@ pub(crate) fn opts() -> TargetOptions {
);
TargetOptions {
os: "illumos".into(),
os: Os::Illumos,
dynamic_linking: true,
has_rpath: true,
families: cvs!["unix"],

View file

@ -1,9 +1,9 @@
use crate::spec::{Cc, LinkerFlavor, PanicStrategy, RelocModel, TargetOptions, cvs};
use crate::spec::{Cc, Env, LinkerFlavor, Os, PanicStrategy, RelocModel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "l4re".into(),
env: "uclibc".into(),
os: Os::L4Re,
env: Env::Uclibc,
linker_flavor: LinkerFlavor::Unix(Cc::No),
panic_strategy: PanicStrategy::Abort,
linker: Some("l4-bender".into()),

View file

@ -1,10 +1,10 @@
use std::borrow::Cow;
use crate::spec::{RelroLevel, SplitDebuginfo, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, SplitDebuginfo, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "linux".into(),
os: Os::Linux,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,7 +1,7 @@
use crate::spec::{Cc, LinkerFlavor, Lld, TargetOptions, base};
use crate::spec::{Cc, Env, LinkerFlavor, Lld, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
let mut base = TargetOptions { env: "gnu".into(), ..base::linux::opts() };
let mut base = TargetOptions { env: Env::Gnu, ..base::linux::opts() };
// When we're asked to use the `rust-lld` linker by default, set the appropriate lld-using
// linker flavor, and self-contained linker component.

View file

@ -1,8 +1,8 @@
use crate::spec::{LinkSelfContainedDefault, TargetOptions, base, crt_objects};
use crate::spec::{Env, LinkSelfContainedDefault, TargetOptions, base, crt_objects};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
env: "musl".into(),
env: Env::Musl,
pre_link_objects_self_contained: crt_objects::pre_musl_self_contained(),
post_link_objects_self_contained: crt_objects::post_musl_self_contained(),
link_self_contained: LinkSelfContainedDefault::InferredForMusl,

View file

@ -1,8 +1,8 @@
use crate::spec::{TargetOptions, TlsModel, base};
use crate::spec::{Env, TargetOptions, TlsModel, base};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
env: "ohos".into(),
env: Env::Ohos,
crt_static_default: false,
tls_model: TlsModel::Emulated,
has_thread_local: false,

View file

@ -1,5 +1,5 @@
use crate::spec::{TargetOptions, base};
use crate::spec::{Env, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
TargetOptions { env: "uclibc".into(), ..base::linux::opts() }
TargetOptions { env: Env::Uclibc, ..base::linux::opts() }
}

View file

@ -2,8 +2,8 @@
//! aspects from their respective base targets
use crate::spec::{
Cc, LinkSelfContainedDefault, LinkerFlavor, PanicStrategy, RelocModel, TargetOptions, TlsModel,
add_link_args, crt_objects, cvs,
Cc, Env, LinkSelfContainedDefault, LinkerFlavor, Os, PanicStrategy, RelocModel, TargetOptions,
TlsModel, add_link_args, crt_objects, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -57,8 +57,8 @@ pub(crate) fn opts() -> TargetOptions {
TargetOptions {
is_like_wasm: true,
families: cvs!["wasm", "unix"],
os: "linux".into(),
env: "musl".into(),
os: Os::Linux,
env: Env::Musl,
// we allow dynamic linking, but only cdylibs. Basically we allow a
// final library artifact that exports some symbols (a wasm module) but

View file

@ -1,12 +1,12 @@
use std::borrow::Cow;
use crate::spec::{
PanicStrategy, RelocModel, RelroLevel, SplitDebuginfo, StackProbeType, TargetOptions, cvs,
Os, PanicStrategy, RelocModel, RelroLevel, SplitDebuginfo, StackProbeType, TargetOptions, cvs,
};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "lynxos178".into(),
os: Os::LynxOs178,
dynamic_linking: false,
families: cvs!["unix"],
position_independent_executables: false,

View file

@ -1,9 +1,9 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Env, Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "managarm".into(),
env: "mlibc".into(),
os: Os::Managarm,
env: Env::Mlibc,
dynamic_linking: true,
executables: true,
families: cvs!["unix"],

View file

@ -1,5 +1,5 @@
use crate::spec::{
Cc, FramePointer, LinkerFlavor, Lld, PanicStrategy, StackProbeType, TargetOptions,
Cc, FramePointer, LinkerFlavor, Lld, Os, PanicStrategy, StackProbeType, TargetOptions,
};
pub(crate) fn opts() -> TargetOptions {
@ -16,7 +16,7 @@ pub(crate) fn opts() -> TargetOptions {
],
);
TargetOptions {
os: "motor".into(),
os: Os::Motor,
executables: true,
// TLS is false below because if true, the compiler assumes
// we handle TLS at the ELF loading level, which we don't.

View file

@ -1,8 +1,8 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "netbsd".into(),
os: Os::NetBsd,
dynamic_linking: true,
families: cvs!["unix"],
no_default_libraries: false,

View file

@ -1,5 +1,5 @@
use crate::spec::{
Cc, LinkArgs, LinkerFlavor, Lld, RelroLevel, Target, TargetMetadata, TargetOptions, cvs,
Cc, LinkArgs, LinkerFlavor, Lld, Os, RelroLevel, Target, TargetMetadata, TargetOptions, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -11,7 +11,7 @@ pub(crate) fn opts() -> TargetOptions {
has_rpath: true,
has_thread_local: false,
linker: Some("qcc".into()),
os: "nto".into(),
os: Os::Nto,
// We want backtraces to work by default and they rely on unwind tables
// (regardless of `-C panic` strategy).
default_uwtable: true,

View file

@ -1,8 +1,8 @@
use crate::spec::{FramePointer, RelroLevel, TargetOptions, TlsModel, cvs};
use crate::spec::{FramePointer, Os, RelroLevel, TargetOptions, TlsModel, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "openbsd".into(),
os: Os::OpenBsd,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,9 +1,9 @@
use crate::spec::{Cc, LinkerFlavor, Lld, RelroLevel, TargetOptions, cvs};
use crate::spec::{Cc, Env, LinkerFlavor, Lld, Os, RelroLevel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "redox".into(),
env: "relibc".into(),
os: Os::Redox,
env: Env::Relibc,
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,

View file

@ -1,8 +1,8 @@
use crate::spec::{Cc, LinkerFlavor, TargetOptions, cvs};
use crate::spec::{Cc, LinkerFlavor, Os, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "solaris".into(),
os: Os::Solaris,
dynamic_linking: true,
has_rpath: true,
families: cvs!["unix"],

View file

@ -1,8 +1,8 @@
use crate::spec::{FramePointer, TargetOptions};
use crate::spec::{FramePointer, Os, TargetOptions};
pub(crate) fn opts(kernel: &str) -> TargetOptions {
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: format!("solid_{kernel}").into(),
os: Os::SolidAsp3,
vendor: "kmc".into(),
executables: false,
frame_pointer: FramePointer::NonLeaf,

View file

@ -1,4 +1,6 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelroLevel, TargetOptions, add_link_args};
use crate::spec::{
Cc, LinkerFlavor, Lld, Os, PanicStrategy, RelroLevel, TargetOptions, add_link_args,
};
pub(crate) fn opts() -> TargetOptions {
let lld_args = &["-zmax-page-size=4096", "-znow", "-ztext", "--execute-only"];
@ -8,8 +10,7 @@ pub(crate) fn opts() -> TargetOptions {
add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), cc_args);
TargetOptions {
os: "teeos".into(),
vendor: "unknown".into(),
os: Os::TeeOs,
dynamic_linking: true,
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
// rpath hardcodes -Wl, so it can't be used together with ld.lld.

View file

@ -9,7 +9,7 @@
// the timer-interrupt. Device-drivers are required to use polling-based models. Furthermore, all
// code runs in the same environment, no process separation is supported.
use crate::spec::{LinkerFlavor, Lld, PanicStrategy, StackProbeType, TargetOptions, base};
use crate::spec::{LinkerFlavor, Lld, Os, PanicStrategy, StackProbeType, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
let mut base = base::msvc::opts();
@ -35,7 +35,7 @@ pub(crate) fn opts() -> TargetOptions {
);
TargetOptions {
os: "uefi".into(),
os: Os::Uefi,
linker_flavor: LinkerFlavor::Msvc(Lld::Yes),
disable_redzone: true,
exe_suffix: ".efi".into(),

View file

@ -1,9 +1,9 @@
use crate::spec::{PanicStrategy, RelocModel, TargetOptions, cvs};
use crate::spec::{Env, Os, PanicStrategy, RelocModel, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "linux".into(),
env: "musl".into(),
os: Os::Linux,
env: Env::Musl,
vendor: "unikraft".into(),
linker: Some("kraftld".into()),
relocation_model: RelocModel::Static,

View file

@ -1,9 +1,9 @@
use crate::spec::{TargetOptions, cvs};
use crate::spec::{Env, Os, TargetOptions, cvs};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "vxworks".into(),
env: "gnu".into(),
os: Os::VxWorks,
env: Env::Gnu,
vendor: "wrs".into(),
linker: Some("wr-c++".into()),
exe_suffix: ".vxe".into(),

View file

@ -1,8 +1,8 @@
use std::borrow::Cow;
use crate::spec::{
BinaryFormat, Cc, DebuginfoKind, LinkSelfContainedDefault, LinkerFlavor, Lld, SplitDebuginfo,
TargetOptions, add_link_args, crt_objects, cvs,
BinaryFormat, Cc, DebuginfoKind, Env, LinkSelfContainedDefault, LinkerFlavor, Lld, Os,
SplitDebuginfo, TargetOptions, add_link_args, crt_objects, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -77,8 +77,8 @@ pub(crate) fn opts() -> TargetOptions {
);
TargetOptions {
os: "windows".into(),
env: "gnu".into(),
os: Os::Windows,
env: Env::Gnu,
vendor: "pc".into(),
// FIXME(#13846) this should be enabled for windows
function_sections: false,

View file

@ -1,7 +1,8 @@
use std::borrow::Cow;
use crate::spec::{
BinaryFormat, Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions, cvs,
Abi, BinaryFormat, Cc, DebuginfoKind, Env, LinkerFlavor, Lld, Os, SplitDebuginfo,
TargetOptions, cvs,
};
pub(crate) fn opts() -> TargetOptions {
@ -20,10 +21,10 @@ pub(crate) fn opts() -> TargetOptions {
);
TargetOptions {
os: "windows".into(),
env: "gnu".into(),
os: Os::Windows,
env: Env::Gnu,
vendor: "pc".into(),
abi: "llvm".into(),
abi: Abi::Llvm,
linker: Some("clang".into()),
dynamic_linking: true,
dll_tls_export: false,

View file

@ -1,11 +1,11 @@
use crate::spec::{TargetOptions, base, cvs};
use crate::spec::{Env, Os, TargetOptions, base, cvs};
pub(crate) fn opts() -> TargetOptions {
let base = base::msvc::opts();
TargetOptions {
os: "windows".into(),
env: "msvc".into(),
os: Os::Windows,
env: Env::Msvc,
vendor: "pc".into(),
dynamic_linking: true,
dll_prefix: "".into(),

View file

@ -1,4 +1,4 @@
use crate::spec::{Cc, LinkArgs, LinkerFlavor, Lld, TargetOptions, add_link_args, base};
use crate::spec::{Abi, Cc, LinkArgs, LinkerFlavor, Lld, TargetOptions, add_link_args, base};
pub(crate) fn opts() -> TargetOptions {
let base = base::windows_gnu::opts();
@ -23,7 +23,7 @@ pub(crate) fn opts() -> TargetOptions {
let late_link_args_static = LinkArgs::new();
TargetOptions {
abi: "uwp".into(),
abi: Abi::Uwp,
vendor: "uwp".into(),
limit_rdylib_exports: false,
late_link_args,

View file

@ -1,8 +1,8 @@
use crate::spec::{LinkerFlavor, Lld, TargetOptions, base};
use crate::spec::{Abi, LinkerFlavor, Lld, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
let mut opts =
TargetOptions { abi: "uwp".into(), vendor: "uwp".into(), ..base::windows_msvc::opts() };
TargetOptions { abi: Abi::Uwp, vendor: "uwp".into(), ..base::windows_msvc::opts() };
opts.add_pre_link_args(LinkerFlavor::Msvc(Lld::No), &["/APPCONTAINER", "mincore.lib"]);

View file

@ -1,10 +1,10 @@
use rustc_abi::Endian;
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, TargetOptions};
use crate::spec::{Cc, LinkerFlavor, Lld, Os, PanicStrategy, RelocModel, TargetOptions};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "none".into(),
os: Os::None,
endian: Endian::Little,
c_int_width: 32,
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),

View file

@ -5,9 +5,9 @@ use rustc_abi::{Align, AlignFromBytesError};
use super::crt_objects::CrtObjects;
use super::{
Arch, BinaryFormat, CodeModel, DebuginfoKind, FloatAbi, FramePointer, LinkArgsCli,
Abi, Arch, BinaryFormat, CodeModel, DebuginfoKind, Env, FloatAbi, FramePointer, LinkArgsCli,
LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFlavorCli, LldFlavor,
MergeFunctions, PanicStrategy, RelocModel, RelroLevel, RustcAbi, SanitizerSet,
MergeFunctions, Os, PanicStrategy, RelocModel, RelroLevel, RustcAbi, SanitizerSet,
SmallDataThresholdSupport, SplitDebuginfo, StackProbeType, StaticCow, SymbolVisibility, Target,
TargetKind, TargetOptions, TargetWarnings, TlsModel,
};
@ -505,9 +505,9 @@ struct TargetSpecJson {
#[serde(rename = "target-c-int-width")]
c_int_width: Option<u16>,
c_enum_min_bits: Option<u64>,
os: Option<StaticCow<str>>,
env: Option<StaticCow<str>>,
abi: Option<StaticCow<str>>,
os: Option<Os>,
env: Option<Env>,
abi: Option<Abi>,
vendor: Option<StaticCow<str>>,
linker: Option<StaticCow<str>>,
#[serde(rename = "linker-flavor")]

View file

@ -1884,14 +1884,7 @@ crate::target_spec_enum! {
X86_64 = "x86_64",
Xtensa = "xtensa",
}
/// The vast majority of the time, the compiler deals with a fixed set of
/// target architectures, so it is convenient for them to be represented in
/// an enum. However, it is possible to have arbitrary values for the "arch"
/// field in a target JSON file (which can be parsed when `--target` is
/// specified). This might occur, for example, for an out-of-tree codegen
/// backend that supports an architecture that rustc currently doesn't know
/// about. This variant exists as an escape hatch for such cases.
other_variant = Unknown;
other_variant = Other;
}
impl Arch {
@ -1928,11 +1921,135 @@ impl Arch {
Self::X86 => sym::x86,
Self::X86_64 => sym::x86_64,
Self::Xtensa => sym::xtensa,
Self::Unknown(name) => rustc_span::Symbol::intern(name),
Self::Other(name) => rustc_span::Symbol::intern(name),
}
}
}
crate::target_spec_enum! {
pub enum Os {
Aix = "aix",
AmdHsa = "amdhsa",
Android = "android",
Cuda = "cuda",
Cygwin = "cygwin",
Dragonfly = "dragonfly",
Emscripten = "emscripten",
EspIdf = "espidf",
FreeBsd = "freebsd",
Fuchsia = "fuchsia",
Haiku = "haiku",
HelenOs = "helenos",
Hermit = "hermit",
Horizon = "horizon",
Hurd = "hurd",
Illumos = "illumos",
IOs = "ios",
L4Re = "l4re",
Linux = "linux",
LynxOs178 = "lynxos178",
MacOs = "macos",
Managarm = "managarm",
Motor = "motor",
NetBsd = "netbsd",
None = "none",
Nto = "nto",
NuttX = "nuttx",
OpenBsd = "openbsd",
Psp = "psp",
Psx = "psx",
Redox = "redox",
Rtems = "rtems",
Solaris = "solaris",
SolidAsp3 = "solid_asp3",
TeeOs = "teeos",
Trusty = "trusty",
TvOs = "tvos",
Uefi = "uefi",
VexOs = "vexos",
VisionOs = "visionos",
Vita = "vita",
VxWorks = "vxworks",
Wasi = "wasi",
WatchOs = "watchos",
Windows = "windows",
Xous = "xous",
Zkvm = "zkvm",
Unknown = "unknown",
}
other_variant = Other;
}
impl Os {
pub fn desc_symbol(&self) -> Symbol {
Symbol::intern(self.desc())
}
}
crate::target_spec_enum! {
pub enum Env {
Gnu = "gnu",
MacAbi = "macabi",
Mlibc = "mlibc",
Msvc = "msvc",
Musl = "musl",
Newlib = "newlib",
Nto70 = "nto70",
Nto71 = "nto71",
Nto71IoSock = "nto71_iosock",
Nto80 = "nto80",
Ohos = "ohos",
Relibc = "relibc",
Sgx = "sgx",
Sim = "sim",
P1 = "p1",
P2 = "p2",
P3 = "p3",
Uclibc = "uclibc",
V5 = "v5",
Unspecified = "",
}
other_variant = Other;
}
impl Env {
pub fn desc_symbol(&self) -> Symbol {
Symbol::intern(self.desc())
}
}
crate::target_spec_enum! {
pub enum Abi {
Abi64 = "abi64",
AbiV2 = "abiv2",
AbiV2Hf = "abiv2hf",
Eabi = "eabi",
EabiHf = "eabihf",
ElfV1 = "elfv1",
ElfV2 = "elfv2",
Fortanix = "fortanix",
Ilp32 = "ilp32",
Ilp32e = "ilp32e",
Llvm = "llvm",
MacAbi = "macabi",
Sim = "sim",
SoftFloat = "softfloat",
Spe = "spe",
Uwp = "uwp",
VecDefault = "vec-default",
VecExtAbi = "vec-extabi",
X32 = "x32",
Unspecified = "",
}
other_variant = Other;
}
impl Abi {
pub fn desc_symbol(&self) -> Symbol {
Symbol::intern(self.desc())
}
}
/// Everything `rustc` knows about how to compile for a specific target.
///
/// Every field here must be specified, and has no default value.
@ -2051,18 +2168,18 @@ pub struct TargetOptions {
pub endian: Endian,
/// Width of c_int type. Defaults to "32".
pub c_int_width: u16,
/// OS name to use for conditional compilation (`target_os`). Defaults to "none".
/// "none" implies a bare metal target without `std` library.
/// A couple of targets having `std` also use "unknown" as an `os` value,
/// OS name to use for conditional compilation (`target_os`). Defaults to [`Os::None`].
/// [`Os::None`] implies a bare metal target without `std` library.
/// A couple of targets having `std` also use [`Os::Unknown`] as their `os` value,
/// but they are exceptions.
pub os: StaticCow<str>,
/// Environment name to use for conditional compilation (`target_env`). Defaults to "".
pub env: StaticCow<str>,
pub os: Os,
/// Environment name to use for conditional compilation (`target_env`). Defaults to [`Env::Unspecified`].
pub env: Env,
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
/// or `"eabihf"`. Defaults to "".
/// or `"eabihf"`. Defaults to [`Abi::Unspecified`].
/// This field is *not* forwarded directly to LLVM; its primary purpose is `cfg(target_abi)`.
/// However, parts of the backend do check this field for specific values to enable special behavior.
pub abi: StaticCow<str>,
pub abi: Abi,
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
#[rustc_lint_opt_deny_field_access(
"use `Target::is_like_*` instead of this field; see https://github.com/rust-lang/rust/issues/100343 for rationale"
@ -2565,9 +2682,9 @@ impl Default for TargetOptions {
TargetOptions {
endian: Endian::Little,
c_int_width: 32,
os: "none".into(),
env: "".into(),
abi: "".into(),
os: Os::None,
env: Env::Unspecified,
abi: Abi::Unspecified,
vendor: "unknown".into(),
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.into()),
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
@ -2763,7 +2880,7 @@ impl Target {
);
check_eq!(
self.is_like_solaris,
self.os == "solaris" || self.os == "illumos",
matches!(self.os, Os::Solaris | Os::Illumos),
"`is_like_solaris` must be set if and only if `os` is `solaris` or `illumos`"
);
check_eq!(
@ -2773,7 +2890,7 @@ impl Target {
);
check_eq!(
self.is_like_windows,
self.os == "windows" || self.os == "uefi" || self.os == "cygwin",
matches!(self.os, Os::Windows | Os::Uefi | Os::Cygwin),
"`is_like_windows` must be set if and only if `os` is `windows`, `uefi` or `cygwin`"
);
check_eq!(
@ -2784,7 +2901,7 @@ impl Target {
if self.is_like_msvc {
check!(self.is_like_windows, "if `is_like_msvc` is set, `is_like_windows` must be set");
}
if self.os == "emscripten" {
if self.os == Os::Emscripten {
check!(self.is_like_wasm, "the `emcscripten` os only makes sense on wasm-like targets");
}
@ -2800,12 +2917,12 @@ impl Target {
"`linker_flavor` must be `msvc` if and only if `is_like_msvc` is set"
);
check_eq!(
self.is_like_wasm && self.os != "emscripten",
self.is_like_wasm && self.os != Os::Emscripten,
matches!(self.linker_flavor, LinkerFlavor::WasmLld(..)),
"`linker_flavor` must be `wasm-lld` if and only if `is_like_wasm` is set and the `os` is not `emscripten`",
);
check_eq!(
self.os == "emscripten",
self.os == Os::Emscripten,
matches!(self.linker_flavor, LinkerFlavor::EmCc),
"`linker_flavor` must be `em-cc` if and only if `os` is `emscripten`"
);
@ -2932,12 +3049,14 @@ impl Target {
// except it and document the reasons.
// Keep the default "unknown" vendor instead.
check_ne!(self.vendor, "", "`vendor` cannot be empty");
check_ne!(self.os, "", "`os` cannot be empty");
if let Os::Other(s) = &self.os {
check!(!s.is_empty(), "`os` cannot be empty");
}
if !self.can_use_os_unknown() {
// Keep the default "none" for bare metal targets instead.
check_ne!(
self.os,
"unknown",
Os::Unknown,
"`unknown` os can only be used on particular targets; use `none` for bare-metal targets"
);
}
@ -2951,7 +3070,7 @@ impl Target {
// BPF: when targeting user space vms (like rbpf), those can load dynamic libraries.
// hexagon: when targeting QuRT, that OS can load dynamic libraries.
// wasm{32,64}: dynamic linking is inherent in the definition of the VM.
if self.os == "none"
if self.os == Os::None
&& !matches!(self.arch, Arch::Bpf | Arch::Hexagon | Arch::Wasm32 | Arch::Wasm64)
{
check!(
@ -2984,7 +3103,7 @@ impl Target {
);
}
// The UEFI targets do not support dynamic linking but still require PIC (#101377).
if self.relocation_model == RelocModel::Pic && (self.os != "uefi") {
if self.relocation_model == RelocModel::Pic && self.os != Os::Uefi {
check!(
self.dynamic_linking || self.position_independent_executables,
"when the relocation model is `pic`, the target must support dynamic linking or use position-independent executables. \
@ -3123,7 +3242,7 @@ impl Target {
fn can_use_os_unknown(&self) -> bool {
self.llvm_target == "wasm32-unknown-unknown"
|| self.llvm_target == "wasm64-unknown-unknown"
|| (self.env == "sgx" && self.vendor == "fortanix")
|| (self.env == Env::Sgx && self.vendor == "fortanix")
}
/// Load a built-in target
@ -3198,15 +3317,7 @@ impl Target {
return load_file(&p);
}
// Leave in a specialized error message for the removed target.
// FIXME: If you see this and it's been a few months after this has been released,
// you can probably remove it.
if target_tuple == "i586-pc-windows-msvc" {
Err("the `i586-pc-windows-msvc` target has been removed. Use the `i686-pc-windows-msvc` target instead.\n\
Windows 10 (the minimum required OS version) requires a CPU baseline of at least i686 so you can safely switch".into())
} else {
Err(format!("could not find specification for target {target_tuple:?}"))
}
Err(format!("could not find specification for target {target_tuple:?}"))
}
TargetTuple::TargetJson { ref contents, .. } => Target::from_json(contents),
}
@ -3305,7 +3416,7 @@ impl Target {
| Arch::SpirV
| Arch::Wasm32
| Arch::Wasm64
| Arch::Unknown(_) => return None,
| Arch::Other(_) => return None,
})
}

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("macos", Arch::Arm64, TargetEnv::Normal);
let (opts, llvm_target, arch) = base(Os::MacOs, Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::Normal);
let (opts, llvm_target, arch) = base(Os::IOs, Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::MacCatalyst);
let (opts, llvm_target, arch) = base(Os::IOs, Arch::Arm64, TargetEnv::MacCatalyst);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::Simulator);
let (opts, llvm_target, arch) = base(Os::IOs, Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetEnv::Normal);
let (opts, llvm_target, arch) = base(Os::TvOs, Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetEnv::Simulator);
let (opts, llvm_target, arch) = base(Os::TvOs, Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetEnv::Normal);
let (opts, llvm_target, arch) = base(Os::VisionOs, Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{SanitizerSet, Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, SanitizerSet, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetEnv::Simulator);
let (opts, llvm_target, arch) = base(Os::VisionOs, Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetEnv::Normal);
let (opts, llvm_target, arch) = base(Os::WatchOs, Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {

View file

@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};
use crate::spec::{Os, Target, TargetMetadata, TargetOptions};
pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetEnv::Simulator);
let (opts, llvm_target, arch) = base(Os::WatchOs, Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {

Some files were not shown because too many files have changed in this diff Show more