Skip to content

Commit

Permalink
If the bootloader has a feature named binary, enable it
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phil-opp committed Jul 18, 2019
1 parent 8c9bbd8 commit 3d967dc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/builder.rs
Expand Up @@ -166,7 +166,7 @@ impl Builder {
"bootloader manifest has no target directory".into(),
),
)?;
let bootloader_target = {
let (bootloader_target, binary_feature) = {
let cargo_toml_content = fs::read_to_string(&bootloader_pkg.manifest_path)
.map_err(|err| format!("bootloader has no valid Cargo.toml: {}", err))
.map_err(CreateBootimageError::BootloaderInvalid)?;
Expand All @@ -185,7 +185,13 @@ impl Builder {
(If you're using the official bootloader crate, you need at least version 0.5.1)"
.into(),
))?;
bootloader_root.join(target_str)

let binary_feature = cargo_toml
.get("features")
.and_then(|f| f.get("binary"))
.is_some();

(bootloader_root.join(target_str), binary_feature)
};
let bootloader_features =
{
Expand All @@ -201,7 +207,11 @@ impl Builder {
.ok_or(CreateBootimageError::CargoMetadataIncomplete {
key: format!("resolve[\"{}\"]", bootloader_name),
})?;
bootloader_resolve.features.clone()
let mut features = bootloader_resolve.features.clone();
if binary_feature {
features.push("binary".into());
}
features
};

// build bootloader
Expand Down

0 comments on commit 3d967dc

Please sign in to comment.