diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3e576c2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.tkcache b/.tkcache new file mode 100644 index 0000000..e69de29 diff --git a/src/compatibility.rs b/src/compatibility.rs new file mode 100644 index 0000000..a265eee --- /dev/null +++ b/src/compatibility.rs @@ -0,0 +1,50 @@ +use std::process::Command; +use std::{fs::File, path::Path}; + +pub fn check_compatibility(linker: String) { + let result = check_compatibility_impl(linker); + if result.is_err() { + println!("Error: {}", result.unwrap_err()); + // maybe exit here? + } +} + +fn check_compatibility_impl(linker: String) -> std::io::Result<()> { + if !Path::new(".tkcache").exists() { + initial_compat_check(linker); + let _ = File::create(".tkcache")?; + } + Ok(()) +} + +fn initial_compat_check(linker: String) { + if cfg!(windows) { + if Command::new("bash").arg("--version").output().is_err() { + println!("Error: WSL installation not found. Please install WSL and try again."); + std::process::exit(1) + } + } + + if get_os_command().arg("-c").arg("nasm").output().is_err() { + println!("Error: NASM installation not found."); + std::process::exit(1) + } + + if get_os_command() + .arg("-c") + .arg(format!("{linker}")) + .output() + .is_err() + { + println!("Error: {linker} installation not found."); + std::process::exit(1) + } +} + +fn get_os_command() -> Command { + return if cfg!(windows) { + Command::new("bash") + } else { + Command::new("sh") + }; +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e67f338..f89ee23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod checker; +pub mod compatibility; pub mod compiler; pub mod graph; pub mod lexer; diff --git a/src/main.rs b/src/main.rs index e4b9225..330003e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use path_slash::PathBufExt; -use std::{path::PathBuf, process::Command}; +use std::path::PathBuf; +use tack::compatibility::check_compatibility; use tack::run::{invoke_command, run}; fn print_help_and_exit() -> ! { @@ -20,15 +21,8 @@ Options: std::process::exit(1); } -fn check_compatibility() { - if cfg!(windows) && Command::new("bash").arg("--version").output().is_err() { - println!("Error: WSL installation not found. Please install WSL and try again."); - std::process::exit(1) - } -} - fn main() { - check_compatibility(); + check_compatibility("ld".to_string()); let input = match std::env::args().nth(1) { Some(value) => {