diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index c76ced4..7adb31f 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -15,7 +15,7 @@ jobs: rust: [stable, beta] steps: - - uses: hecrj/setup-rust-action@v1 + - uses: hecrj/setup-rust-action@v2 with: rust-version: ${{ matrix.rust }}${{ matrix.toolchain }} - uses: actions/checkout@v2 @@ -29,7 +29,7 @@ jobs: sudo apt-get install -y libasound2-dev - name: Run tests run: | - cargo test --verbose --workspace + cargo test --verbose --workspace --all-features test-windows: name: Test (Windows) @@ -37,14 +37,11 @@ jobs: strategy: matrix: rust: [stable, beta] - include: - - os: windows-latest - toolchain: -gnu steps: - - uses: hecrj/setup-rust-action@v1 + - uses: hecrj/setup-rust-action@v2 with: - rust-version: ${{ matrix.rust }}${{ matrix.toolchain }} + rust-version: ${{ matrix.rust }} - uses: actions/checkout@v2 with: submodules: true @@ -53,7 +50,7 @@ jobs: args: install -y pkgconfiglite --checksum 6004df17818f5a6dbf19cb335cc92702 - name: Run tests run: | - cargo test --verbose --workspace + cargo test --verbose --workspace --all-features fmt: name: Rustfmt diff --git a/Cargo.toml b/Cargo.toml index 6a3329f..1492132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ members = ["libmysofa-sys"] [dependencies] ffi = { package = "libmysofa-sys", version = "0.1", path = "libmysofa-sys" } -realfft = {version = "3.2", optional = true} +realfft = {version = "3.3", optional = true} thiserror = "1" [dev-dependencies] @@ -28,9 +28,9 @@ anyhow = "1.0" assert_approx_eq = "1.1" hound = "3.5" cpal = "0.15" -criterion = "0.4" +criterion = "0.5" rand = "0.8" -ringbuf = "0.3" +ringbuf = "0.4" [[bench]] name = "renderer" diff --git a/examples/renderer.rs b/examples/renderer.rs index 595f380..e238bea 100644 --- a/examples/renderer.rs +++ b/examples/renderer.rs @@ -7,7 +7,7 @@ use hound::WavReader; use sofar::reader::{Filter, OpenOptions, Sofar}; use sofar::render::Renderer; -use ringbuf::HeapRb; +use ringbuf::{traits::*, HeapRb}; use std::sync::{Arc, Condvar, Mutex}; use std::{env, io::Read}; @@ -92,7 +92,7 @@ where let (mut producer, mut consumer) = ringbuf.split(); for _ in 0..BLOCK_LEN { - producer.push(0.0).unwrap(); + producer.try_push(0.0).unwrap(); } let stream = device.build_output_stream( @@ -111,7 +111,7 @@ where return; } - while data_samples >= consumer.len() { + while data_samples >= consumer.occupied_len() { let src = reader .samples::() .take(BLOCK_LEN) @@ -125,14 +125,14 @@ where .unwrap(); for (l, r) in Iterator::zip(left.iter(), right.iter()) { - producer.push(*l).unwrap(); - producer.push(*r).unwrap(); + producer.try_push(*l).unwrap(); + producer.try_push(*r).unwrap(); } } for dst in data.chunks_exact_mut(2) { - dst[0] = consumer.pop().unwrap(); - dst[1] = consumer.pop().unwrap(); + dst[0] = consumer.try_pop().unwrap(); + dst[1] = consumer.try_pop().unwrap(); } }, |err| eprintln!("An error occurred on stream: {}", err), diff --git a/libmysofa-sys/Cargo.toml b/libmysofa-sys/Cargo.toml index 254d452..ae0c178 100644 --- a/libmysofa-sys/Cargo.toml +++ b/libmysofa-sys/Cargo.toml @@ -16,8 +16,9 @@ exclude = ["libmysofa/tests"] libz-sys = { version = "1.1", default-features = false, features = ["static", "libc"] } [build-dependencies] -cmake = "0.1" -system-deps = "6.1" +cc = "1.0" +system-deps = "7.0" +cmake = { version = "0.1", optional = true } [package.metadata.system-deps] libmysofa = "1" diff --git a/libmysofa-sys/build.rs b/libmysofa-sys/build.rs index 1b62f68..20a58b5 100644 --- a/libmysofa-sys/build.rs +++ b/libmysofa-sys/build.rs @@ -1,24 +1,65 @@ -use cmake::Config; use system_deps::{BuildInternalClosureError, Library}; use std::env; pub fn build_from_src(lib: &str, version: &str) -> Result { - let mut config = Config::new("libmysofa"); + let lib = lib.strip_prefix("lib").unwrap_or(lib); + let dst = std::path::PathBuf::from(env::var_os("OUT_DIR").unwrap()); let z_root = env::var_os("DEP_Z_ROOT").unwrap(); + let z_inc = std::path::PathBuf::from(&z_root).join("include"); + let z_lib = std::path::PathBuf::from(&z_root).join("lib"); - let dst = config - .define("BUILD_TESTS", "OFF") - .define("BUILD_STATIC_LIBS", "ON") - .define("BUILD_SHARED_LIBS", "OFF") - .define("CODE_COVERAGE", "OFF") - .define("ADDRESS_SANITIZE", "OFF") - .define("ZLIB_ROOT", z_root) - .profile("Release") - .build(); + let mut cfg = cc::Build::new(); + cfg.flag_if_supported("-Wno-sign-compare") + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable") + .include(z_inc) + .include("libmysofa/src/hrtf") + .include("src") + .file("libmysofa/src/hrtf/cache.c") + .file("libmysofa/src/hdf/gunzip.c") + .file("libmysofa/src/hdf/gcol.c") + .file("libmysofa/src/hrtf/tools.c") + .file("libmysofa/src/hdf/superblock.c") + .file("libmysofa/src/hrtf/loudness.c") + .file("libmysofa/src/hrtf/lookup.c") + .file("libmysofa/src/hdf/btree.c") + .file("libmysofa/src/hrtf/minphase.c") + .file("libmysofa/src/hrtf/neighbors.c") + .file("libmysofa/src/hrtf/easy.c") + .file("libmysofa/src/hrtf/check.c") + .file("libmysofa/src/hrtf/kdtree.c") + .file("libmysofa/src/hrtf/spherical.c") + .file("libmysofa/src/hrtf/reader.c") + .file("libmysofa/src/hdf/fractalhead.c") + .file("libmysofa/src/hrtf/interpolate.c") + .file("libmysofa/src/hrtf/resample.c") + .file("libmysofa/src/hdf/dataobject.c") + .file("libmysofa/src/resampler/speex_resampler.c") + .compile(lib); - let pkg_dir = dst.join("lib/pkgconfig"); - Library::from_internal_pkg_config(pkg_dir, lib, version) + Ok(Library { + name: lib.to_owned(), + version: version.to_owned(), + source: system_deps::Source::EnvVariables, + link_paths: vec![dst, z_lib.to_owned()], + libs: vec![ + system_deps::InternalLib { + name: lib.to_owned(), + is_static_available: false, + }, + system_deps::InternalLib { + name: "z".to_owned(), + is_static_available: false, + }, + ], + frameworks: Default::default(), + framework_paths: Default::default(), + include_paths: Default::default(), + defines: Default::default(), + ld_args: Default::default(), + statik: true, + }) } fn main() { diff --git a/libmysofa-sys/libmysofa b/libmysofa-sys/libmysofa index 0b6c965..da9e4ad 160000 --- a/libmysofa-sys/libmysofa +++ b/libmysofa-sys/libmysofa @@ -1 +1 @@ -Subproject commit 0b6c96541cbabcaf4ace1a0f48d3aef548be448d +Subproject commit da9e4adc619ee3d1ae5e68da3ed14aa5e60b3ec1 diff --git a/libmysofa-sys/src/config.h b/libmysofa-sys/src/config.h new file mode 100644 index 0000000..ecb1b5d --- /dev/null +++ b/libmysofa-sys/src/config.h @@ -0,0 +1,9 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#define CMAKE_INSTALL_PREFIX "/usr/local" +#define CPACK_PACKAGE_VERSION_MAJOR 1 +#define CPACK_PACKAGE_VERSION_MINOR 3 +#define CPACK_PACKAGE_VERSION_PATCH 2 + +#endif // _CONFIG_H diff --git a/libmysofa-sys/src/mysofa_export.h b/libmysofa-sys/src/mysofa_export.h new file mode 100644 index 0000000..9d704df --- /dev/null +++ b/libmysofa-sys/src/mysofa_export.h @@ -0,0 +1,7 @@ +#ifndef MYSOFA_EXPORT_H_ +#define MYSOFA_EXPORT_H_ + +#define MYSOFA_EXPORT +#define MYSOFA_NO_EXPORT + +#endif // MYSOFA_EXPORT_H_