Skip to content

Commit f745ca7

Browse files
committed
Address review about doc blocks
1 parent ef425b7 commit f745ca7

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,24 @@ pub struct BuildContext<'a, 'cfg> {
3131
pub extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
3232
pub packages: &'a PackageSet<'cfg>,
3333

34-
/// Information about the compiler.
34+
/// Source of interning new units as they're created.
35+
pub units: &'a UnitInterner<'a>,
36+
37+
/// Information about the compiler that we've detected on the local system.
3538
pub rustc: Rustc,
36-
/// Build information for the host arch.
39+
40+
/// Build information for the "host", which is information about when
41+
/// `rustc` is invoked without a `--target` flag. This is used for
42+
/// procedural macros, build scripts, etc.
3743
host_config: TargetConfig,
38-
/// Build information for the target.
44+
host_info: TargetInfo,
45+
46+
/// Build information for targets that we're building for. This will be
47+
/// empty if the `--target` flag is not passed, and currently also only ever
48+
/// has at most one entry, but eventually we'd like to support multi-target
49+
/// builds with Cargo.
3950
target_config: HashMap<CompileTarget, TargetConfig>,
4051
target_info: HashMap<CompileTarget, TargetInfo>,
41-
host_info: TargetInfo,
42-
pub units: &'a UnitInterner<'a>,
4352
}
4453

4554
impl<'a, 'cfg> BuildContext<'a, 'cfg> {

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct TargetInfo {
3636
pub rustdocflags: Vec<String>,
3737
}
3838

39-
/// CompileKind of each file generated by a Unit, part of `FileType`.
39+
/// Kind of each file generated by a Unit, part of `FileType`.
4040
#[derive(Clone, PartialEq, Eq, Debug)]
4141
pub enum FileFlavor {
4242
/// Not a special file type.

src/cargo/core/compiler/compile_kind.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ use crate::util::errors::{CargoResult, CargoResultExt};
44
use serde::Serialize;
55
use std::path::Path;
66

7-
/// Indicates whether an object is for the host architcture or the target architecture.
7+
/// Indicator for how a unit is being compiled.
88
///
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.
1013
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord, Serialize)]
1114
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.
1218
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.
1322
Target(CompileTarget),
1423
}
1524

@@ -42,6 +51,23 @@ impl CompileKind {
4251
}
4352
}
4453

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.
4571
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord, Serialize)]
4672
pub struct CompileTarget {
4773
name: InternedString,
@@ -71,10 +97,22 @@ impl CompileTarget {
7197
Ok(CompileTarget { name: name.into() })
7298
}
7399

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.
74106
pub fn rustc_target(&self) -> &str {
75107
&self.name
76108
}
77109

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.
78116
pub fn short_name(&self) -> &str {
79117
// Flexible target specifications often point at json files, so if it
80118
// looks like we've got one of those just use the file stem (the file

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ fn build_deps_args<'a, 'cfg>(
924924

925925
// Be sure that the host path is also listed. This'll ensure that proc macro
926926
// dependencies are correctly found (for reexported macros).
927-
if let CompileKind::Target(_) = unit.kind {
927+
if !unit.kind.is_host() {
928928
cmd.arg("-L").arg(&{
929929
let mut deps = OsString::from("dependency=");
930930
deps.push(cx.files().host_deps());

0 commit comments

Comments
 (0)