Skip to content

Commit

Permalink
Bug fixed:
Browse files Browse the repository at this point in the history
1.Apply src_only logic only to files
2.Change the exe link order
  • Loading branch information
BeichenY1 committed Mar 3, 2024
1 parent b03e2f3 commit f657c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion doc/ruxgo_book/src/guide/target_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- `src`: 指定目标源代码的路径,会递归构建该目录下的所有源文件。

- `src_only`: 可选。如果你只想使用`src`中的某些文件,可以在此处指定。
- `src_only`: 可选。如果你只想使用`src`中的某些源文件,可以在此处指定。

- `src_exclude`: 可选。如果你想要排除`src`中的某些源文件或目录,可以在此处指定。

Expand Down
37 changes: 18 additions & 19 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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" {
Expand All @@ -535,6 +532,7 @@ impl<'a> Target<'a> {
cmd.push_str(" ");
}
}
cmd.push_str(&self.target_config.ldflags);
}

(cmd, cmd_bin)
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit f657c90

Please sign in to comment.