Split any YouTube song into stems
TypeScript
fix: ship an Intel mac build — x64 dmg/zip targets, universal bundled ffmpeg
Anton Sychevaa172219736a
diff --git a/README.md b/README.mdindex 253963c..27df3b2 100644--- a/README.md+++ b/README.md@@ -26,7 +26,7 @@ Everything runs locally — no accounts, no API keys. Your songs, searches and a## DownloadGrab installers from [Releases](https://github.com/danvelope/stemkit/releases):-- **macOS** (Apple Silicon): `StemKit-x.y.z-mac-arm64.dmg`+- **macOS**: `StemKit-x.y.z-mac-arm64.dmg` (Apple Silicon) or `StemKit-x.y.z-mac-x64.dmg` (Intel)- **Windows**: `StemKit-Setup-x.y.z.exe` (installer) or portable `.zip`- **Linux** (x64): `StemKit-x.y.z-linux-x86_64.AppImage` (portable, self-updating) or `StemKit-x.y.z-linux-amd64.deb`@@ -47,7 +47,7 @@ Optional quality upgrades live behind a gear icon in the app (Settings), each wi- No manual installs: if no Python 3.9+ is detected, StemKit downloads a private runtime (python-build-standalone) during first-launch setup- Node.js 20+ only for building from source-> **Intel Mac**: supported for running from source. PyTorch publishes no macOS x86_64 wheels past 2.2.2, so first-launch setup installs that build instead of the 2.5.1 used everywhere else. MPS is still available on that build when the machine has a Metal-capable GPU (verified on an Intel Mac with a discrete GPU); integrated-only Macs fall back to CPU. Packaged `.dmg`/`.zip` targets are still `arm64`-only, so there is no Intel installer to download yet.+> **Intel Mac**: PyTorch publishes no macOS x86_64 wheels past 2.2.2, so first-launch setup installs that build instead of the 2.5.1 used everywhere else. MPS is still available on that build when the machine has a Metal-capable GPU (verified on an Intel Mac with a discrete GPU); integrated-only Macs fall back to CPU.## Develop@@ -61,7 +61,7 @@ Wrong Node version? Scripts auto-relaunch with a suitable one (nvm / nvm-windows## Build & release```bash-bash scripts/fetch-ffmpeg.sh # mac (builds ffmpeg + libsoxr for the host arch, needs cmake) / linux (one time)+bash scripts/fetch-ffmpeg.sh # mac (compiles arm64 + x86_64 ffmpeg + libsoxr, needs cmake) / linux (one time)powershell scripts/fetch-ffmpeg.ps1 # windows (one time)npm run dist # mac dmg -> release/diff --git a/electron-builder.yml b/electron-builder.ymlindex 65ef503..2131899 100644--- a/electron-builder.yml+++ b/electron-builder.yml@@ -17,13 +17,18 @@ extraResources:mac:category: public.app-category.musicicon: build/icon.png+ # both slices: the bundled ffmpeg is universal (see scripts/fetch-ffmpeg.sh),+ # so the x64 dmg carries a working Intel binary even though CI only has+ # arm64 macOS runners to build it ontarget:- target: dmgarch:- arm64+ - x64- target: ziparch:- arm64+ - x64extraResources:- from: extras/ffmpeg-mac/ffmpegto: ffmpeg/ffmpegdiff --git a/scripts/fetch-ffmpeg.sh b/scripts/fetch-ffmpeg.shindex 9496d12..82e0d37 100755--- a/scripts/fetch-ffmpeg.sh+++ b/scripts/fetch-ffmpeg.sh@@ -8,108 +8,131 @@ mkdir -p "$ROOT/extras"# the pipeline resamples with soxr, so every bundled ffmpeg must be built# with libsoxr. There is no public static macOS build with libsoxr for either# architecture (evermeet.cx is x86_64 without soxr, osxexperts.net ships arm64-# without soxr), so the mac path compiles ffmpeg + soxr from source for-# whichever arch the host Mac actually runs+# without soxr), so the mac path compiles ffmpeg + soxr from source.+#+# It compiles BOTH slices and lipo-merges them. GitHub no longer offers Intel+# macOS runners, so the release job always cross-compiles the x86_64 slice on+# an arm64 host — a single-arch build would put an arm64-only ffmpeg inside the+# x64 dmg and fail every Intel split with "Something went wrong with the+# built-in audio tools".SOXR_VERSION="0.1.3"FFMPEG_VERSION="9.0.2"--# detect the native CPU arch once. hw.optional.arm64 is kernel truth — a shell-# or binary running under Rosetta makes uname -m report x86_64 even on an-# Apple Silicon Mac-function mac_native_arch() {- if [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]; then- echo "arm64"- else- echo "x86_64"- fi-}+MAC_ARCHS=(arm64 x86_64)+# 11.0 is the floor for the arm64 slice; x86_64 would run back to 10.13 but a+# single target keeps the two slices' objects linkable+MAC_DEPLOY_TARGET="11.0"function mac_ffmpeg_is_usable() {local bin="$1"- local expected_arch="$2"[[ -x "$bin" ]] || return 1- file "$bin" 2>/dev/null | grep -q "$expected_arch" || return 1+ local have+ have="$(lipo -archs "$bin" 2>/dev/null)" || return 1+ local a+ for a in "${MAC_ARCHS[@]}"; do+ [[ " $have " == *" $a "* ]] || return 1+ done"$bin" -hide_banner -buildconf 2>/dev/null | grep -q -- --enable-libsoxr}+# ffmpeg bakes exactly one architecture into config.h at configure time, so a+# single -arch arm64 -arch x86_64 pass does not work: the arm64 slice then+# compiles libavcodec/x86/mathops.h inline asm and dies on+# "invalid input constraint 'c' in asm". Each slice therefore gets its own+# configure + build, and the binaries are merged with lipo.function build_mac_ffmpeg() {local out="$1"- local target_arch- target_arch="$(mac_native_arch)"-- # if the script is running under Rosetta on an arm64 Mac (e.g. an x86_64- # bash from anaconda or Homebrew), re-exec natively so clang builds the- # correct slice — configure would otherwise pick x86_64 from uname -m- if [[ "$(uname -m)" != "$target_arch" ]]; then- exec arch -"$target_arch" /bin/bash "$0" "$@"- fiif ! command -v cmake >/dev/null 2>&1; thenecho "cmake is required to build the bundled ffmpeg — install it first (e.g. brew install cmake)"exit 1fi- # arm64 requires macOS 11.0+; x86_64 works back to 10.13- if [[ "$target_arch" == "arm64" ]]; then- local deploy_target="11.0"+ # hw.optional.arm64 is kernel truth — a shell running under Rosetta makes+ # uname -m report x86_64 even on an Apple Silicon Mac. Only the non-native+ # slice may use --enable-cross-compile; forcing it on the native one skips+ # host probes ffmpeg otherwise passes+ local native_arch+ if [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]; then+ native_arch="arm64"else- local deploy_target="10.13"+ native_arch="x86_64"fiTMP="$(mktemp -d)"trap 'rm -rf "$TMP"' EXIT- PREFIX="$TMP/prefix"JOBS="$(sysctl -n hw.ncpu)"- echo "building libsoxr $SOXR_VERSION ($target_arch)..."curl -fsSL -o "$TMP/soxr.tar.gz" "https://github.com/chirlu/soxr/archive/refs/tags/$SOXR_VERSION.tar.gz"tar -xzf "$TMP/soxr.tar.gz" -C "$TMP"- cmake -S "$TMP/soxr-$SOXR_VERSION" -B "$TMP/soxr-build" \- -DBUILD_SHARED_LIBS=OFF \- -DBUILD_TESTS=OFF \- -DCMAKE_BUILD_TYPE=Release \- -DCMAKE_OSX_ARCHITECTURES="$target_arch" \- -DCMAKE_OSX_DEPLOYMENT_TARGET="$deploy_target" \- -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \- -DCMAKE_INSTALL_PREFIX="$PREFIX" >/dev/null- cmake --build "$TMP/soxr-build" --target install --parallel "$JOBS" >/dev/null-- # x86_64 builds need nasm for hand-optimized assembly; rather than require- # another dependency, disable x86asm — the performance difference is- # negligible for audio processing- local x86asm_flag="--disable-x86asm"- if [[ "$target_arch" == "arm64" ]]; then- x86asm_flag=""- fi-- echo "building ffmpeg $FFMPEG_VERSION ($target_arch, static libsoxr) — this takes a few minutes..."curl -fsSL -o "$TMP/ffmpeg.tar.xz" "https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.xz"tar -xf "$TMP/ffmpeg.tar.xz" -C "$TMP"- (- cd "$TMP/ffmpeg-$FFMPEG_VERSION"- PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure \- --enable-libsoxr \- --disable-autodetect \- --enable-zlib \- --enable-bzlib \- --disable-ffplay \- --disable-ffprobe \- --disable-doc \- --disable-debug \- $x86asm_flag \- --pkg-config-flags=--static \- --extra-cflags="-I$PREFIX/include -mmacosx-version-min=$deploy_target" \- --extra-ldflags="-L$PREFIX/lib -mmacosx-version-min=$deploy_target" >/dev/null- make --silent --jobs "$JOBS" >/dev/null- )++ local SLICES=() ARCH FF_ARCH PREFIX+ for ARCH in "${MAC_ARCHS[@]}"; do+ # ffmpeg's configure calls the arm64 target aarch64+ FF_ARCH="$ARCH"+ if [[ "$ARCH" == "arm64" ]]; then+ FF_ARCH="aarch64"+ fi+ PREFIX="$TMP/$ARCH/prefix"++ echo "building libsoxr $SOXR_VERSION ($ARCH)..."+ cmake -S "$TMP/soxr-$SOXR_VERSION" -B "$TMP/$ARCH/soxr-build" \+ -DBUILD_SHARED_LIBS=OFF \+ -DBUILD_TESTS=OFF \+ -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_OSX_ARCHITECTURES="$ARCH" \+ -DCMAKE_OSX_DEPLOYMENT_TARGET="$MAC_DEPLOY_TARGET" \+ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \+ -DCMAKE_INSTALL_PREFIX="$PREFIX" >/dev/null+ cmake --build "$TMP/$ARCH/soxr-build" --target install --parallel "$JOBS" >/dev/null++ echo "building ffmpeg $FFMPEG_VERSION ($ARCH, static libsoxr) — this takes a few minutes..."+ # x86_64 hand-optimized assembly needs nasm; rather than add a build+ # dependency, skip it — the only resampler this app uses is soxr+ # (plain strings, not arrays: macOS ships bash 3.2, where expanding an+ # empty array under set -u aborts the script)+ local cross_flags="" asm_flags=""+ if [[ "$ARCH" != "$native_arch" ]]; then+ cross_flags="--enable-cross-compile --target-os=darwin"+ fi+ if [[ "$ARCH" == "x86_64" ]]; then+ asm_flags="--disable-x86asm"+ fi++ rm -rf "$TMP/$ARCH/src"+ mkdir -p "$TMP/$ARCH"+ cp -R "$TMP/ffmpeg-$FFMPEG_VERSION" "$TMP/$ARCH/src"+ (+ cd "$TMP/$ARCH/src"+ PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure \+ --arch="$FF_ARCH" \+ --cc="clang -arch $ARCH" \+ $cross_flags \+ $asm_flags \+ --enable-libsoxr \+ --disable-autodetect \+ --enable-zlib \+ --enable-bzlib \+ --disable-ffplay \+ --disable-ffprobe \+ --disable-doc \+ --disable-debug \+ --pkg-config-flags=--static \+ --extra-cflags="-I$PREFIX/include -arch $ARCH -mmacosx-version-min=$MAC_DEPLOY_TARGET" \+ --extra-ldflags="-L$PREFIX/lib -arch $ARCH -mmacosx-version-min=$MAC_DEPLOY_TARGET" >/dev/null+ make --silent --jobs "$JOBS" >/dev/null+ )+ SLICES+=("$TMP/$ARCH/src/ffmpeg")+ donemkdir -p "$OUT"- cp -f "$TMP/ffmpeg-$FFMPEG_VERSION/ffmpeg" "$out"+ lipo -create "${SLICES[@]}" -output "$out"chmod +x "$out"xattr -dr com.apple.quarantine "$out" 2>/dev/null || true- if ! mac_ffmpeg_is_usable "$out" "$target_arch"; then- echo "built ffmpeg is not usable (wrong arch or missing libsoxr)" >&2+ if ! mac_ffmpeg_is_usable "$out"; then+ echo "built ffmpeg is not usable (missing an arch slice or libsoxr)" >&2rm -f "$out"exit 1fi@@ -117,14 +140,13 @@ function build_mac_ffmpeg() {if [[ "$OS" == "Darwin" ]]; thenOUT="$ROOT/extras/ffmpeg-mac"- EXPECTED_ARCH="$(mac_native_arch)"- if mac_ffmpeg_is_usable "$OUT/ffmpeg" "$EXPECTED_ARCH"; then+ if mac_ffmpeg_is_usable "$OUT/ffmpeg"; thenecho "ffmpeg already present: $OUT/ffmpeg""$OUT/ffmpeg" -version | head -1exit 0fiif [[ -e "$OUT/ffmpeg" ]]; then- echo "existing ffmpeg is unusable (wrong CPU arch or missing libsoxr) — replacing it..."+ echo "existing ffmpeg is unusable (missing an arch slice or libsoxr) — replacing it..."rm -f "$OUT/ffmpeg"fibuild_mac_ffmpeg "$OUT/ffmpeg"