#!/bin/sh # Builds native/build/DeepFilter.xcframework and copies the DeepFilterNet 3 # model beside it: Rikorose/DeepFilterNet's libDF (MIT or Apache-2.0) with # its C API, as a static library for Mac, iPhone and the iPhone simulator # (Apple silicon). # # Built rather than committed, as CallsBridge and RNNoise are. Needs rustup # (https://rustup.rs); the toolchain, its targets and cbindgen are pinned # and installed on first run. set -eu cd "$(dirname "$0")/.." commit=d375b2d8309e0935d165700c91da9de862a99c31 toolchain=1.92.0 cbindgen_version=0.29.2 out=build/DeepFilter.xcframework model=build/DeepFilterNet3_onnx.tar.gz stamp="$out/.built-$commit-$toolchain" if [ -f "$stamp" ] && [ -f "$model" ]; then exit 0; fi PATH="$HOME/.cargo/bin:$PATH" command -v rustup >/dev/null || { echo "build-deepfilter: rustup is required (https://rustup.rs)" >&2 exit 1 } targets="aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim" # shellcheck disable=SC2086 rustup toolchain install "$toolchain" --profile minimal $(printf ' -t %s' $targets) >/dev/null if [ "$(cbindgen --version 2>/dev/null)" != "cbindgen $cbindgen_version" ]; then cargo "+$toolchain" install cbindgen --version "$cbindgen_version" --locked fi work=build/deepfilter mkdir -p "$work" if [ ! -d "$work/src/.git" ]; then rm -rf "$work/src" git clone --quiet https://github.com/Rikorose/DeepFilterNet.git "$work/src" fi git -C "$work/src" -c advice.detachedHead=false checkout --quiet --force "$commit" # Deployment targets matching the apps, so the linker does not warn that # the library was built for newer systems than they run on. export MACOSX_DEPLOYMENT_TARGET=14.0 IPHONEOS_DEPLOYMENT_TARGET=17.0 for target in $targets; do cargo "+$toolchain" build --manifest-path "$work/src/Cargo.toml" -p deep_filter --lib \ --release --features capi --target "$target" --target-dir "$work/target" done headers="$work/headers" rm -rf "$headers" mkdir -p "$headers/DeepFilter" cbindgen --config "$work/src/cbindgen.toml" --crate deep_filter \ --output "$headers/DeepFilter/deep_filter.h" "$work/src/libDF" cat >"$headers/DeepFilter/module.modulemap" <<'EOF' module DeepFilter { header "deep_filter.h" link "df" export * } EOF rm -rf "$out" xcodebuild -create-xcframework \ -library "$work/target/aarch64-apple-darwin/release/libdf.a" -headers "$headers" \ -library "$work/target/aarch64-apple-ios/release/libdf.a" -headers "$headers" \ -library "$work/target/aarch64-apple-ios-sim/release/libdf.a" -headers "$headers" \ -output "$out" >/dev/null cp "$work/src/models/DeepFilterNet3_onnx.tar.gz" "$model" cp "$work/src/LICENSE-MIT" "$out/LICENSE-MIT" touch "$stamp" printf 'Built %s/%s\n' "$PWD" "$out"