Skip to content

Commit a7efa91

Browse files
committed
Move features to Unit.
1 parent 531c4bf commit a7efa91

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub enum CompileMode {
156156
/// a test.
157157
Check { test: bool },
158158
/// Used to indicate benchmarks should be built. This is not used in
159-
/// `Target`, because it is essentially the same as `Test` (indicating
159+
/// `Unit`, because it is essentially the same as `Test` (indicating
160160
/// `--test` should be passed to rustc) and by using `Test` instead it
161161
/// allows some de-duping of Units to occur.
162162
Bench,

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,7 @@ fn compute_metadata<'a, 'cfg>(
522522

523523
// Also mix in enabled features to our metadata. This'll ensure that
524524
// when changing feature sets each lib is separately cached.
525-
bcx.resolve
526-
.features_sorted(unit.pkg.package_id())
527-
.hash(&mut hasher);
525+
unit.features.hash(&mut hasher);
528526

529527
// Mix in the target-metadata of all the dependencies of this target.
530528
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
227227
});
228228
}
229229

230-
let feats = self.bcx.resolve.features(unit.pkg.package_id());
230+
let feats = &unit.features;
231231
if !feats.is_empty() {
232232
self.compilation
233233
.cfgs

src/cargo/core/compiler/context/unit_dependencies.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn compute_deps<'a, 'cfg, 'tmp>(
228228
t.is_bin() &&
229229
// Skip binaries with required features that have not been selected.
230230
t.required_features().unwrap_or(&no_required_features).iter().all(|f| {
231-
bcx.resolve.features(id).contains(f)
231+
unit.features.contains(&f.as_str())
232232
})
233233
})
234234
.map(|t| {
@@ -383,6 +383,7 @@ fn dep_build_script<'a>(
383383
bcx.profiles.get_profile_run_custom_build(&unit.profile),
384384
unit.kind,
385385
CompileMode::RunCustomBuild,
386+
bcx.resolve.features_sorted(unit.pkg.package_id()),
386387
);
387388

388389
(unit, UnitFor::new_build())
@@ -423,7 +424,8 @@ fn new_unit<'a>(
423424
bcx.build_config.release,
424425
);
425426

426-
bcx.units.intern(pkg, target, profile, kind, mode)
427+
let features = bcx.resolve.features_sorted(pkg.package_id());
428+
bcx.units.intern(pkg, target, profile, kind, mode, features)
427429
}
428430

429431
/// Fill in missing dependencies for units of the `RunCustomBuild`

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
190190

191191
// Be sure to pass along all enabled features for this package, this is the
192192
// last piece of statically known information that we have.
193-
for feat in bcx.resolve.features(unit.pkg.package_id()).iter() {
193+
for feat in &unit.features {
194194
cmd.env(&format!("CARGO_FEATURE_{}", super::envify(feat)), "1");
195195
}
196196

src/cargo/core/compiler/fingerprint.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,7 @@ fn calculate_normal<'a, 'cfg>(
10901090
// Note that .0 is hashed here, not .1 which is the cwd. That doesn't
10911091
// actually affect the output artifact so there's no need to hash it.
10921092
path: util::hash_u64(super::path_args(cx.bcx, unit).0),
1093-
features: format!(
1094-
"{:?}",
1095-
cx.bcx.resolve.features_sorted(unit.pkg.package_id())
1096-
),
1093+
features: format!("{:?}", unit.features),
10971094
deps,
10981095
local: Mutex::new(local),
10991096
memoized_hash: Mutex::new(None),

src/cargo/core/compiler/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,7 @@ fn link_targets<'a, 'cfg>(
408408
let package_id = unit.pkg.package_id();
409409
let profile = unit.profile;
410410
let unit_mode = unit.mode;
411-
let features = bcx
412-
.resolve
413-
.features_sorted(package_id)
414-
.into_iter()
415-
.map(|s| s.to_owned())
416-
.collect();
411+
let features = unit.features.iter().map(|s| s.to_string()).collect();
417412
let json_messages = bcx.build_config.emit_json();
418413
let executable = cx.get_executable(unit)?;
419414
let mut target = unit.target.clone();
@@ -630,7 +625,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
630625

631626
rustdoc.arg("-o").arg(doc_dir);
632627

633-
for feat in bcx.resolve.features_sorted(unit.pkg.package_id()) {
628+
for feat in &unit.features {
634629
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
635630
}
636631

@@ -913,10 +908,7 @@ fn build_base_args<'a, 'cfg>(
913908
cmd.arg("--cfg").arg("test");
914909
}
915910

916-
// We ideally want deterministic invocations of rustc to ensure that
917-
// rustc-caching strategies like sccache are able to cache more, so sort the
918-
// feature list here.
919-
for feat in bcx.resolve.features_sorted(unit.pkg.package_id()) {
911+
for feat in &unit.features {
920912
cmd.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
921913
}
922914

src/cargo/core/compiler/unit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub struct UnitInner<'a> {
4848
pub kind: Kind,
4949
/// The "mode" this unit is being compiled for. See [`CompileMode`] for more details.
5050
pub mode: CompileMode,
51+
/// The `cfg` features to enable for this unit.
52+
/// This must be sorted.
53+
pub features: Vec<&'a str>,
5154
}
5255

5356
impl UnitInner<'_> {
@@ -139,13 +142,15 @@ impl<'a> UnitInterner<'a> {
139142
profile: Profile,
140143
kind: Kind,
141144
mode: CompileMode,
145+
features: Vec<&'a str>,
142146
) -> Unit<'a> {
143147
let inner = self.intern_inner(&UnitInner {
144148
pkg,
145149
target,
146150
profile,
147151
kind,
148152
mode,
153+
features,
149154
});
150155
Unit { inner }
151156
}

src/cargo/ops/cargo_clean.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
9393
opts.release,
9494
)
9595
};
96-
units.push(bcx.units.intern(pkg, target, profile, *kind, *mode));
96+
let features = resolve.features_sorted(pkg.package_id());
97+
units.push(
98+
bcx.units
99+
.intern(pkg, target, profile, *kind, *mode, features),
100+
);
97101
}
98102
}
99103
}

src/cargo/ops/cargo_compile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ fn generate_targets<'a>(
652652
target_mode,
653653
bcx.build_config.release,
654654
);
655-
bcx.units.intern(pkg, target, profile, kind, target_mode)
655+
let features = bcx.resolve.features_sorted(pkg.package_id());
656+
bcx.units
657+
.intern(pkg, target, profile, kind, target_mode, features)
656658
};
657659

658660
// Create a list of proposed targets.

0 commit comments

Comments
 (0)