Skip to content

Commit 1b36ddc

Browse files
committed
minor cleanup
1 parent 236fe87 commit 1b36ddc

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/cargo/core/compiler/custom_build.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
269269
}
270270
})
271271
.collect::<Vec<_>>();
272-
let library_name = unit
273-
.pkg
274-
.targets()
275-
.iter()
276-
.find(|t| t.is_lib())
277-
.map(|t| t.crate_name());
272+
let library_name = unit.pkg.library().map(|t| t.crate_name());
278273
let pkg_descr = unit.pkg.to_string();
279274
let build_script_outputs = Arc::clone(&cx.build_script_outputs);
280275
let id = unit.pkg.package_id();
@@ -881,11 +876,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
881876
(
882877
BuildOutput::parse_file(
883878
&output_file,
884-
unit.pkg
885-
.targets()
886-
.iter()
887-
.find(|t| t.is_lib())
888-
.map(|t| t.crate_name()),
879+
unit.pkg.library().map(|t| t.crate_name()),
889880
&unit.pkg.to_string(),
890881
&prev_script_out_dir,
891882
&script_out_dir,

src/cargo/core/package.rs

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ impl Package {
151151
pub fn targets(&self) -> &[Target] {
152152
self.manifest().targets()
153153
}
154+
/// Gets the library crate for this package, if it exists.
155+
pub fn library(&self) -> Option<&Target> {
156+
self.targets().iter().find(|t| t.is_lib())
157+
}
154158
/// Gets the current package version.
155159
pub fn version(&self) -> &Version {
156160
self.package_id().version()

0 commit comments

Comments
 (0)