Skip to content

Commit 3d967dc

Browse files
committed
If the bootloader has a feature named binary, enable it
This allows the bootloader to define dependencies that only apply to the main.rs (not the lib.rs), in order to reduce compile times. See rust-lang/cargo#1982 (comment) for more information.
1 parent 8c9bbd8 commit 3d967dc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/builder.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Builder {
166166
"bootloader manifest has no target directory".into(),
167167
),
168168
)?;
169-
let bootloader_target = {
169+
let (bootloader_target, binary_feature) = {
170170
let cargo_toml_content = fs::read_to_string(&bootloader_pkg.manifest_path)
171171
.map_err(|err| format!("bootloader has no valid Cargo.toml: {}", err))
172172
.map_err(CreateBootimageError::BootloaderInvalid)?;
@@ -185,7 +185,13 @@ impl Builder {
185185
(If you're using the official bootloader crate, you need at least version 0.5.1)"
186186
.into(),
187187
))?;
188-
bootloader_root.join(target_str)
188+
189+
let binary_feature = cargo_toml
190+
.get("features")
191+
.and_then(|f| f.get("binary"))
192+
.is_some();
193+
194+
(bootloader_root.join(target_str), binary_feature)
189195
};
190196
let bootloader_features =
191197
{
@@ -201,7 +207,11 @@ impl Builder {
201207
.ok_or(CreateBootimageError::CargoMetadataIncomplete {
202208
key: format!("resolve[\"{}\"]", bootloader_name),
203209
})?;
204-
bootloader_resolve.features.clone()
210+
let mut features = bootloader_resolve.features.clone();
211+
if binary_feature {
212+
features.push("binary".into());
213+
}
214+
features
205215
};
206216

207217
// build bootloader

0 commit comments

Comments
 (0)