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 autobins = true
[features] [features]
default = []
algorithms = [] algorithms = []
[[bin]]
name = "sha256sum"
path = "src/bin/sha256sum.rs"
required-features = []
[[bin]] [[bin]]
name = "picca" name = "picca"
path = "src/bin/picca.rs"
required-features = ["algorithms"] required-features = ["algorithms"]
[dependencies] [dependencies]

View file

@ -38,6 +38,10 @@ push-docker-latest: build-docker push-docker
docker push forge.steck.dev/bryson/picca:latest docker push forge.steck.dev/bryson/picca:latest
docker image rm forge.steck.dev/bryson/picca:latest docker image rm forge.steck.dev/bryson/picca:latest
# generate algorithm bin into Cargo.toml
generate-bin:
doc: doc:
@mkdir -p target @mkdir -p target
sed s/\<VERSION\>/{{version}}/g man/picca.1.md | pandoc --standalone -t man > target/picca.1 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] #[quit::main]
fn main() { fn main() {
let args = Args::parse(); let args = picca::Args::parse();
let algorithm = args.algorithm; let algorithm = env!("CARGO_BIN_NAME").replace("sum", "");
let docker = match option_env!("PICCA_DOCKER") { picca::main!(args, algorithm, false);
Some(v) => match v {
"true" => true,
_ => false,
},
None => false,
};
picca::main!(args, algorithm, docker);
} }

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] #[quit::main]
fn main() { fn main() {
let args = picca::Args::parse(); let args = picca::Args::parse();
let algorithm = env!("CARGO_BIN_NAME").replace("sum", ""); let algorithm = env!("CARGO_BIN_NAME").replace("sum", "");
let docker = match option_env!("PICCA_DOCKER") { picca::main!(args, algorithm, true);
Some(v) => match v {
"true" => true,
_ => false,
},
None => false,
};
picca::main!(args, algorithm, docker);
} }

View file

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

View file

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