Skip to content

Commit

Permalink
Codchi rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Jan 30, 2024
1 parent 9d3ac78 commit fa3a6ce
Show file tree
Hide file tree
Showing 20 changed files with 902 additions and 573 deletions.
37 changes: 19 additions & 18 deletions codchi/Cargo.lock

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

9 changes: 4 additions & 5 deletions codchi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ strip = true
[dependencies]
clap = { version = "4", features = ["derive", "cargo", "string"] }
clap-verbosity-flag = "2.1.0"

lazy_static = "1.4.0"
once_cell = "1.19.0"
strum = { version = "0.25.0", features = ["derive"] }
itertools = "0.12.0"
Expand Down Expand Up @@ -47,19 +45,20 @@ futures = "0.3"
# futures-io = { version = "0.3" }

parity-tokio-ipc = "0.9.0"
tarpc = { version = "0.33", features = [ "serde1", "tokio1", "serde-transport", "serde-transport-bincode" ] }
tarpc = { version = "0.34", git = "https://github.com/google/tarpc", features = [ "serde1", "tokio1", "serde-transport", "serde-transport-bincode" ] }

tray-icon = { version = "0.11.1", default-features = false }
image = { version = "0.24", features = ["png"], default-features = false }
tao = {version = "0.24.0", default-features = false }
inquire = "0.6.2"
spinoff = { version = "0.8.0", features = ["dots"] }
dashmap = { version = "5.5.3", features = ["serde"] }

[target.'cfg(unix)'.dependencies]
daemonize = "0.5.0"

[target.'cfg(target_os = "linux")'.dependencies]
lxd = "0.1.9"
# [target.'cfg(target_os = "linux")'.dependencies]
# lxd = "0.1.9"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.52", features = [ "Win32_System_Threading" ]}
Expand Down
18 changes: 15 additions & 3 deletions codchi/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{error::Error, fs, path::PathBuf};
use std::{env, error::Error, fs, path::PathBuf};

use clap::CommandFactory;
use clap_complete::{generate_to, Shell::*};
Expand All @@ -7,7 +7,7 @@ use clap_complete::{generate_to, Shell::*};
mod cli;

