Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable building libmysofa without cmake #1

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,22 +29,19 @@ 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)
runs-on: windows-latest
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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ 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]
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"
Expand Down
14 changes: 7 additions & 7 deletions examples/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(
Expand All @@ -111,7 +111,7 @@ where
return;
}

while data_samples >= consumer.len() {
while data_samples >= consumer.occupied_len() {
let src = reader
.samples::<f32>()
.take(BLOCK_LEN)
Expand All @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions libmysofa-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.101"
system-deps = "7.0"
cmake = { version = "0.1", optional = true }

[package.metadata.system-deps]
libmysofa = "1"
67 changes: 54 additions & 13 deletions libmysofa-sys/build.rs
Original file line number Diff line number Diff line change
@@ -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<Library, BuildInternalClosureError> {
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() {
Expand Down
9 changes: 9 additions & 0 deletions libmysofa-sys/src/config.h
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions libmysofa-sys/src/mysofa_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef MYSOFA_EXPORT_H_
#define MYSOFA_EXPORT_H_

#define MYSOFA_EXPORT
#define MYSOFA_NO_EXPORT

#endif // MYSOFA_EXPORT_H_
Loading