Skip to content

Commit 21aa8e4

Browse files
authored
Merge pull request #62 from rust-osdev/Zbuild-std
Add support for building bootloaders using `-Zbuild-std`
2 parents 57983ec + d28fe8c commit 21aa8e4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/builder/bootloader.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct BuildConfig {
1414
target_dir: PathBuf,
1515
kernel_bin_path: PathBuf,
1616
kernel_manifest_path: PathBuf,
17+
build_std: Option<String>,
1718
}
1819

1920
impl BuildConfig {
@@ -54,6 +55,19 @@ impl BuildConfig {
5455
.into(),
5556
)
5657
})?;
58+
let build_std = {
59+
let key = metadata
60+
.and_then(|t| t.get("bootloader"))
61+
.and_then(|t| t.get("build-std"));
62+
if let Some(key) = key {
63+
let err_msg = "A non-string `package.metadata.bootloader.build-std` key found in \
64+
Cargo.toml of bootloader";
65+
let err = || BootloaderError::BootloaderInvalid(err_msg.into());
66+
Some(key.as_str().ok_or_else(err)?.into())
67+
} else {
68+
None
69+
}
70+
};
5771

5872
let binary_feature = cargo_toml
5973
.get("features")
@@ -90,14 +104,19 @@ impl BuildConfig {
90104
target_dir,
91105
kernel_manifest_path: kernel_pkg.manifest_path.clone(),
92106
kernel_bin_path: kernel_bin_path.to_owned(),
107+
build_std,
93108
})
94109
}
95110

96111
/// Creates the cargo build command for building the bootloader.
97112
pub fn build_command(&self) -> Command {
98113
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
99114
let mut cmd = Command::new(&cargo);
100-
cmd.arg("xbuild");
115+
if let Some(build_std) = &self.build_std {
116+
cmd.arg("build").arg(&format!("-Zbuild-std={}", build_std));
117+
} else {
118+
cmd.arg("xbuild");
119+
}
101120
cmd.arg("--manifest-path");
102121
cmd.arg(&self.manifest_path);
103122
cmd.arg("--bin").arg(&self.bootloader_name);

0 commit comments

Comments
 (0)