A free, open source, and extensible speech-to-text application that works completely offline.
fix(build): auto-fall-back to AI stub on Command Line Tools-only macOS (#1510)
paperterminal485f4ade0016
diff --git a/src-tauri/build.rs b/src-tauri/build.rsindex 5f97e647..66e209d9 100644--- a/src-tauri/build.rs+++ b/src-tauri/build.rs@@ -365,13 +365,45 @@ fn build_apple_intelligence_bridge() {// Check if the SDK supports FoundationModels (required for Apple Intelligence)let framework_path =Path::new(&sdk_path).join("System/Library/Frameworks/FoundationModels.framework");- let has_foundation_models = framework_path.exists();+ // HANDY_FORCE_AI_STUB=1 is an explicit escape hatch: force the stub even when+ // the active toolchain could build the real path (e.g. to skip the Swift+ // compile, or if the auto-detection below misfires). The common CLT-only case+ // is detected automatically just below, so this flag is rarely needed.+ let force_stub = env::var("HANDY_FORCE_AI_STUB").as_deref() == Ok("1");++ // Auto-detect a Command-Line-Tools-only toolchain. The CLT SDK contains+ // FoundationModels.framework, so the `framework_path.exists()` check alone+ // wrongly selects the real Swift path, which then fails to compile because+ // the CLT `swiftc` has no FoundationModelsMacros plugin (full Xcode only).+ // Detecting this lets a plain `cargo build` / `tauri dev` succeed without the+ // manual flag. Skipped when SWIFTC is overridden: that signals a custom+ // toolchain (e.g. the nixpkgs standalone-swift path supported above) whose+ // capabilities can't be inferred from `xcode-select`.+ let command_line_tools_only = env::var("SWIFTC").is_err() && is_command_line_tools_only();+ if command_line_tools_only && !force_stub {+ println!(+ "cargo:warning=Command Line Tools-only toolchain detected; Apple Intelligence \+ (FoundationModels) needs full Xcode. Falling back to stubs. Install Xcode and run \+ `sudo xcode-select -s /Applications/Xcode.app`, or set HANDY_FORCE_AI_STUB=1 to \+ silence this message."+ );+ }++ let has_foundation_models = framework_path.exists() && !force_stub && !command_line_tools_only;let source_file = if has_foundation_models {println!("cargo:warning=Building with Apple Intelligence support.");REAL_SWIFT_FILE} else {- println!("cargo:warning=Apple Intelligence SDK not found. Building with stubs.");+ // The SDK genuinely lacking FoundationModels is only one reason we build+ // stubs — CLT-only detection and HANDY_FORCE_AI_STUB (each warned about+ // above) also land here, and for those the framework does exist. Only+ // claim it's "not found" when that's actually true.+ if framework_path.exists() {+ println!("cargo:warning=Building Apple Intelligence with stubs.");+ } else {+ println!("cargo:warning=Apple Intelligence SDK not found. Building with stubs.");+ }STUB_SWIFT_FILE};@@ -470,3 +502,27 @@ fn build_apple_intelligence_bridge() {println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");}++/// Returns true when the active developer directory is the standalone Command+/// Line Tools rather than a full Xcode install.+///+/// `xcode-select -p` prints the active developer dir; the CLT install resolves+/// to a path ending in `CommandLineTools` (e.g. `/Library/Developer/CommandLineTools`),+/// whereas full Xcode resolves under `Xcode.app`. A CLT-only toolchain ships+/// FoundationModels.framework in its SDK but a `swiftc` without the+/// FoundationModelsMacros plugin, so the Apple Intelligence Swift path cannot+/// compile (issue #1448). On any error we conservatively return false so the+/// existing SDK-presence check decides.+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]+fn is_command_line_tools_only() -> bool {+ use std::process::Command;++ Command::new("xcode-select")+ .arg("-p")+ .output()+ .ok()+ .filter(|out| out.status.success())+ .and_then(|out| String::from_utf8(out.stdout).ok())+ .map(|path| path.trim().ends_with("CommandLineTools"))+ .unwrap_or(false)+}