Skip to content

Commit

Permalink
feat: add experimental windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHedmad committed Nov 26, 2024
1 parent 8f5d07b commit ed11a39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/commands/data/describe.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,6 +24,14 @@ impl TryFrom<PathBuf> for FileSize {
fn try_from(value: PathBuf) -> std::result::Result<Self, Self::Error> {
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,
})
Expand Down
21 changes: 18 additions & 3 deletions src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PathBuf>>" to the Executor and remove
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -161,7 +167,7 @@ impl Executor {
]),
ExecutionStrategy::Shell => stringify!(vec![
"--entrypoint",
"bash",
SHELL,
&runtime_name,
&format!("{}/executor", workdir)
]),
Expand All @@ -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()]]
}
}
};
Expand Down Expand Up @@ -414,8 +420,17 @@ impl FileMover {
fn _link(&self) -> Result<PathBuf> {
// 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())
}

Expand Down

0 comments on commit ed11a39

Please sign in to comment.