further cleanup of libs and bins

This commit is contained in:
Bryson Steck 2025-08-13 00:15:39 -06:00
parent 56e8b69322
commit 480a9f72fb
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
6 changed files with 52 additions and 59 deletions

View file

@ -5,10 +5,17 @@ edition = "2024"
autobins = true
[features]
default = []
algorithms = []
[[bin]]
name = "sha256sum"
path = "src/bin/sha256sum.rs"
required-features = []
[[bin]]
name = "picca"
path = "src/bin/picca.rs"
required-features = ["algorithms"]
[dependencies]

View file

@ -38,6 +38,10 @@ push-docker-latest: build-docker push-docker
docker push forge.steck.dev/bryson/picca:latest
docker image rm forge.steck.dev/bryson/picca:latest
# generate algorithm bin into Cargo.toml
generate-bin:
doc:
@mkdir -p target
sed s/\<VERSION\>/{{version}}/g man/picca.1.md | pandoc --standalone -t man > target/picca.1

View file

@ -1,26 +1,6 @@
use clap::Parser;
use std::collections::{HashMap, VecDeque};
use std::fs::{self, File, read_to_string};
use std::io::{self, Read};
use std::path::PathBuf;
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle, available_parallelism};
use picca::core::hashers;
use picca::{get_algorithms, message};
#[quit::main]
fn main() {
let args = Args::parse();
let algorithm = args.algorithm;
let docker = match option_env!("PICCA_DOCKER") {
Some(v) => match v {
"true" => true,
_ => false,
},
None => false,
};
picca::main!(args, algorithm, docker);
let args = picca::Args::parse();
let algorithm = env!("CARGO_BIN_NAME").replace("sum", "");
picca::main!(args, algorithm, false);
}

View file

@ -1,23 +1,6 @@
use clap::Parser;
use std::collections::VecDeque;
use std::fs::{self};
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::thread::available_parallelism;
use picca::message;
#[quit::main]
fn main() {
let args = picca::Args::parse();
let algorithm = env!("CARGO_BIN_NAME").replace("sum", "");
let docker = match option_env!("PICCA_DOCKER") {
Some(v) => match v {
"true" => true,
_ => false,
},
None => false,
};
picca::main!(args, algorithm, docker);
picca::main!(args, algorithm, true);
}

View file

@ -1,10 +1,11 @@
use std::{
collections::{HashMap, VecDeque},
fs::{read_to_string, File},
fs::{File, read_to_string},
io::{self, Read},
path::PathBuf,
sync::{
atomic::{AtomicI32, Ordering}, Arc, Mutex
Arc, Mutex,
atomic::{AtomicI32, Ordering},
},
thread::{self, JoinHandle},
};

View file

@ -1,16 +1,34 @@
#[macro_export]
macro_rules! main {
($a:expr,$b:expr,$c:expr) => {
let cpus = match $a.threads {
0 => available_parallelism().unwrap().get(),
_ => $a.threads,
($args: expr, $algorithm: expr, $independent: expr) => {
use clap::Parser;
use std::collections::VecDeque;
use std::fs::{self};
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::thread::available_parallelism;
use picca::message;
let docker = match option_env!("PICCA_DOCKER") {
Some(v) => match v {
"true" => true,
_ => false,
},
None => false,
};
if $a.debug {
let cpus = match $args.threads {
0 => available_parallelism().unwrap().get(),
_ => $args.threads,
};
if $args.debug {
if env!("CARGO_BIN_NAME") != "picca" {
message::debug(format!(
"Starting picca using algorithm {} with a max of {} threads",
$b, cpus
$algorithm, cpus
));
} else {
message::debug(format!(
@ -20,26 +38,26 @@ macro_rules! main {
));
}
if $c {
if docker {
message::debug(format!("Docker is detected"));
}
}
if picca::UNSECURE_ALGORITHMS.contains(&$b.as_str()) {
message::warning(format!("{} is an unsecure hashing algorithm!", &$b));
if picca::UNSECURE_ALGORITHMS.contains(&$algorithm.as_str()) {
message::warning(format!("{} is an unsecure hashing algorithm!", &$algorithm));
}
let handles;
let arc_fe;
let arc_he;
let check_mode = !$a.check.is_empty();
if &$a.check.len() >= &1 {
(handles, arc_fe, arc_he) = picca::core::verify(cpus, $b, $a.debug, $a.quiet, $a.check);
let check_mode = !$args.check.is_empty();
if &$args.check.len() >= &1 {
(handles, arc_fe, arc_he) = picca::core::verify(cpus, $algorithm, $args.debug, $args.quiet, $args.check);
} else {
let mut buffer = VecDeque::new();
if &$a.files.len() >= &1 {
for file in $a.files {
if $a.canonicalize {
if &$args.files.len() >= &1 {
for file in $args.files {
if $args.canonicalize {
match fs::canonicalize(file.as_path()) {
Ok(p) => buffer.push_back(p),
Err(e) => panic!("unable to canonicalize {}: {}", file.as_path().display(), e),
@ -53,7 +71,7 @@ macro_rules! main {
buffer.push_back(PathBuf::from("-"));
}
(handles, arc_fe, arc_he) = picca::core::generate(cpus, buffer, $b, $a.debug, $a.quiet);
(handles, arc_fe, arc_he) = picca::core::generate(cpus, buffer, $algorithm, $args.debug, $args.quiet);
}
for handle in handles {