From f657c90a3fb823d798426842ce3f4848c0841d5e Mon Sep 17 00:00:00 2001 From: Ybeichen Date: Sun, 3 Mar 2024 12:20:14 +0800 Subject: [PATCH] Bug fixed: 1.Apply src_only logic only to files 2.Change the exe link order --- doc/ruxgo_book/src/guide/target_module.md | 2 +- src/builder.rs | 37 +++++++++++------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/doc/ruxgo_book/src/guide/target_module.md b/doc/ruxgo_book/src/guide/target_module.md index c1adbf8..7fd96bf 100644 --- a/doc/ruxgo_book/src/guide/target_module.md +++ b/doc/ruxgo_book/src/guide/target_module.md @@ -6,7 +6,7 @@ - `src`: 指定目标源代码的路径,会递归构建该目录下的所有源文件。 -- `src_only`: 可选。如果你只想使用`src`中的某些文件,可以在此处指定。 +- `src_only`: 可选。如果你只想使用`src`中的某些源文件,可以在此处指定。 - `src_exclude`: 可选。如果你想要排除`src`中的某些源文件或目录,可以在此处指定。 diff --git a/src/builder.rs b/src/builder.rs index 028e18a..0b57e3a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -134,8 +134,8 @@ impl<'a> Target<'a> { std::process::exit(1); } log(LogLevel::Info, &format!("Adding dependant lib: {}", dep_lib.target_config.name)); - if !dep_lib.target_config.name.starts_with("lib") { - log(LogLevel::Error, "Dependant lib name must start with lib"); + if dep_lib.target_config.typ == "dll" && !dep_lib.target_config.name.starts_with("lib") { + log(LogLevel::Error, "Dependant dll lib name must start with lib"); log(LogLevel::Error, &format!("Target: {} does not start with lib", dep_lib.target_config.name)); std::process::exit(1); } @@ -510,9 +510,6 @@ impl<'a> Target<'a> { cmd.push_str(obj); } cmd.push_str(" "); - cmd.push_str(&self.target_config.ldflags); - cmd.push_str(" "); - // link other dependant libraries for dep_target in dep_targets { if dep_target.target_config.typ == "object" || dep_target.target_config.typ == "static" { @@ -535,6 +532,7 @@ impl<'a> Target<'a> { cmd.push_str(" "); } } + cmd.push_str(&self.target_config.ldflags); } (cmd, cmd_bin) @@ -661,17 +659,6 @@ impl<'a> Target<'a> { let entry = entry.unwrap(); let path = entry.path().to_str().unwrap().to_string().replace("\\", "/"); // if windows's path - // Inclusion logic: Check if the path is in src_only - let include = if !src_only.is_empty() { - src_only.iter().any(|&included| path.contains(included)) - } else { - true // If src_only is empty, include all - }; - if !include { - log(LogLevel::Debug, &format!("Excluding (not in src_only): {}", path)); - continue; - } - // Exclusion logic: Check if the path is in src_exclude let exclude = src_exclude.iter().any(|&excluded| path.contains(excluded)); if exclude { @@ -682,10 +669,21 @@ impl<'a> Target<'a> { if entry.path().is_dir() { srcs.append(&mut self.get_srcs(&path)); } else { - if !path.ends_with(".cpp") && !path.ends_with(".c") { + // Inclusion logic: Apply src_only logic only to files + let include = if !src_only.is_empty() { + src_only.iter().any(|&included| path.contains(included)) + } else { + true // If src_only is empty, include all + }; + + if !include { + log(LogLevel::Debug, &format!("Excluding (not in src_only): {}", path)); continue; } - self.add_src(path); + + if path.ends_with(".cpp") || path.ends_with(".c") { + self.add_src(path); + } } } @@ -715,6 +713,7 @@ impl<'a> Target<'a> { obj_name.push_str(OBJ_DIR); obj_name.push_str("/"); obj_name.push_str(&self.target_config.name); + obj_name.push_str("-"); obj_name.push_str(src_name); obj_name.push_str(".o"); obj_name @@ -900,7 +899,7 @@ impl Src { if stderr.len() > 0 { return Some(stderr.to_string()); } - return None; + None } else { log(LogLevel::Error, &format!(" Error: {}", &self.name)); log(LogLevel::Error, &format!(" Command: {}", &cmd));