Skip to content

Commit 11501a4

Browse files
committed
Use config.build_command instead of rlibc heuristic
This is a breaking change since it changes the default build command to `cargo build`.
1 parent 2e680f9 commit 11501a4

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/bin/cargo-bootimage.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Context, Result};
22
use bootimage::{
33
args::{BuildArgs, BuildCommand},
44
builder::Builder,
5-
help,
5+
config, help,
66
};
77
use std::{
88
env,
@@ -43,9 +43,10 @@ pub fn main() -> Result<()> {
4343

4444
fn build(args: BuildArgs) -> Result<()> {
4545
let mut builder = Builder::new(args.manifest_path().map(PathBuf::from))?;
46+
let config = config::read_config(builder.manifest_path())?;
4647
let quiet = args.quiet();
4748

48-
let executables = builder.build_kernel(&args.cargo_args(), quiet)?;
49+
let executables = builder.build_kernel(&args.cargo_args(), &config, quiet)?;
4950
if executables.is_empty() {
5051
return Err(anyhow!("no executables built"));
5152
}

src/builder/mod.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Provides functions to build the kernel and the bootloader.
22
3+
use crate::config::Config;
34
use cargo_metadata::Metadata;
45
use error::{BootloaderError, BuildKernelError, BuilderError, CreateBootimageError};
56
use std::{
@@ -46,27 +47,17 @@ impl Builder {
4647
pub fn build_kernel(
4748
&mut self,
4849
args: &[String],
50+
config: &Config,
4951
quiet: bool,
5052
) -> Result<Vec<PathBuf>, BuildKernelError> {
5153
if !quiet {
5254
println!("Building kernel");
5355
}
5456

55-
let build_arg = if self
56-
.project_metadata()
57-
.ok()
58-
.and_then(|m| m.packages.iter().find(|p| p.name == "rlibc"))
59-
.is_some()
60-
{
61-
"build"
62-
} else {
63-
"xbuild"
64-
};
65-
6657
// try to run cargo xbuild
6758
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
6859
let mut cmd = process::Command::new(&cargo);
69-
cmd.arg(build_arg);
60+
cmd.args(&config.build_command);
7061
cmd.args(args);
7162
if !quiet {
7263
cmd.stdout(process::Stdio::inherit());
@@ -77,7 +68,7 @@ impl Builder {
7768
error: err,
7869
})?;
7970
if !output.status.success() {
80-
if build_arg == "xbuild" {
71+
if config.build_command.starts_with(&["xbuild".into()]) {
8172
// try executing `cargo xbuild --help` to check whether cargo-xbuild is installed
8273
let mut help_command = process::Command::new("cargo");
8374
help_command.arg("xbuild").arg("--help");
@@ -96,7 +87,7 @@ impl Builder {
9687

9788
// Retrieve binary paths
9889
let mut cmd = process::Command::new(cargo);
99-
cmd.arg(build_arg);
90+
cmd.args(&config.build_command);
10091
cmd.args(args);
10192
cmd.arg("--message-format").arg("json");
10293
let output = cmd.output().map_err(|err| BuildKernelError::Io {

src/config.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use toml::Value;
1212
#[derive(Debug, Clone)]
1313
#[non_exhaustive]
1414
pub struct Config {
15-
/// The command that is used for building the kernel for `cargo bootimage`.
15+
/// The cargo subcommand that is used for building the kernel for `cargo bootimage`.
1616
///
17-
/// Defaults to `cargo build`.
17+
/// Defaults to `build`.
1818
pub build_command: Vec<String>,
1919
/// The run command that is invoked on `bootimage run` or `bootimage runner`
2020
///
@@ -128,9 +128,7 @@ struct ConfigBuilder {
128128
impl Into<Config> for ConfigBuilder {
129129
fn into(self) -> Config {
130130
Config {
131-
build_command: self
132-
.build_command
133-
.unwrap_or(vec!["cargo".into(), "build".into()]),
131+
build_command: self.build_command.unwrap_or(vec!["build".into()]),
134132
run_command: self.run_command.unwrap_or_else(|| {
135133
vec![
136134
"qemu-system-x86_64".into(),

0 commit comments

Comments
 (0)