@@ -4,12 +4,21 @@ use crate::util::errors::{CargoResult, CargoResultExt};
4
4
use serde:: Serialize ;
5
5
use std:: path:: Path ;
6
6
7
- /// Indicates whether an object is for the host architcture or the target architecture .
7
+ /// Indicator for how a unit is being compiled .
8
8
///
9
- /// These will be the same unless cross-compiling.
9
+ /// This is used primarily for organizing cross compilations vs host
10
+ /// compilations, where cross compilations happen at the request of `--target`
11
+ /// and host compilations happen for things like build scripts and procedural
12
+ /// macros.
10
13
#[ derive( PartialEq , Eq , Hash , Debug , Clone , Copy , PartialOrd , Ord , Serialize ) ]
11
14
pub enum CompileKind {
15
+ /// Attached to a unit that is compiled for the "host" system or otherwise
16
+ /// is compiled without a `--target` flag. This is used for procedural
17
+ /// macros and build scripts, or if the `--target` flag isn't passed.
12
18
Host ,
19
+
20
+ /// Attached to a unit to be compiled for a particular target. This is used
21
+ /// for units when the `--target` flag is passed.
13
22
Target ( CompileTarget ) ,
14
23
}
15
24
@@ -42,6 +51,23 @@ impl CompileKind {
42
51
}
43
52
}
44
53
54
+ /// Abstraction for the representation of a compilation target that Cargo has.
55
+ ///
56
+ /// Compilation targets are one of two things right now:
57
+ ///
58
+ /// 1. A raw target string, like `x86_64-unknown-linux-gnu`.
59
+ /// 2. The path to a JSON file, such as `/path/to/my-target.json`.
60
+ ///
61
+ /// Raw target strings are typically dictated by `rustc` itself and represent
62
+ /// built-in targets. Custom JSON files are somewhat unstable, but supported
63
+ /// here in Cargo. Note that for JSON target files this `CompileTarget` stores a
64
+ /// full canonicalized path to the target.
65
+ ///
66
+ /// The main reason for this existence is to handle JSON target files where when
67
+ /// we call rustc we pass full paths but when we use it for Cargo's purposes
68
+ /// like naming directories or looking up configuration keys we only check the
69
+ /// file stem of JSON target files. For built-in rustc targets this is just an
70
+ /// uninterpreted string basically.
45
71
#[ derive( PartialEq , Eq , Hash , Debug , Clone , Copy , PartialOrd , Ord , Serialize ) ]
46
72
pub struct CompileTarget {
47
73
name : InternedString ,
@@ -71,10 +97,22 @@ impl CompileTarget {
71
97
Ok ( CompileTarget { name : name. into ( ) } )
72
98
}
73
99
100
+ /// Returns the full unqualified name of this target, suitable for passing
101
+ /// to `rustc` directly.
102
+ ///
103
+ /// Typically this is pretty much the same as `short_name`, but for the case
104
+ /// of JSON target files this will be a full canonicalized path name for the
105
+ /// current filesystem.
74
106
pub fn rustc_target ( & self ) -> & str {
75
107
& self . name
76
108
}
77
109
110
+ /// Returns a "short" version of the target name suitable for usage within
111
+ /// Cargo for configuration and such.
112
+ ///
113
+ /// This is typically the same as `rustc_target`, or the full name, but for
114
+ /// JSON target files this returns just the file stem (e.g. `foo` out of
115
+ /// `foo.json`) instead of the full path.
78
116
pub fn short_name ( & self ) -> & str {
79
117
// Flexible target specifications often point at json files, so if it
80
118
// looks like we've got one of those just use the file stem (the file
0 commit comments