From ed11a39167899de16d5f4277290509e61a01ac6f Mon Sep 17 00:00:00 2001 From: Luca Visentin Date: Tue, 26 Nov 2024 10:28:39 +0100 Subject: [PATCH] feat: add experimental windows compatibility --- src/commands/data/describe.rs | 15 ++++++++++++++- src/execution.rs | 21 ++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/commands/data/describe.rs b/src/commands/data/describe.rs index cc66c4e..f4d472f 100644 --- a/src/commands/data/describe.rs +++ b/src/commands/data/describe.rs @@ -1,11 +1,16 @@ use core::iter::Sum; use std::fmt::Display; use std::fs; -use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use crate::options::KerblamTomlOptions; +#[cfg(target_family = "windows")] +use std::os::windows::fs::MetadataExt; + +#[cfg(target_family = "unix")] +use std::os::unix::fs::MetadataExt; + #[derive(Debug, Clone)] /// Wrapper to interpret a usize as a File size. pub struct FileSize { @@ -19,6 +24,14 @@ impl TryFrom for FileSize { fn try_from(value: PathBuf) -> std::result::Result { let meta = fs::metadata(value)?; + #[cfg(target_family = "windows")] + { + Ok(FileSize { + size: meta.file_size() as usize, + }) + } + + #[cfg(target_family = "unix")] Ok(FileSize { size: meta.size() as usize, }) diff --git a/src/execution.rs b/src/execution.rs index fd5002f..c491e21 100644 --- a/src/execution.rs +++ b/src/execution.rs @@ -13,6 +13,12 @@ use anyhow::{anyhow, bail, Context, Result}; use crossbeam_channel::{bounded, Receiver}; use lazy_static::lazy_static; +#[cfg(target_family = "unix")] +static SHELL: &str = "bash"; + +#[cfg(target_family = "windows")] +static SHELL: &str = "powershell"; + // TODO: I think we can add all cleanup code to `Drop`, so that a lot of these // functions can be simplified a lot. // E.g. make a "cleanup: Option>" to the Executor and remove @@ -109,7 +115,7 @@ impl Executor { /// Execute this executor based on its data /// /// Either builds and runs a container, or executes make and/or - /// bash, depending on the execution strategy. + /// bash (powershell on windows), depending on the execution strategy. /// /// Needs the kerblam config to work, as we need to bind-mount the local /// paths in the containers as locally needed and follow other settings. @@ -161,7 +167,7 @@ impl Executor { ]), ExecutionStrategy::Shell => stringify!(vec![ "--entrypoint", - "bash", + SHELL, &runtime_name, &format!("{}/executor", workdir) ]), @@ -180,7 +186,7 @@ impl Executor { stringify![vec!["make", "-f", self.target.to.to_str().unwrap()]] } ExecutionStrategy::Shell => { - stringify![vec!["bash", self.target.to.to_str().unwrap()]] + stringify![vec![SHELL, self.target.to.to_str().unwrap()]] } } }; @@ -414,8 +420,17 @@ impl FileMover { fn _link(&self) -> Result { // TODO: Make this compatible with other operating systems. log::debug!("Linking {:?} to {:?}", self.from, self.to); + + #[cfg(target_family = "unix")] std::os::unix::fs::symlink(self.from.clone(), self.to.clone())?; + #[cfg(target_family = "windows")] + if self.from.is_dir() { + std::os::windows::fs::symlink_dir(self.from.clone(), self.to.clone())?; + } else { + std::os::windows::fs::symlink_file(self.from.clone(), self.to.clone())?; + } + Ok(self.to.clone()) }