From 7ea6c3befd152457c51bf79a43087127de4990ad Mon Sep 17 00:00:00 2001 From: CDrummond Date: Sun, 9 Mar 2025 08:02:37 +0000 Subject: [PATCH] Add excplcit 'ffmpeg' feature flag. --- .github/workflows/build.yml | 6 +++--- Cargo.toml | 8 +++++--- README.md | 2 +- docker/docker-build-arm-ffmpeg.sh | 2 +- src/analyse.rs | 24 ++++++++++++------------ src/cue.rs | 14 +++++++------- src/db.rs | 4 ++-- src/main.rs | 6 +++--- 8 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79ffcf2..dddb3ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Build x86 ffmpeg version run: | - cargo build --release + cargo build --release --features=ffmpeg strip target/release/bliss-analyser mkdir releases cp target/release/bliss-analyser releases/bliss-analyser @@ -202,10 +202,10 @@ jobs: - name: Build run: | - cargo build --release --features update-aubio-bindings + cargo build --release --features ffmpeg,update-aubio-bindings strip target/release/bliss-analyser cp target/release/bliss-analyser releases/bliss-analyser-x86_64 - cargo build --target=aarch64-apple-darwin --release --features update-aubio-bindings + cargo build --target=aarch64-apple-darwin --release --features ffmpeg,update-aubio-bindings strip target/aarch64-apple-darwin/release/bliss-analyser cp target/aarch64-apple-darwin/release/bliss-analyser releases/bliss-analyser-arm64 diff --git a/Cargo.toml b/Cargo.toml index 8eb3ae0..cc5d8f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,14 +25,16 @@ ureq = "2.4.0" configparser = "3.0.0" if_chain = "1.0.2" num_cpus = "1.13.0" -which = "7.0.2" -rcue = "0.1.3" -hhmmss = "0.1.0" +which = { "7.0.2", optional = true } +rcue = { "0.1.3", optional = true } +hhmmss = { "0.1.0", optional = true } [features] +default = ["libav"] libav = ["bliss-audio/ffmpeg"] update-aubio-bindings = ["bliss-audio/update-aubio-bindings"] staticlibav = ["bliss-audio/build-ffmpeg", "bliss-audio/ffmpeg-static"] +ffmpeg = ["dep:which", "dep:rcue", "dep:hhmmss"] [dependencies.bliss-audio] default-features = false diff --git a/README.md b/README.md index 08e65a4..3f366a1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ To install dependencies on a Fedora system: dnf install clang pkg-config ``` -Build with `cargo build --release` +Build with `cargo build --release --features=ffmpeg` `ffmpeg` is then a run-time dependency, and should be installed on any system where this application is to be run - it should also be in the users `$PATH` diff --git a/docker/docker-build-arm-ffmpeg.sh b/docker/docker-build-arm-ffmpeg.sh index 8201d31..4b1bba0 100755 --- a/docker/docker-build-arm-ffmpeg.sh +++ b/docker/docker-build-arm-ffmpeg.sh @@ -14,7 +14,7 @@ function build { if [[ ! -f /build/$1/release/bliss-analyser ]]; then export RUST_BACKTRACE=full export PKG_CONFIG=${1//unknown-/}-pkg-config - BINDGEN_EXTRA_CLANG_ARGS="--sysroot /usr/${1//unknown-/}" cargo build --release --target $1 + BINDGEN_EXTRA_CLANG_ARGS="--sysroot /usr/${1//unknown-/}" cargo build --release --features=ffmpeg --target $1 fi $2 /build/$1/release/bliss-analyser && cp /build/$1/release/bliss-analyser $DESTDIR/$3 diff --git a/src/analyse.rs b/src/analyse.rs index db7e634..40c2789 100644 --- a/src/analyse.rs +++ b/src/analyse.rs @@ -8,11 +8,11 @@ use crate::cue; use crate::db; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use crate::ffmpeg; use crate::tags; use anyhow::Result; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use hhmmss::Hhmmss; use if_chain::if_chain; use indicatif::{ProgressBar, ProgressStyle}; @@ -23,18 +23,18 @@ use std::fs::{DirEntry, File}; use std::io::{BufRead, BufReader}; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use std::sync::mpsc; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use std::sync::mpsc::{Receiver, Sender}; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use std::thread; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use std::time::Duration; use num_cpus; #[cfg(feature = "libav")] use bliss_audio::{decoder::Decoder, decoder::ffmpeg::FFmpeg}; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use bliss_audio::{decoder::Decoder, BlissResult, Song}; const DONT_ANALYSE: &str = ".notmusic"; @@ -92,7 +92,7 @@ fn check_dir_entry(db: &mut db::Db, mpath: &Path, entry: DirEntry, track_paths: *file_count+=1; } - #[cfg(not(feature = "libav"))] + #[cfg(feature = "ffmpeg")] if id<=0 { let this_cue_tracks = cue::parse(&pb, &cue_file); for track in this_cue_tracks { @@ -255,7 +255,7 @@ fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec, max Ok(()) } -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec, max_threads: usize, use_tags: bool) -> Result<()> { let total = track_paths.len(); let progress = ProgressBar::new(total.try_into().unwrap()).with_style( @@ -314,7 +314,7 @@ fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec, max Ok(()) } -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] fn analyze_cue_streaming(tracks: Vec,) -> BlissResult)>> { let num_cpus = num_cpus::get(); @@ -354,7 +354,7 @@ fn analyze_cue_streaming(tracks: Vec,) -> BlissResult) -> Result<()> { let total = cue_tracks.len(); let progress = ProgressBar::new(total.try_into().unwrap()).with_style( @@ -455,7 +455,7 @@ pub fn analyse_files(db_path: &str, mpaths: &Vec, dry_run: bool, keep_o log::info!("No new files to analyse"); } - #[cfg(not(feature = "libav"))] + #[cfg(feature = "ffmpeg")] if !cue_tracks.is_empty() { match analyse_new_cue_tracks(&db, &mpath, cue_tracks) { Ok(_) => { changes_made = true; }, diff --git a/src/cue.rs b/src/cue.rs index 2595163..8b2773f 100644 --- a/src/cue.rs +++ b/src/cue.rs @@ -8,17 +8,17 @@ extern crate rcue; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use crate::db; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use rcue::parser::parse_from_file; use std::path::PathBuf; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use std::time::Duration; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] pub const LAST_TRACK_DURATION:u64 = 60*60*24; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] const GENRE:&str = "GENRE"; #[cfg(feature = "libav")] @@ -27,7 +27,7 @@ pub struct CueTrack { pub track_path:PathBuf } -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] #[derive(Clone)] pub struct CueTrack { pub audio_path:PathBuf, @@ -41,7 +41,7 @@ pub struct CueTrack { pub duration:Duration } -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] pub fn parse(audio_path:&PathBuf, cue_path:&PathBuf) -> Vec { let mut resp:Vec = Vec::new(); diff --git a/src/db.rs b/src/db.rs index 68e3a67..a0934bc 100644 --- a/src/db.rs +++ b/src/db.rs @@ -6,7 +6,7 @@ * **/ - #[cfg(not(feature = "libav"))] + #[cfg(feature = "ffmpeg")] use crate::ffmpeg; use crate::tags; use bliss_audio::{Analysis, AnalysisIndex}; @@ -288,7 +288,7 @@ impl Db { let path = String::from(track_path.to_string_lossy()); let mut ftags = tags::read(&path, false); - #[cfg(not(feature = "libav"))] + #[cfg(feature = "ffmpeg")] if ftags.is_empty() { ftags = ffmpeg::read_tags(&path); } diff --git a/src/main.rs b/src/main.rs index bc5bc5b..e944506 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,12 @@ use log::LevelFilter; use std::io::Write; use std::path::PathBuf; use std::process; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] use which::which; mod analyse; mod cue; mod db; -#[cfg(not(feature = "libav"))] +#[cfg(feature = "ffmpeg")] mod ffmpeg; mod tags; mod upload; @@ -104,7 +104,7 @@ fn main() { } // Ensure ffmpeg is in PATH... - #[cfg(not(feature = "libav"))] + #[cfg(feature = "ffmpeg")] match which("ffmpeg") { Ok(_) => { } Err(_) => {