first version of init done
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/test
|
||||
9
c_config.toml
Normal file
9
c_config.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
[general]
|
||||
target = "test"
|
||||
main = "main.c"
|
||||
|
||||
[build]
|
||||
build_dir = "build"
|
||||
cc = "gcc"
|
||||
cflags = "-Wall"
|
||||
@@ -56,7 +56,7 @@ impl Compiler {
|
||||
|
||||
let o_path_strip = o_path_dir.to_str().unwrap();
|
||||
|
||||
println!("Compiling {}", file);
|
||||
println!("Compiling {file}");
|
||||
|
||||
let mut c_path = path::Path::new(&file).parent().unwrap().components();
|
||||
c_path.next();
|
||||
@@ -85,7 +85,7 @@ impl Compiler {
|
||||
);
|
||||
|
||||
if verbose {
|
||||
println!("{}", command);
|
||||
println!("{command}");
|
||||
}
|
||||
|
||||
o_s.push(o_path_strip.to_string());
|
||||
@@ -96,10 +96,10 @@ impl Compiler {
|
||||
let stderr = std::str::from_utf8(&out.stderr).unwrap();
|
||||
|
||||
if !stdout.is_empty() {
|
||||
println!("{}", stdout);
|
||||
println!("{stdout}");
|
||||
}
|
||||
if !stderr.is_empty() {
|
||||
println!("{}", stderr);
|
||||
println!("{stderr}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ impl Compiler {
|
||||
);
|
||||
|
||||
for o_file in o_s {
|
||||
link_command = format!("{} {}", link_command, o_file);
|
||||
link_command = format!("{link_command} {o_file}");
|
||||
}
|
||||
|
||||
let target_path = path::Path::new(&self.path).join(&self.config.general.target);
|
||||
@@ -125,7 +125,7 @@ impl Compiler {
|
||||
println!("Building {}", target_path.to_str().unwrap());
|
||||
|
||||
if verbose {
|
||||
println!("{}", link_command);
|
||||
println!("{link_command}");
|
||||
}
|
||||
|
||||
let out = Command::new("sh")
|
||||
@@ -138,10 +138,10 @@ impl Compiler {
|
||||
let stderr = std::str::from_utf8(&out.stderr).unwrap();
|
||||
|
||||
if !stdout.is_empty() {
|
||||
println!("{}", stdout);
|
||||
println!("{stdout}");
|
||||
}
|
||||
if !stderr.is_empty() {
|
||||
println!("{}", stderr);
|
||||
println!("{stderr}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +164,8 @@ impl Compiler {
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
println!("{scanned_files:?}");
|
||||
|
||||
(src_file, header_files)
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ impl Compiler {
|
||||
let mut inc_string = "".to_string();
|
||||
|
||||
for inc_dir in self.inc_dirs.clone() {
|
||||
inc_string = format!("{} -I{}", inc_string, inc_dir);
|
||||
inc_string = format!("{inc_string} -I{inc_dir}");
|
||||
}
|
||||
|
||||
inc_string
|
||||
|
||||
37
src/init.rs
37
src/init.rs
@@ -1,7 +1,40 @@
|
||||
use std::{fs, path};
|
||||
use std::{fs, io::Write, path};
|
||||
|
||||
pub fn init(path: String) {
|
||||
println!("Creating {}", path);
|
||||
println!("Creating {path}");
|
||||
fs::create_dir(path.clone()).unwrap();
|
||||
fs::create_dir(path::Path::new(&path).join("src")).unwrap();
|
||||
let mut conf_file = fs::File::create(path::Path::new(&path).join("c_config.toml")).unwrap();
|
||||
conf_file
|
||||
.write_all(
|
||||
format!(
|
||||
r#"[general]
|
||||
target = "{path}"
|
||||
main = "src/main.c"
|
||||
|
||||
[build]
|
||||
build_dir = "build"
|
||||
cc = "gcc"
|
||||
cflags = "-Wall"
|
||||
"#
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
conf_file.flush().unwrap();
|
||||
|
||||
let mut main_file =
|
||||
fs::File::create(path::Path::new(&path).join("src").join("main.c")).unwrap();
|
||||
main_file
|
||||
.write_all(
|
||||
r#"#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Hello world!\n");
|
||||
}
|
||||
"#
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
main_file.flush().unwrap();
|
||||
}
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -61,8 +61,15 @@ fn main() {
|
||||
} else {
|
||||
let conf_path = path::Path::new(args.path.as_str()).join("c_config.toml");
|
||||
|
||||
let contents = fs::read_to_string(conf_path.clone())
|
||||
.unwrap_or_else(|_| panic!("Couldn't read {}", conf_path.to_str().unwrap()));
|
||||
// let contents = fs::read_to_string(conf_path.clone())
|
||||
// .unwrap_or_else(|_| panic!("Couldn't read {}", conf_path.to_str().unwrap()));
|
||||
|
||||
let contents = if let Ok(s) = fs::read_to_string(conf_path.clone()) {
|
||||
s
|
||||
} else {
|
||||
eprintln!("Error: Couldn't read c_config.toml");
|
||||
return;
|
||||
};
|
||||
|
||||
let config: Config = toml::from_str(&contents).unwrap();
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
[general]
|
||||
target = "main"
|
||||
main = "main.c"
|
||||
target = "test"
|
||||
main = "src/main.c"
|
||||
|
||||
[build]
|
||||
build_dir = "build"
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "test1.h"
|
||||
#include "test2.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void test1() {
|
||||
printf("Hola desde test1\n");
|
||||
test2();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef TEST1_HEADER
|
||||
#define TEST1_HEADER
|
||||
|
||||
void test1();
|
||||
|
||||
#endif
|
||||
@@ -1,6 +0,0 @@
|
||||
#include "test2.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void test2() {
|
||||
printf("Hola desde test2\n");
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef TEST2_HEADER
|
||||
#define TEST2_HEADER
|
||||
|
||||
void test2();
|
||||
|
||||
#endif
|
||||
@@ -1,8 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test1.h"
|
||||
|
||||
int main() {
|
||||
printf("Hola desde main\n");
|
||||
test1();
|
||||
}
|
||||
Reference in New Issue
Block a user