Files
qbz/scripts/slint-dev-mac.sh
T
vicrodh 395e537b59 fix(build): drop compile-time x86 target-features — runtime AES dispatch
Users on CPUs without AES-NI (Nehalem i7-860, pre-2010 Intel Macs) or
without SSSE3 (AMD Phenom II) crashed at launch with SIGILL. The
global `-C target-feature=+aes,+ssse3` was kept after the #353/#343
x86-64-v3 incident on the belief that the aes crate's cpufeatures
runtime check would protect CPUs without AES-NI — but a compile-time
target feature makes cpufeatures compile its check to a constant, so
the AES-NI intrinsics ran unconditionally (credentials AES-GCM decrypt
at startup), and +ssse3 let LLVM autovectorize anywhere, breaking
Phenom II. Measured on the qbz-cmaf hot path (Ctr128BE<Aes128>
apply_keystream, 256 MB, release): 2145 MB/s compiled-in vs 2162 MB/s
runtime-dispatched, identical output — the flags bought nothing on
capable CPUs. Removed from .cargo/config.toml, all dev/build scripts
and the release/build workflows; old CPUs now get the software AES
fallback instead of a crash.

Fixes #549

cc
2026-07-05 14:17:46 -06:00

59 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# QBZ Slint — macOS dev build/run (Apple Silicon & Intel).
#
# macOS counterpart of slint-dev.sh / slint-dev-fast.sh. Same intent (build +
# run qbz-slint with the nightly PARALLEL FRONTEND so the giant Slint-generated
# module compiles across cores), but with the three Linux-only assumptions of
# those scripts removed because they break on Mach-O / Apple toolchains:
#
# 1. NO `-fuse-ld=mold`. mold only emits ELF; on macOS clang rejects it with
# "invalid linker name in argument '-fuse-ld=mold'" and the very first
# link (libc's build script) fails. Apple's default linker (ld-prime) is
# already fast, so we simply don't override the linker.
#
# 2. NO x86 target-features anywhere (#549): the aes crate runtime-dispatches
# to AES-NI at identical speed, and compile-time features SIGILL CPUs
# without them (pre-2010 Intel Macs). aarch64 gets its AES from the armv8
# crypto extensions automatically.
#
# 3. The nightly parallel frontend (`-Z threads`) is kept — it works on macOS
# and only cuts COMPILE time; the produced binary is identical to a plain
# `cargo build`/`cargo build --release`.
#
# By default this builds in RELEASE (release runtime perf is the whole reason we
# moved from Tauri to Slint — always measure at release). Pass --fast for a quick
# DEBUG build (opt-level 0, no debuginfo) for purely visual/layout iteration;
# DO NOT judge performance from a --fast build.
#
# Debug and release artifacts live in target/debug and target/release, so the
# two modes don't invalidate each other's cache.
#
# Usage: ./scripts/slint-dev-mac.sh [--fast] [extra cargo args]
# THREADS=8 ./scripts/slint-dev-mac.sh # override frontend threads
# ./scripts/slint-dev-mac.sh --fast -- --some-app-arg
set -euo pipefail
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
FAST=false
if [[ "${1:-}" == "--fast" ]]; then
FAST=true
shift
fi
# Parallel rustc frontend across cores. Defaults to the machine's logical CPU
# count; override with THREADS=N. This only speeds compilation.
THREADS="${THREADS:-$(sysctl -n hw.ncpu)}"
# No x86 target-features (#549): the aes crate runtime-dispatches to AES-NI
# at identical speed, and compile-time features SIGILL pre-2010 Intel Macs.
export RUSTFLAGS="-Z threads=${THREADS}"
if [[ "$FAST" == true ]]; then
# DEBUG: opt-level 0 skips the heavy LLVM passes; -C debuginfo=0 means less to
# generate and link. Unoptimised — never trust runtime behaviour from this.
export RUSTFLAGS="${RUSTFLAGS} -C debuginfo=0"
exec cargo +nightly run --manifest-path crates/Cargo.toml -p qbz "$@"
else
exec cargo +nightly run --release --manifest-path crates/Cargo.toml -p qbz "$@"
fi