diff --git a/Cargo.lock b/Cargo.lock index d54e978..06751a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -365,6 +365,7 @@ dependencies = [ "core-foundation-sys 0.8.4", "coreaudio-rs", "dasp_sample", + "jack", "jni 0.19.0", "js-sys", "libc", @@ -558,6 +559,33 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "jack" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e5a18a3c2aefb354fb77111ade228b20267bdc779de84e7a4ccf7ea96b9a6cd" +dependencies = [ + "bitflags 1.3.2", + "jack-sys", + "lazy_static", + "libc", + "log", +] + +[[package]] +name = "jack-sys" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6013b7619b95a22b576dfb43296faa4ecbe40abbdb97dfd22ead520775fc86ab" +dependencies = [ + "bitflags 1.3.2", + "lazy_static", + "libc", + "libloading", + "log", + "pkg-config", +] + [[package]] name = "jni" version = "0.19.0" @@ -693,6 +721,7 @@ dependencies = [ "alsa", "bitflags 1.3.2", "coremidi", + "jack-sys", "js-sys", "libc", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 7e66e2b..02afd1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,18 @@ exclude = [ cpal = { git = "https://github.com/RustAudio/cpal.git", features = ["asio"] } midir = { version = "0.9", features = ["winrt"] } +[target.'cfg(target_os = "linux")'.dependencies] +cpal = { git = "https://github.com/RustAudio/cpal.git", features = ["jack"] } +midir = { version = "0.9", features = ["jack"] } + # [target.'cfg(target_os = "windows")'.dependencies] # cpal = { version = "0.15", features = ["asio"] } # midir = { version = "0.9", features = ["winrt"] } +# [target.'cfg(target_os = "linux")'.dependencies] +# cpal = { version = "0.15", features = ["jack"] } +# midir = { version = "0.9", features = ["jack"] } + [dependencies] midir = "0.9" clap = { version = "4", features = ["derive", "env"] } diff --git a/justfile b/justfile index 5a00080..0a822fd 100644 --- a/justfile +++ b/justfile @@ -8,3 +8,5 @@ install-win: cargo build --release Copy-Item -Path {{ justfile_directory() }}\target\release\smrec.exe -Destination {{ env_var_or_default("USERPROFILE", "") }}\.cargo\bin\ +prepare-linux: + ./pre-build-linux.sh \ No newline at end of file diff --git a/pre-build-linux.sh b/pre-build-linux.sh new file mode 100755 index 0000000..847402c --- /dev/null +++ b/pre-build-linux.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Determine the package manager +if command -v apt-get >/dev/null 2>&1; then + PACKAGE_MANAGER="apt-get" +elif command -v dnf >/dev/null 2>&1; then + PACKAGE_MANAGER="dnf" +elif command -v yum >/dev/null 2>&1; then + PACKAGE_MANAGER="yum" +elif command -v zypper >/dev/null 2>&1; then + PACKAGE_MANAGER="zypper" +elif command -v pacman >/dev/null 2>&1; then + PACKAGE_MANAGER="pacman" +else + echo "Unsupported package manager. Exiting." + exit 1 +fi + +# Define the package names +if [[ "$PACKAGE_MANAGER" == "apt-get" ]]; then + ALSA_PACKAGE="libasound2-dev" + JACK_PACKAGE="libjack-jackd2-dev" +elif [[ "$PACKAGE_MANAGER" == "dnf" || "$PACKAGE_MANAGER" == "yum" ]]; then + ALSA_PACKAGE="alsa-lib-devel" + JACK_PACKAGE="jack-audio-connection-kit-devel" +elif [[ "$PACKAGE_MANAGER" == "zypper" ]]; then + ALSA_PACKAGE="alsa-devel" + JACK_PACKAGE="jack-devel" +elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then + ALSA_PACKAGE="alsa-lib" + JACK_PACKAGE="jack" +fi + +# Update package lists for the latest version of the repository +if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then + echo "Updating package databases..." + sudo pacman -Syq --noconfirm || { + echo "Updating package databases failed. Exiting." + exit 1 + } +else + echo "Updating package lists..." + sudo $PACKAGE_MANAGER update -yq || { + echo "Updating package lists failed. Exiting." + exit 1 + } +fi + +# Install necessary packages for ALSA +echo "Installing ALSA development files..." +sudo $PACKAGE_MANAGER install -yq $ALSA_PACKAGE || { + echo "Installing ALSA development files failed. Exiting." + exit 1 +} + +# Install necessary packages for JACK +echo "Installing JACK development files..." +sudo $PACKAGE_MANAGER install -yq $JACK_PACKAGE || { + echo "Installing JACK development files failed. Exiting." + exit 1 +} + +echo "Build environment preparation complete."