Skip to content

Commit

Permalink
Change ruxos_bld to ruxgo_bld and other optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
BeichenY1 committed Feb 6, 2024
1 parent e147273 commit b20b5e9
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/Nomu_Engine
*.hash
compile_commands.json
ruxos_bld
ruxgo_bld
sqlite-amalgamation-3410100
file.sqlite
dump.rdb
iperf
ruxos_pkg
ruxgo_pkg
my_project
4 changes: 2 additions & 2 deletions doc/ruxgo_book/src/commands/ruxgo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ ruxgo -b [--path <路径>] [--gen-cc] [--gen-vsc]

## 命令行为

当执行 `ruxgo -b` 命令后,将会在当前目录下创建一个名为 `ruxos_bld/` 的构建目录,包括以下内容:
当执行 `ruxgo -b` 命令后,将会在当前目录下创建一个名为 `ruxgo_bld/` 的构建目录,包括以下内容:

```bash
ruxos_bld/
ruxgo_bld/
├── bin/
├── obj_linux/ 或 obj_win32/
├── target/
Expand Down
2 changes: 1 addition & 1 deletion doc/ruxgo_book/src/commands/ruxgo-pkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ruxgo pkg [选项]
- `--clean-all`: 清理所有软件包。
- `-h, --help`: 打印帮助信息。

下载的文件保存在 `ruxos_pkg/` 目录中,具体内容如下:
下载的文件保存在 `ruxgo_pkg/` 目录中,具体内容如下:

- `app-bin/`: 存放 app 可执行文件及其对应脚本。
- `ruxos/`: ruxos 存储位置。
Expand Down
2 changes: 1 addition & 1 deletion doc/ruxgo_book/src/guide/ruxgo_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Ruxgo 设计充分考虑构建过程的效率、可靠性和可维护性,同

- **构建过程模块化**:构建过程以 Target 为中心,按照不同的 Target 模块来配置源文件和依赖库。构建应用程序可以像搭积木一样进行。

- **源码和构建目录分离**:构建过程中生成的中间文件都会被放置在构建目录`ruxos_bld/`中,防止构建过程中文件冲突和混乱。
- **源码和构建目录分离**:构建过程中生成的中间文件都会被放置在构建目录`ruxgo_bld/`中,防止构建过程中文件冲突和混乱。

- **友好的编译错误诊断**:使用更友好的编译器错误输出显示,包括清晰的错误提示、指向源代码行数等信息。
26 changes: 13 additions & 13 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use std::sync::{Arc, Mutex};
use indicatif::{ProgressBar, ProgressStyle};
use colored::Colorize;

static BUILD_DIR: &str = "ruxos_bld";
static BIN_DIR: &str = "ruxos_bld/bin";
static BUILD_DIR: &str = "ruxgo_bld";
static BIN_DIR: &str = "ruxgo_bld/bin";
#[cfg(target_os = "windows")]
static OBJ_DIR: &str = "ruxos_bld/obj_win32";
static OBJ_DIR: &str = "ruxgo_bld/obj_win32";
#[cfg(target_os = "linux")]
static OBJ_DIR: &str = "ruxos_bld/obj_linux";
static OBJ_DIR: &str = "ruxgo_bld/obj_linux";

// ruxlibc info and ld script
lazy_static! {
Expand All @@ -42,12 +42,12 @@ lazy_static! {
}
};
}
static RUXLIBC_BIN: &str = "ruxos_bld/bin/libc.a";
static RUXLIBC_BIN: &str = "ruxgo_bld/bin/libc.a";
static RUXLIBC_RUST_LIB: &str = "libruxlibc.a";

// ruxmusl info
static RUXMUSL_INC: &str = "ruxos_bld/ruxmusl/install/include";
static RUXMUSL_BIN: &str = "ruxos_bld/ruxmusl/install/lib/libc.a";
static RUXMUSL_INC: &str = "ruxgo_bld/ruxmusl/install/include";
static RUXMUSL_BIN: &str = "ruxgo_bld/ruxmusl/install/lib/libc.a";
static RUXMUSL_RUST_LIB: &str = "libruxmusl.a";

/// Represents a target
Expand Down Expand Up @@ -112,9 +112,9 @@ impl<'a> Target<'a> {
_ => (),
}
#[cfg(target_os = "windows")]
let hash_file_path = format!("ruxos_bld/{}.win32.hash", &target_config.name);
let hash_file_path = format!("ruxgo_bld/{}.win32.hash", &target_config.name);
#[cfg(target_os = "linux")]
let hash_file_path = format!("ruxos_bld/{}.linux.hash", &target_config.name);
let hash_file_path = format!("ruxgo_bld/{}.linux.hash", &target_config.name);
let path_hash = Hasher::load_hashes_from_file(&hash_file_path);
let mut dependant_libs = Vec::new();

Expand Down Expand Up @@ -266,7 +266,7 @@ impl<'a> Target<'a> {
return;
}

// Add progress bar
// Parallel built
let progress_bar = Arc::new(Mutex::new(ProgressBar::new(srcs_needed as u64)));
let num_complete = Arc::new(Mutex::new(0));
let src_hash_to_update = Arc::new(Mutex::new(Vec::new()));
Expand All @@ -281,8 +281,8 @@ impl<'a> Target<'a> {
}
src_hash_to_update.lock().unwrap().push(src);
log(LogLevel::Info, &format!("Compiled: {}", src.path));
// If the RUXOS_LOG_LEVEL is not "Info" or "Debug", update the compilation progress bar
let log_level = std::env::var("RUXOS_LOG_LEVEL").unwrap_or("".to_string());
// If the RUXGO_LOG_LEVEL is not "Info" or "Debug", update the compilation progress bar
let log_level = std::env::var("RUXGO_LOG_LEVEL").unwrap_or("".to_string());
if !(log_level == "Info" || log_level == "Debug") {
let mut num_complete = num_complete.lock().unwrap();
*num_complete += 1;
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<'a> Target<'a> {
.expect("failed to execute process");
if output.status.success() {
log(LogLevel::Log, "Linking successful");
Hasher::save_hashes_to_file(&self.hash_file_path, &self.path_hash);
Hasher::save_hashes_to_file(&self.hash_file_path, &self.path_hash); // ? check if repeated
} else {
log(LogLevel::Error, "Linking failed");
log(LogLevel::Error, &format!(" Command: {}", &cmd));
Expand Down
39 changes: 19 additions & 20 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ use std::fs;
use std::process::{Command, Stdio};
use crate::hasher::Hasher;

static BUILD_DIR: &str = "ruxos_bld";
static BIN_DIR: &str = "ruxos_bld/bin";
static BUILD_DIR: &str = "ruxgo_bld";
static BIN_DIR: &str = "ruxgo_bld/bin";
#[cfg(target_os = "windows")]
static OBJ_DIR: &str = "ruxos_bld/obj_win32";
static OBJ_DIR: &str = "ruxgo_bld/obj_win32";
#[cfg(target_os = "linux")]
static OBJ_DIR: &str = "ruxos_bld/obj_linux";
static TARGET_DIR: &str = "ruxos_bld/target";
static PACKAGES_DIR: &str = "ruxos_bld/packages";
static OBJ_DIR: &str = "ruxgo_bld/obj_linux";
static TARGET_DIR: &str = "ruxgo_bld/target";
static PACKAGES_DIR: &str = "ruxgo_bld/packages";

// OSConfig hash file
static OSCONFIG_HASH_FILE: &str = "ruxos_bld/os_config.hash";
static OSCONFIG_HASH_FILE: &str = "ruxgo_bld/os_config.hash";

// ruxlibc info
static RUXLIBC_BIN: &str = "ruxos_bld/bin/libc.a";
static RUXLIBC_HASH_PATH: &str = "ruxos_bld/libc.linux.hash";
static RUXLIBC_BIN: &str = "ruxgo_bld/bin/libc.a";
static RUXLIBC_HASH_PATH: &str = "ruxgo_bld/libc.linux.hash";
lazy_static! {
static ref RUXLIBC_SRC: String = {
let path1 = "../ruxos/ulib/ruxlibc/c";
Expand All @@ -38,7 +38,7 @@ lazy_static! {
}

// ruxmusl info
static RUXMUSL_DIR: &str = "ruxos_bld/ruxmusl";
static RUXMUSL_DIR: &str = "ruxgo_bld/ruxmusl";
lazy_static! {
static ref ULIB_RUXMUSL: String = {
let path1 = "../ruxos/ulib/ruxmusl";
Expand Down Expand Up @@ -105,9 +105,9 @@ pub fn clean(targets: &Vec<TargetConfig>, os_config: &OSConfig, packages: &Vec<P
// removes local bins of targets
for target in targets {
#[cfg(target_os = "windows")]
let hash_path = format!("ruxos_bld/{}.win32.hash", &target.name);
let hash_path = format!("ruxgo_bld/{}.win32.hash", &target.name);
#[cfg(target_os = "linux")]
let hash_path = format!("ruxos_bld/{}.linux.hash", &target.name);
let hash_path = format!("ruxgo_bld/{}.linux.hash", &target.name);
remove_file(&hash_path);
if Path::new(BIN_DIR).exists() {
let mut bin_name = format!("{}/{}", BIN_DIR, target.name);
Expand Down Expand Up @@ -137,9 +137,9 @@ pub fn clean(targets: &Vec<TargetConfig>, os_config: &OSConfig, packages: &Vec<P
for pack in packages {
for target in &pack.target_configs {
#[cfg(target_os = "windows")]
let hash_path = format!("ruxos_bld/{}.win32.hash", &target.name);
let hash_path = format!("ruxgo_bld/{}.win32.hash", &target.name);
#[cfg(target_os = "linux")]
let hash_path = format!("ruxos_bld/{}.linux.hash", &target.name);
let hash_path = format!("ruxgo_bld/{}.linux.hash", &target.name);
remove_file(&hash_path);
if Path::new(BIN_DIR).exists() {
let mut bin_name = format!("{}/{}", BIN_DIR, target.name);
Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn build(
) {
if !Path::new(BUILD_DIR).exists() {
fs::create_dir(BUILD_DIR).unwrap_or_else(|why| {
log(LogLevel::Error, &format!("Could not create ruxos_bld directory: {}", why));
log(LogLevel::Error, &format!("Could not create ruxgo_bld directory: {}", why));
std::process::exit(1);
});
}
Expand Down Expand Up @@ -330,9 +330,8 @@ pub fn build(

let mut config_changed = false;

// Constructs os and ulib
// Checks and constructs os and ulib based on the os_config changes.
if os_config != &OSConfig::default() {
// check if the hash has changed and update if necessary
let os_config_str = serde_json::to_string(os_config).unwrap_or_else(|_| "".to_string());
let current_hash = Hasher::hash_string(&os_config_str);
let old_hash = Hasher::read_hash_from_file(OSCONFIG_HASH_FILE);
Expand All @@ -353,7 +352,7 @@ pub fn build(
}
};

// Constructs each target separately
// Constructs each target separately based on the os_config changes.
for target in targets {
let mut tgt = Target::new(build_config, os_config, target, targets, packages);

Expand Down Expand Up @@ -483,7 +482,7 @@ fn build_ruxmusl(build_config: &BuildConfig, os_config: &OSConfig) {
.wait().expect("Failed to wait for command");
}

// create ruxos_bld/ruxmusl
// create ruxgo_bld/ruxmusl
fs::create_dir_all(RUXMUSL_DIR).unwrap_or_else(|why| {
log(LogLevel::Error, &format!("Couldn't create build dir: {}", why));
std::process::exit(1);
Expand Down Expand Up @@ -843,7 +842,7 @@ pub fn init_project(project_name: &str, is_c: Option<bool>, config: &GlobalConfi
std::process::exit(1);
});
gitignore_file
.write_all(b"ruxos_bld\ncompile_commands.json\n.cache\n")
.write_all(b"ruxgo_bld\ncompile_commands.json\n.cache\n")
.unwrap_or_else(|why| {
log(LogLevel::Error, &format!("Could not write to .gitignore: {}", why));
std::process::exit(1);
Expand Down
6 changes: 3 additions & 3 deletions src/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use std::error::Error;

static PACKAGES_URL: &str = "https://mirror.ghproxy.com/https://raw.githubusercontent.com/Ybeichen/ruxos-pkgs/master/";
static SYSWONDER_URL: &str = "https://mirror.ghproxy.com/https://github.com/syswonder";
static PKG_DIR: &str = "ruxos_pkg";
static BIN_DIR: &str = "ruxos_pkg/app-bin";
static CACHE_DIR: &str = "ruxos_pkg/cache";
static PKG_DIR: &str = "ruxgo_pkg";
static BIN_DIR: &str = "ruxgo_pkg/app-bin";
static CACHE_DIR: &str = "ruxgo_pkg/cache";

/// Enum describing the Package type
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ impl Package {
let repo = deets[0].to_string().replace(",", "");
let branch = deets[1].to_string();
let name = repo.split("/").collect::<Vec<&str>>()[1].to_string();
let source_dir = format!("./ruxos_bld/packages/{}/", name);
let source_dir = format!("./ruxgo_bld/packages/{}/", name);
let mut sub_packages: Vec<Package> = Vec::new();
// git clone packages
if !Path::new(&source_dir).exists() {
Expand Down

0 comments on commit b20b5e9

Please sign in to comment.