Skip to content

Commit

Permalink
v0.11.0: fix cargo install & upgrade rustpotter
Browse files Browse the repository at this point in the history
  • Loading branch information
GiviMAD committed Jun 3, 2022
1 parent d45642d commit ca8fb1f
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 149 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
shell: powershell
- name: build binary
run: |
cargo build --release
cargo build --release --features dist
ls target/release/
mkdir output
cp target/release/rustpotter-cli.exe output/rustpotter-cli_win_x86_64.exe
Expand All @@ -105,11 +105,11 @@ jobs:
- name: build binary
run: |
export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/
cargo build --release
cargo build --release --features dist
mkdir output
cp target/release/rustpotter-cli output/rustpotter-cli_macos_x86_64
rustup target add aarch64-apple-darwin
cargo build --target aarch64-apple-darwin --release
cargo build --target aarch64-apple-darwin --release --features dist
cp target/aarch64-apple-darwin/release/rustpotter-cli output/rustpotter-cli_macos_aarch64
- name: artifact macos x86_64
uses: actions/upload-artifact@v3
Expand Down
111 changes: 3 additions & 108 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
[package]
name = "rustpotter-cli"
version = "0.10.0"
version = "0.10.1"
edition = "2021"
license = "Apache-2.0"
description = "CLI for Rustpotter, a free and open source wake word spotter forged in rust"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rustpotter = { version = "0.10.1", features = ["vad"] }
rustpotter = { version = "0.11.0", features = ["log", "vad"] }
log = "0.4.6"
pv_recorder = "1.0.2"
ctrlc = "3.2.2"
clap = { version = "3.1.13", features = ["derive"] }
hound = "3.4.0"
include_dir = "0.7.2"
tempfile = "3.3.0"
simple_logger = "2.1.0"
simple_logger = "2.1.0"

[features]
default = []
# include recorder library into the binary for distribution outside cargo
dist = []
33 changes: 23 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#[cfg(feature = "dist")]
use std::{env, fs, path::PathBuf};

fn main() {
let base_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
out_dir.pop();
out_dir.pop();
prepare_pv_recorder_lib(base_dir, out_dir);
#[cfg(feature = "dist")]
{
let base_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
out_dir.pop();
out_dir.pop();
prepare_pv_recorder_lib(base_dir, out_dir);
}
}
fn prepare_pv_recorder_lib (base_dir: PathBuf, build_dir: PathBuf) {
#[cfg(feature = "dist")]
fn prepare_pv_recorder_lib(base_dir: PathBuf, build_dir: PathBuf) {
let pv_recorder_lib_path = fs::read_dir(build_dir)
.unwrap()
.find_map(|entry| {
Expand All @@ -30,17 +35,25 @@ fn prepare_pv_recorder_lib (base_dir: PathBuf, build_dir: PathBuf) {
let windows_x86_64_binary = windows_folder.clone().join("amd64/libpv_recorder.dll");
let windows_x86_64_binary_dest = dist_folder.clone().join("windows/amd64");
fs::create_dir_all(windows_x86_64_binary_dest.clone()).unwrap();
fs::copy(windows_x86_64_binary, windows_x86_64_binary_dest.join("libpv_recorder.dll")).unwrap();
fs::copy(
windows_x86_64_binary,
windows_x86_64_binary_dest.join("libpv_recorder.dll"),
)
.unwrap();
}
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
let linux_folder = pv_recorder_lib_path.clone().join("linux");
let linux_x86_64_binary = linux_folder.clone().join("x86_64/libpv_recorder.so");
let linux_x86_64_binary_dest = dist_folder.clone().join("linux/x86_64");
fs::create_dir_all(linux_x86_64_binary_dest.clone()).unwrap();
fs::copy(linux_x86_64_binary, linux_x86_64_binary_dest.join("libpv_recorder.so")).unwrap();
fs::copy(
linux_x86_64_binary,
linux_x86_64_binary_dest.join("libpv_recorder.so"),
)
.unwrap();
}
#[cfg(all(target_os = "linux", any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(all(target_os = "linux", any(target_arch = "arm", target_arch = "aarch64")))]
let rpi_folder = pv_recorder_lib_path.clone().join("raspberry-pi");
#[cfg(all(target_os = "linux", target_arch = "arm"))]
{
Expand Down Expand Up @@ -128,4 +141,4 @@ fn prepare_pv_recorder_lib (base_dir: PathBuf, build_dir: PathBuf) {
}
println!("cargo:rerun-if-changed={:?}", dist_folder);
println!("cargo:rerun-if-changed={:?}", pv_recorder_lib_path);
}
}
12 changes: 6 additions & 6 deletions src/cli/devices.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use clap::Args;
use pv_recorder::RecorderBuilder;
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
use crate::pv_recorder_utils::_get_pv_recorder_lib;
#[derive(Args, Debug)]
/// Record audio sample
#[clap()]
pub struct DevicesCommand {}
pub fn devices(_: DevicesCommand) -> Result<(), String> {
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
let mut recorder_builder = RecorderBuilder::new();
#[cfg(debug_assertions)]
#[cfg(not(feature = "dist"))]
let recorder_builder = RecorderBuilder::new();
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
let lib_temp_path = _get_pv_recorder_lib();
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
recorder_builder.library_path(lib_temp_path.to_path_buf().as_path());
let recorder = recorder_builder.init()
.expect("Failed to initialize recorder");
Expand All @@ -27,7 +27,7 @@ pub fn devices(_: DevicesCommand) -> Result<(), String> {
}
Err(err) => panic!("Failed to get audio devices: {}", err),
};
#[cfg(all(not(debug_assertions), not(target_os = "windows")))]
#[cfg(all(feature = "dist", not(target_os = "windows")))]
lib_temp_path.close().expect("Unable to remove temp file");
Ok(())
}
8 changes: 4 additions & 4 deletions src/cli/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicBool, Ordering};

use clap::Args;
use pv_recorder::RecorderBuilder;
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
use crate::pv_recorder_utils::_get_pv_recorder_lib;
use rustpotter::{WakewordDetectorBuilder};

Expand All @@ -25,9 +25,9 @@ pub fn record(command: RecordCommand) -> Result<(), String> {
recorder_builder.frame_length(detector.get_samples_per_frame() as i32);
recorder_builder.device_index(command.device_index as i32);
recorder_builder.log_overflow(false);
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
let lib_temp_path = _get_pv_recorder_lib();
#[cfg(not(debug_assertions))]
#[cfg(feature = "dist")]
recorder_builder.library_path(lib_temp_path.to_path_buf().as_path());
let recorder = recorder_builder
.device_index(command.device_index as i32)
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn record(command: RecordCommand) -> Result<(), String> {
writer.write_sample(sample).unwrap();
}
println!("Done");
#[cfg(all(not(debug_assertions), not(target_os = "windows")))]
#[cfg(all(feature = "dist", not(target_os = "windows")))]
lib_temp_path.close().expect("Unable to remove temp file");
Ok(())
}
Loading

0 comments on commit ca8fb1f

Please sign in to comment.