Skip to content

Commit

Permalink
Multithreaded builds OS and ulib
Browse files Browse the repository at this point in the history
  • Loading branch information
BeichenY1 committed Jan 1, 2024
1 parent 04473ec commit 376527a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ indicatif = "0.17.3"
clap = { version = "4.4.11", features = ["derive"] }
directories = "5.0.1"
serde = { version = "1.0.190", features = ["derive"] }
dialoguer = "0.11.0"
dialoguer = "0.11.0"
num_cpus = "1.16.0"
47 changes: 33 additions & 14 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::Path;
use std::io::Write;
use std::fs;
use std::process::{Command, Stdio};
extern crate num_cpus;

static ROOT_DIR: &str = "ruxos_bld";
static BUILD_DIR: &str = "ruxos_bld/bin";
Expand Down Expand Up @@ -342,18 +343,32 @@ pub fn build(

// Construct os and ulib
if os_config != &OSConfig::default() {
log(LogLevel::Log, &format!("Compiling OS: {}, Ulib: {} ", os_config.name, os_config.ulib));
let (rux_feats_final, lib_feats_final) = features::cfg_feat_addprefix(os_config);
if os_config.ulib == "ruxlibc" {
log(LogLevel::Log, &format!("Compiling OS: {}", os_config.name));
build_os(&os_config, &os_config.ulib, &rux_feats_final, &lib_feats_final);
log(LogLevel::Log, &format!("Compiling Ulib: {}", os_config.ulib));
build_ruxlibc(build_config, os_config, gen_cc);
} else if os_config.ulib == "ruxmusl" {
log(LogLevel::Log, &format!("Compiling OS: {}", os_config.name));
build_os(&os_config, &os_config.ulib, &rux_feats_final, &lib_feats_final);
log(LogLevel::Log, &format!("Compiling Ulib: {}", os_config.ulib));
build_ruxmusl(build_config, os_config);
}

// thread os
let os_config_clone = os_config.clone();
let rux_feats_final_clone = rux_feats_final.clone();
let lib_feats_final_clone = lib_feats_final.clone();
let thread_os = std::thread::spawn(move || {
build_os(&os_config_clone, &os_config_clone.ulib, &rux_feats_final_clone, &lib_feats_final_clone);
});

// thread ulib
let build_config_clone = build_config.clone();
let os_config_clone_ = os_config.clone();
let gen_cc_clone = gen_cc.clone();
let thread_ulib = std::thread::spawn(move || {
if os_config_clone_.ulib == "ruxlibc" {
build_ruxlibc(&build_config_clone, &os_config_clone_, gen_cc_clone);
} else if os_config_clone_.ulib == "ruxmusl" {
build_ruxmusl(&build_config_clone, &os_config_clone_);
}
});

// join thread
thread_os.join().expect("Thread OS panicked");
thread_ulib.join().expect("Thread Ulib panicked");
};

// Construct each target separately
Expand Down Expand Up @@ -394,9 +409,13 @@ fn build_os(os_config: &OSConfig, ulib: &str, rux_feats: &Vec<String>, lib_feats
};
// add features
let features = [&rux_feats[..], &lib_feats[..]].concat().join(" ");
// number of parallel jobs
let num_cores = num_cpus::get();
log(LogLevel::Debug, &format!("Num_cores: {}", num_cores));
// cmd
let cmd = format!(
"cargo build {} {} {} {} {} --features \"{}\"",
target, target_dir, mode, os_ulib, verbose, features
"cargo build {} {} {} {} {} --features \"{}\" -j {}",
target, target_dir, mode, os_ulib, verbose, features, num_cores
);
log(LogLevel::Info, &format!("Command: {}", cmd));
let output = Command::new("sh")
Expand Down Expand Up @@ -486,7 +505,7 @@ fn build_ruxmusl(build_config: &BuildConfig, os_config: &OSConfig) {
}

// compile and install ruxmusl
log(LogLevel::Log, "Musl source code is installing...");
log(LogLevel::Log, "Compiling and installing Musl...");
let make_output = Command::new("make")
.args(&["-j"])
.current_dir(RUXMUSL_DIR)
Expand Down
2 changes: 1 addition & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn cfg_feat_addprefix(os_config: &OSConfig) -> (Vec<String>, Vec<String>) {
"ruxlibc" => "ruxlibc/",
"ruxmusl" => "ruxmusl/",
_ => {
log(LogLevel::Error, "Invalid ulib value");
log(LogLevel::Error, "Ulib must be one of \"ruxlibc\" or \"ruxmusl\"");
std::process::exit(1);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct BuildConfig {
}

/// Struct descibing the OS config of the local project
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct OSConfig {
pub name: String,
pub features: Vec<String>,
Expand All @@ -87,7 +87,7 @@ pub struct OSConfig {
}

/// Struct descibing the platform config of the local project
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct PlatformConfig {
pub name: String,
pub arch: String,
Expand All @@ -101,7 +101,7 @@ pub struct PlatformConfig {
}

/// Struct descibing the qemu config of the local project
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct QemuConfig {
pub debug: String,
pub blk: String,
Expand Down

0 comments on commit 376527a

Please sign in to comment.