oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/sh
2# Builds native/build/RNNoise.xcframework: xiph's RNNoise (BSD-3) as a
3# static library for Mac, iPhone and the iPhone simulator.
4#
5# Built rather than committed, as CallsBridge is: the model's weights come
6# as a generated C file of 78 MB (rnnoise_data.c), which is no more source
7# than a framework binary is. Both the code and the model are pinned — the
8# code to a commit, the model to its SHA-256, which is also its name.
9set -eu
10cd "$(dirname "$0")/.."
11
12commit=70f1d256acd4b34a572f999a05c87bf00b67730d
13model=0a8755f8e2d834eff6a54714ecc7d75f9932e845df35f8b59bc52a7cfe6e8b37
14out=build/RNNoise.xcframework
15stamp="$out/.built-$commit-$model"
16if [ -f "$stamp" ]; then exit 0; fi
17
18work=build/rnnoise
19mkdir -p "$work"
20if [ ! -d "$work/src/.git" ]; then
21 rm -rf "$work/src"
22 git clone --quiet https://gitlab.xiph.org/xiph/rnnoise.git "$work/src"
23fi
24git -C "$work/src" -c advice.detachedHead=false checkout --quiet "$commit"
25
26tarball="$work/rnnoise_data-$model.tar.gz"
27if [ ! -f "$tarball" ]; then
28 curl --fail --silent --show-error --location -o "$tarball.part" \
29 "https://media.xiph.org/rnnoise/models/rnnoise_data-$model.tar.gz"
30 mv "$tarball.part" "$tarball"
31fi
32echo "$model $tarball" | shasum -a 256 -c --status || {
33 echo "build-rnnoise: model checksum mismatch; delete $tarball and retry" >&2
34 exit 1
35}
36tar -xzf "$tarball" -C "$work/src" src/rnnoise_data.c src/rnnoise_data.h
37
38sources="denoise.c rnn.c pitch.c kiss_fft.c celt_lpc.c nnet.c nnet_default.c parse_lpcnet_weights.c rnnoise_tables.c rnnoise_data.c"
39
40# One static library per platform, fat across its architectures.
41build_slice() { # name sdk "triple triple..."
42 name=$1 sdk=$2 triples=$3
43 root=$(xcrun --sdk "$sdk" --show-sdk-path)
44 libs=""
45 for triple in $triples; do
46 objdir="$work/obj/$name/$triple"
47 mkdir -p "$objdir"
48 for f in $sources; do
49 clang -c -O3 -target "$triple" -isysroot "$root" -fvisibility=hidden -DRNNOISE_BUILD \
50 -I"$work/src/include" -I"$work/src/src" "$work/src/src/$f" -o "$objdir/${f%.c}.o" &
51 done
52 wait
53 libtool -static -o "$objdir/librnnoise.a" "$objdir"/*.o
54 libs="$libs $objdir/librnnoise.a"
55 done
56 mkdir -p "$work/lib/$name"
57 # shellcheck disable=SC2086
58 lipo -create $libs -output "$work/lib/$name/librnnoise.a"
59}
60build_slice macos macosx "arm64-apple-macos14.0 x86_64-apple-macos14.0"
61build_slice ios iphoneos "arm64-apple-ios17.0"
62build_slice simulator iphonesimulator "arm64-apple-ios17.0-simulator x86_64-apple-ios17.0-simulator"
63
64# Headers in a subdirectory of their own: Xcode copies every static
65# xcframework's headers into one include directory, and two module maps at
66# its root collide.
67headers="$work/headers"
68rm -rf "$headers"
69mkdir -p "$headers/RNNoise"
70cp "$work/src/include/rnnoise.h" "$headers/RNNoise/"
71cat >"$headers/RNNoise/module.modulemap" <<'EOF'
72module RNNoise {
73 header "rnnoise.h"
74 link "rnnoise"
75 export *
76}
77EOF
78
79rm -rf "$out"
80xcodebuild -create-xcframework \
81 -library "$work/lib/macos/librnnoise.a" -headers "$headers" \
82 -library "$work/lib/ios/librnnoise.a" -headers "$headers" \
83 -library "$work/lib/simulator/librnnoise.a" -headers "$headers" \
84 -output "$out" >/dev/null
85cp "$work/src/COPYING" "$out/COPYING"
86touch "$stamp"
87printf 'Built %s/%s\n' "$PWD" "$out"
88