Skip to content

Commit 3ce65d6

Browse files
committed
Build with cargo build instead of xbuild if rlibc is a dependencyy
1 parent c4c9b93 commit 3ce65d6

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/builder/mod.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,29 @@ impl Builder {
4444
///
4545
/// If the quiet argument is set to true, all output to stdout is suppressed.
4646
pub fn build_kernel(
47-
&self,
47+
&mut self,
4848
args: &[String],
4949
quiet: bool,
5050
) -> Result<Vec<PathBuf>, BuildKernelError> {
5151
if !quiet {
5252
println!("Building kernel");
5353
}
5454

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+
5566
// try to run cargo xbuild
5667
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
5768
let mut cmd = process::Command::new(&cargo);
58-
cmd.arg("xbuild");
69+
cmd.arg(build_arg);
5970
cmd.args(args);
6071
if !quiet {
6172
cmd.stdout(process::Stdio::inherit());
@@ -66,14 +77,16 @@ impl Builder {
6677
error: err,
6778
})?;
6879
if !output.status.success() {
69-
// try executing `cargo xbuild --help` to check whether cargo-xbuild is installed
70-
let mut help_command = process::Command::new("cargo");
71-
help_command.arg("xbuild").arg("--help");
72-
help_command.stdout(process::Stdio::null());
73-
help_command.stderr(process::Stdio::null());
74-
if let Ok(help_exit_status) = help_command.status() {
75-
if !help_exit_status.success() {
76-
return Err(BuildKernelError::XbuildNotFound);
80+
if build_arg == "xbuild" {
81+
// try executing `cargo xbuild --help` to check whether cargo-xbuild is installed
82+
let mut help_command = process::Command::new("cargo");
83+
help_command.arg("xbuild").arg("--help");
84+
help_command.stdout(process::Stdio::null());
85+
help_command.stderr(process::Stdio::null());
86+
if let Ok(help_exit_status) = help_command.status() {
87+
if !help_exit_status.success() {
88+
return Err(BuildKernelError::XbuildNotFound);
89+
}
7790
}
7891
}
7992
return Err(BuildKernelError::XbuildFailed {
@@ -83,7 +96,7 @@ impl Builder {
8396

8497
// Retrieve binary paths
8598
let mut cmd = process::Command::new(cargo);
86-
cmd.arg("xbuild");
99+
cmd.arg(build_arg);
87100
cmd.args(args);
88101
cmd.arg("--message-format").arg("json");
89102
let output = cmd.output().map_err(|err| BuildKernelError::Io {

0 commit comments

Comments
 (0)