infrastructure/patches/npins/01-libnpins-2.patch

173 lines
5 KiB
Diff

From 9d497f4efd7c25842b737478f6582abff2e8b1cd Mon Sep 17 00:00:00 2001
From: piegames <git@piegames.de>
Date: Wed, 12 Mar 2025 22:13:29 +0100
Subject: [PATCH 2/4] libnpins: Init
---
.github/workflows/test.yml | 6 +++++-
Cargo.toml | 20 +++++++++++++++++---
npins.nix | 7 +++++++
src/cli.rs | 22 +++++++++++++++++++++-
src/main.rs | 22 ----------------------
5 files changed, 50 insertions(+), 27 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 04db4ec..ecc0878 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -13,10 +13,14 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@v10
- name: Build
run: nix-build
+ - name: Cargo Build Lib
+ run: nix-shell --run "cargo build --lib"
+ - name: Cargo Build CLI
+ run: nix-shell --run "cargo build --bin npins --features=clap,crossterm,env_logger"
- name: Run pre-commit hooks
run: nix-shell --run "pre-commit run --all"
- name: Cargo test
- run: nix-shell --run "cargo test"
+ run: nix-shell --run "cargo test --all"
- name: Test dev shell
# Simple check that the pins in the current repository are still working.
# Importantly, this will fail on any version mismatch, indicating that versions need to be upgraded.
diff --git a/Cargo.toml b/Cargo.toml
index c0d8be3..9b855bb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,20 +4,34 @@ version = "0.3.0"
edition = "2021"
license = "EUPL-1.2"
+[lib]
+name = "npins"
+path = "src/main.rs"
+
+[[bin]]
+name = "npins"
+path = "src/cli.rs"
+required-features = [ "clap", "crossterm", "env_logger" ]
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "^1.0", features = [ "derive" ] }
serde_json = { version = "^1.0", features = ["preserve_order"] }
url = { version = "^2.2.2", features = [ "serde" ] }
-clap = { version = "4.5", features = [ "derive", "env" ] }
anyhow = "^1.0"
tokio = { version = "^1.0", features = ["macros", "rt-multi-thread", "process"] }
-env_logger = { version = "^0.11.0", features = ["color", "auto-color", "regex"], default-features = false }
log = "^0.4"
reqwest = { version = "^0.12.0", features = [ "rustls-tls" ], default-features = false }
async-trait = "0.1.52"
lenient_semver_parser = { version = "0.4.2", default-features = false }
lenient_version = { version = "0.4.2" }
futures = "0.3.31"
-crossterm = { version = "0.28.1", default-features = false }
+
+# CLI dependencies
+clap = { version = "4.5", features = [ "derive", "env" ], optional = true }
+crossterm = { version = "0.28.1", default-features = false, optional = true }
+env_logger = { version = "^0.11.0", features = ["color", "auto-color", "regex"], default-features = false, optional = true }
+
+[dev-dependencies]
+env_logger = { version = "^0.11.0", features = ["color", "auto-color", "regex"], default-features = false }
diff --git a/npins.nix b/npins.nix
index b51871f..912d431 100644
--- a/npins.nix
+++ b/npins.nix
@@ -58,6 +58,13 @@ let
buildInputs = lib.optional stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security ]);
nativeBuildInputs = [ makeWrapper ];
+ cargoBuildFlags = [
+ "--bin"
+ "npins"
+ "--features"
+ "clap,crossterm,env_logger"
+ ];
+
# (Almost) all tests require internet
doCheck = false;
diff --git a/src/cli.rs b/src/cli.rs
index a689658..3f5a347 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,6 +1,8 @@
//! The main CLI application
+use std::collections::BTreeMap;
+use std::path::PathBuf;
-use super::*;
+use npins::*;
use std::{
collections::BTreeSet,
@@ -1097,3 +1099,21 @@ impl Opts {
Ok(())
}
}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let opts = Opts::parse();
+
+ env_logger::builder()
+ .filter_level(if opts.verbose {
+ log::LevelFilter::Debug
+ } else {
+ log::LevelFilter::Info
+ })
+ .format_timestamp(None)
+ .format_target(false)
+ .init();
+
+ opts.run().await?;
+ Ok(())
+}
diff --git a/src/main.rs b/src/main.rs
index 0b700cc..46b7a5f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,14 +1,10 @@
-use std::path::PathBuf;
-
use anyhow::Result;
-use clap::Parser;
use diff::{Diff, OptionExt};
use reqwest::IntoUrl;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
pub mod channel;
-pub mod cli;
pub mod diff;
pub mod flake;
pub mod git;
@@ -348,24 +344,6 @@ impl diff::Diff for GenericUrlHashes {
}
}
-#[tokio::main]
-async fn main() -> Result<()> {
- let opts = cli::Opts::parse();
-
- env_logger::builder()
- .filter_level(if opts.verbose {
- log::LevelFilter::Debug
- } else {
- log::LevelFilter::Info
- })
- .format_timestamp(None)
- .format_target(false)
- .init();
-
- opts.run().await?;
- Ok(())
-}
-
#[cfg(test)]
mod tests {
use super::*;