Skip to content

Commit

Permalink
added WSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Mar 25, 2024
1 parent 0c3ed3c commit d2403db
Show file tree
Hide file tree
Showing 26 changed files with 1,264 additions and 466 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"editor.formatOnSave": true,
"files.autoSave": "onFocusChange",
}
"rust-analyzer.linkedProjects": [
"./codchi/cli/Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": false,
}
125 changes: 89 additions & 36 deletions codchi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions codchi/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ toml_edit = { version = "0.21.0", features = ["serde"] }
# url = "2.5.0"
git-url-parse = "0.4.4"
lazy-regex = "3.1.0"
# which = "6.0.0"

# tokio = { version = "1.35", features = [ "io-util", "rt-multi-thread" ] }
# futures = "0.3"
Expand All @@ -43,7 +44,8 @@ lazy-regex = "3.1.0"
# tarpc = { version = "0.34", git = "https://github.com/google/tarpc", features = [ "serde1", "tokio1", "serde-transport", "serde-transport-bincode" ] }

inquire = "0.6.2"
spinoff = { version = "0.8.0", features = ["dots"] }
indicatif = "0.17.8"
indicatif-log-bridge = "0.2.2"

[target.'cfg(unix)'.dependencies]
# signal-hook = "0.3.17"
Expand All @@ -52,8 +54,12 @@ spinoff = { version = "0.8.0", features = ["dots"] }
# lxd = "0.1.9"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.52", features = [ "Win32_System_Threading" ]}
# windows = { version = "0.52", features = [ "Win32_System_Threading", "Win32_System_Console", "Win32_Foundation" ]}
wslapi = "0.1.3"
version-compare = "0.1"
# codepage-strings = "1.0.2"
known-folders = "1.1.0"
# wtf8 = "0.1"
# colored = "2.1.0"

[build-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions codchi/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ fn main() -> Result<(), Box<dyn Error>> {
}

{
if let Ok(wsl_ver_min) = env::var("CODCHI_WSL_VERSION_MIN") {
println!("cargo:rustc-env=CODCHI_WSL_VERSION_MIN={wsl_ver_min}",);
}

if let Ok(wsl_ver_max) = env::var("CODCHI_WSL_VERSION_MAX") {
println!("cargo:rustc-env=CODCHI_WSL_VERSION_MAX={wsl_ver_max}",);
}

let commit = build_data::exec("nix-git-commit", &[]).unwrap();
println!("cargo:rustc-env=CODCHI_GIT_COMMIT={}", commit);
build_data::set_SOURCE_TIMESTAMP();
Expand Down
22 changes: 15 additions & 7 deletions codchi/cli/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// use anyhow::{Context, Result};
use directories::ProjectDirs;
use once_cell::sync::Lazy;
use std::{
env, fs, io,
path::{Path, PathBuf},
};

pub const APP_NAME: &str = "codchi";

pub static GIT_BRANCH: &str = env!("CODCHI_GIT_BRANCH");
pub static CODCHI_FLAKE_URL: &str = concat!("github:aformatik/codchi/", env!("CODCHI_GIT_BRANCH"));

Expand Down Expand Up @@ -54,23 +55,24 @@ impl ToPath for PathBuf {
}

pub mod host {
use directories::BaseDirs;

use super::*;
static CODCHI_PROJ_DIR: Lazy<ProjectDirs> =
Lazy::new(|| ProjectDirs::from("dev", "codchi", "codchi").unwrap());
static CODCHI_PROJ_DIR: Lazy<BaseDirs> = Lazy::new(|| BaseDirs::new().unwrap());
pub static DIR_CONFIG: Lazy<PathBuf> = Lazy::new(|| {
env::var_os("CODCHI_CONFIG_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| CODCHI_PROJ_DIR.config_dir().to_path_buf())
.unwrap_or_else(|| CODCHI_PROJ_DIR.config_dir().join(APP_NAME))
});
pub static DIR_DATA: Lazy<PathBuf> = Lazy::new(|| {
env::var_os("CODCHI_DATA_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| CODCHI_PROJ_DIR.data_local_dir().to_path_buf())
.unwrap_or_else(|| CODCHI_PROJ_DIR.data_local_dir().join(APP_NAME))
});
pub static DIR_NIX: Lazy<PathBuf> = Lazy::new(|| {
env::var_os("CODCHI_NIX_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| CODCHI_PROJ_DIR.cache_dir().join("/nix").to_path_buf())
.unwrap_or_else(|| CODCHI_PROJ_DIR.cache_dir().join(APP_NAME).join("/nix"))
});
pub static DIR_RUNTIME: Lazy<PathBuf> = Lazy::new(|| {
env::var_os("CODCHI_RUNTIME_DIR")
Expand All @@ -79,7 +81,8 @@ pub mod host {
CODCHI_PROJ_DIR
.runtime_dir()
.map(Path::to_path_buf)
.unwrap_or_else(|| env::temp_dir().join("codchi"))
.unwrap_or_else(|| env::temp_dir())
.join(APP_NAME)
})
});
}
Expand Down Expand Up @@ -108,3 +111,8 @@ pub mod user {
pub const DEFAULT_UID: &str = "1000";
pub const DEFAULT_GID: &str = "100";
}

pub mod files {
pub const STORE_ROOTFS_NAME: &str = "store.tar.gz";
pub const MACHINE_ROOTFS_NAME: &str = "machine.tar.gz";
}
Loading

0 comments on commit d2403db

Please sign in to comment.