From ac0a35a180311d8ad412d9fc0c756e6cb5035fd2 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Tue, 6 Oct 2026 15:04:52 -0700 Subject: [PATCH] robius-speech: link clang's runtime library on Apple platforms The Swift bridge calls into clang's runtime library, e.g. `__isPlatformVersionAtLeast` for its `#available` checks and `__chkstk_darwin` for stack probes. rustc links Apple targets with `-nodefaultlibs`, which leaves that library out, so linking an iOS app failed (as in Robrix's TestFlight build with Xcode 26.3). The build script now links `clang_rt.ios` (or `clang_rt.iossim`/`clang_rt.osx`) from clang's resource directory. --- crates/speech/build.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/speech/build.rs b/crates/speech/build.rs index d68a894..ed1b2de 100644 --- a/crates/speech/build.rs +++ b/crates/speech/build.rs @@ -101,4 +101,19 @@ fn apple_build(target_os: &str) { println!("cargo:rustc-link-search=native={path}"); } } + // Swift's `#available` checks call `__isPlatformVersionAtLeast` from clang's runtime library, + // which rustc leaves out since it links with `-nodefaultlibs`, so we link it ourselves. + let Ok(resource_dir) = Command::new("xcrun").args(["--sdk", sdk, "clang", "-print-resource-dir"]).output() else { + missing_toolchain("clang is not installed"); + }; + if !resource_dir.status.success() { + missing_toolchain("cannot locate clang's runtime libraries"); + } + println!("cargo:rustc-link-search=native={}/lib/darwin", String::from_utf8_lossy(&resource_dir.stdout).trim()); + let clang_runtime = match (target_os, simulator) { + ("macos", _) => "clang_rt.osx", + (_, true) => "clang_rt.iossim", + _ => "clang_rt.ios", + }; + println!("cargo:rustc-link-lib=static:-bundle={clang_runtime}"); }