50 lines
1.6 KiB
Rust
50 lines
1.6 KiB
Rust
mod cmake_o;
|
|
mod config;
|
|
mod gcc;
|
|
mod utils;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use config::{BuildConfig, BuildConfigTrait};
|
|
|
|
pub fn build_project() {
|
|
let project_path = std::env::current_dir().unwrap();
|
|
println!("{:?}", project_path);
|
|
|
|
// 获取配置
|
|
let config: Box<dyn BuildConfigTrait> = Box::new(BuildConfig::new(
|
|
None,
|
|
// Some(PathBuf::from(r"C:\Program Files\CodeBlocks\MinGW")),
|
|
PathBuf::from(project_path),
|
|
String::from("HelloWorld"),
|
|
));
|
|
|
|
// 递归所有src目录下的.c/.cpp文件并编译为.o文件输出到@/target/o目录下
|
|
let mut file_set: Vec<PathBuf> = Vec::new(); // 所有应临时存储的文件路径集合
|
|
println!(
|
|
"{}: start to compile 开始编译 step: 1/2",
|
|
crate::PROJECT_NAME
|
|
);
|
|
std::fs::create_dir_all(config.getpath_target_o()).unwrap(); // 先创建这层目录
|
|
cmake_o::cmake_o(&config, PathBuf::from(config.getpath_src()), &mut file_set).unwrap();
|
|
|
|
// 遍历@/target/o联合编译到@/target/bin中
|
|
println!(
|
|
"{}: start to compile 开始编译 step: 2/2",
|
|
crate::PROJECT_NAME
|
|
);
|
|
std::fs::create_dir_all(config.getpath_target_bin()).unwrap(); // 先创建这层目录
|
|
if PathBuf::from(config.getpath_target_file()).exists() {
|
|
std::fs::remove_file(config.getpath_target_file()).unwrap(); // 先删除目标文件
|
|
}
|
|
gcc::make_o_files_to_bin(
|
|
config.getpath_gpp(),
|
|
&mut file_set,
|
|
config.getpath_target_file(),
|
|
)
|
|
.unwrap();
|
|
|
|
// 删除@/target/o文件夹
|
|
std::fs::remove_dir_all(config.getpath_target_o()).unwrap();
|
|
}
|