Skip to content

Commit de792eb

Browse files
compiler: Redescribe rustc_target::spec more accurately
1 parent 3bc767e commit de792eb

File tree

1 file changed

+18
-8
lines changed
  • compiler/rustc_target/src/spec

1 file changed

+18
-8
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,24 @@
2525
//!
2626
//! # Defining a new target
2727
//!
28-
//! Targets are defined using [JSON](https://json.org/). The `Target` struct in
29-
//! this module defines the format the JSON file should take, though each
30-
//! underscore in the field names should be replaced with a hyphen (`-`) in the
31-
//! JSON file. Some fields are required in every target specification, such as
32-
//! `llvm-target`, `target-endian`, `target-pointer-width`, `data-layout`,
33-
//! `arch`, and `os`. In general, options passed to rustc with `-C` override
34-
//! the target's settings, though `target-feature` and `link-args` will *add*
35-
//! to the list specified by the target, rather than replace.
28+
//! Targets are defined using a struct which additionally has serialization to and from [JSON].
29+
//! The `Target` struct in this module loosely corresponds with the format the JSON takes.
30+
//! We usually try to make the fields equivalent but we have given up on a 1:1 correspondence
31+
//! between the JSON and the actual structure itself.
32+
//!
33+
//! Some fields are required in every target spec, and they should be embedded in Target directly.
34+
//! Optional keys are in TargetOptions, but Target derefs to it, for no practical difference.
35+
//! Most notable is the "data-layout" field which specifies Rust's notion of sizes and alignments
36+
//! for several key types, such as f64, pointers, and so on.
37+
//!
38+
//! At one point we felt `-C` options should override the target's settings, like in C compilers,
39+
//! but that was an essentially-unmarked route for making code incorrect and Rust unsound.
40+
//! Confronted with programmers who prefer a compiler with a good UX instead of a lethal weapon,
41+
//! we have almost-entirely recanted that notion, though we hope "target modifiers" will offer
42+
//! a way to have a decent UX yet still extend the necessary compiler controls, without
43+
//! requiring a new target spec for each and every single possible target micro-variant.
44+
//!
45+
//! [JSON]: https://json.org
3646
3747
use std::borrow::Cow;
3848
use std::collections::BTreeMap;

0 commit comments

Comments
 (0)