fn main() -> Result<(), Box<dyn Error>> {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

let man_dir = out_dir.join("man");
fs::create_dir_all(&man_dir).unwrap();
Expand All @@ -31,8 +31,20 @@ fn main() -> Result<(), Box<dyn Error>> {

{
let commit = build_data::exec("nix-git-commit", &[]).unwrap();
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
println!("cargo:rustc-env=CODCHI_GIT_COMMIT={}", commit);
build_data::set_SOURCE_TIMESTAMP();

if let Ok(branch) = build_data::get_git_branch() {
println!("cargo:rustc-env=CODCHI_GIT_BRANCH={}", branch);
} else {
println!(
"cargo:rustc-env=CODCHI_GIT_BRANCH=v{}",
env::var("CARGO_PKG_VERSION").unwrap()
);
}
if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=profile={:?}", profile);
}
build_data::no_debug_rebuilds();
}
// #[cfg(target_os = "linux")]
Expand Down
30 changes: 22 additions & 8 deletions codchi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
, writeShellScript
, writeShellScriptBin
, fetchFromGitHub

, lib

, lxd-ctrl-rootfs
, platform

, makeRustPlatform
, rust-bin

, makeWrapper
, pkg-config
, gtk3
# , xdotool
# , xdotool
# , libappindicator-gtk3
, libayatana-appindicator
# , libxkbcommon
# , libxkbcommon
# , xorg
# , vulkan-loader
# , libGL
# , vulkan-loader
# , libGL
# , webkitgtk_4_1
# , libsoup
# , libdbusmenu
# , libdbusmenu

, llvmPackages
, cargo-xwin
Expand Down Expand Up @@ -139,7 +142,6 @@ let

auditable = false; # disable cargo auditable

# targetCargo = "X86_64_PC_WINDOWS_MSVC";
CARGO_BUILD_TARGET = "x86_64-pc-windows-msvc";
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER = writeShellScript "wine-wsl" ''
if ! command -v wslpath &> /dev/null; then
Expand All @@ -149,6 +151,10 @@ let
fi
'';

# On Windows MSVC, statically link the C runtime so that the resulting EXE does
# not depend on the vcruntime DLL.
RUSTFLAGS = "-C target-feature=+crt-static";

nativeBuildInputs = [
llvmPackages.llvm
llvmPackages.bintools
Expand All @@ -169,6 +175,9 @@ let
linux = rec {
# targetCargo = "X86_64-UNKNOWN-LINUX-GNU";
CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";

CODCHI_LXD_CTRL_ROOTFS = lxd-ctrl-rootfs;

passthru = {
inherit xwin;
rust = rustOrig;
Expand All @@ -185,6 +194,7 @@ let
# gtk3
# gtk3.debug
nix-git
makeWrapper
];
buildInputs = [
gtk3
Expand All @@ -202,8 +212,10 @@ let
];

postFixup = ''
patchelf $out/bin/codchi \
patchelf "$out/bin/codchi" \
--add-rpath ${lib.makeLibraryPath buildInputs}
wrapProgram "$out/bin/codchi" \
--set CODCHI_LXD_CTRL_ROOTFS $CODCHI_LXD_CTRL_ROOTFS
'';
};
}.${platform};
Expand All @@ -217,7 +229,9 @@ native.passthru.rustPlatform.buildRustPackage (lib.recursiveUpdate

src = ./.;
cargoLock.lockFile = ./Cargo.lock;
# cargoLock.outputHashes = { "tray-icon-0.11.0" = ""; };
cargoLock.outputHashes = {
"tarpc-0.34.0" = "";
};

passthru = { inherit nix-git; };
}
Expand Down
9 changes: 4 additions & 5 deletions codchi/shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ self
, mkShell
{ mkShell
, writeShellScriptBin
, lib
, callPackage

, codchi

, nixpkgs-fmt
, strace
Expand All @@ -21,14 +21,13 @@
}:
let

codchi = callPackage ./. { inherit self platform; };

native = {
win = {
inherit (codchi) CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER;
shellHook = codchi.passthru.setupXWin "$(git rev-parse --show-toplevel)";
};
linux = {
inherit (codchi) CODCHI_LXD_CTRL_ROOTFS;
LD_LIBRARY_PATH = lib.makeLibraryPath codchi.buildInputs;
};
}.${platform};
Expand Down
33 changes: 29 additions & 4 deletions codchi/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub use self::module::*;

pub static CLI_ARGS: OnceCell<Cli> = OnceCell::new();

// static long_version: &'static str = ;

type DefaultLogLevel = WarnLevel;

/// codchi
Expand All @@ -23,13 +21,17 @@ type DefaultLogLevel = WarnLevel;
// infer_subcommands = true
long_version = format!("v{}\n{}",
option_env!("CARGO_PKG_VERSION").unwrap_or(""),
option_env!("GIT_COMMIT").unwrap_or(""),
option_env!("CODCHI_GIT_COMMIT").unwrap_or(""),
)
)]
pub struct Cli {
#[command(flatten)]
pub verbose: Verbosity<DefaultLogLevel>,

/// Dont keep the controller running in background
#[arg(long, short = 's')]
pub stop_ctrl: bool,

#[command(subcommand)]
pub command: Option<Cmd>,
}
Expand Down Expand Up @@ -148,7 +150,7 @@ mod module {
},
}

#[derive(clap::Args, Debug, Clone, Default)]
#[derive(clap::Args, Debug, Clone)]
// branch an tag are mutually exclusive
#[clap(group(ArgGroup::new("ref").args(&["branch", "tag"])))]
pub struct AddModuleOptions {
Expand Down Expand Up @@ -185,6 +187,29 @@ mod module {
pub module_path: Option<ModuleAttrPath>,
}

// TODO this is only neccessary when we have named modules. Currently they are refered to by
// their index
// #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
// pub struct CodchiName(pub String);

// impl Display for CodchiName {
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// f.write_str(&self.0)
// }
// }

// impl FromStr for CodchiName {
// type Err = String;

// fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
// if s != "__codchi" {
// Ok(CodchiName(s.to_string()))
// } else {
// Err("The name '__codchi' is a reserved keyword.".to_string())
// }
// }
// }

#[derive(Clone, Debug, PartialEq)]
pub struct ModuleAttrPath {
/// codchiModules or nixosModules
Expand Down
Loading

0 comments on commit fa3a6ce

Please sign in to comment.