Copy WebRTC into `Zed.app/Contents/Frameworks` when bundling the app

Antonio Scandurra created

Change summary

crates/zed/build.rs | 9 +++++++--
script/bundle       | 5 +++++
2 files changed, 12 insertions(+), 2 deletions(-)

Detailed changes

crates/zed/build.rs 🔗

@@ -7,8 +7,13 @@ fn main() {
         println!("cargo:rustc-env=ZED_AMPLITUDE_API_KEY={api_key}");
     }
 
-    // Find WebRTC.framework as a sibling of the executable when running outside of an application bundle
-    println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path");
+    if std::env::var("ZED_BUNDLE").ok().as_deref() == Some("true") {
+        // Find WebRTC.framework in the Frameworks folder when running as part of an application bundle.
+        println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../Frameworks");
+    } else {
+        // Find WebRTC.framework as a sibling of the executable when running outside of an application bundle.
+        println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path");
+    }
 
     // Register exported Objective-C selectors, protocols, etc
     println!("cargo:rustc-link-arg=-Wl,-ObjC");

script/bundle 🔗

@@ -33,6 +33,11 @@ lipo \
     -output \
     target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/cli
 
+echo "Copying WebRTC.framework into the frameworks folder"
+mkdir target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks
+cp -R target/x86_64-apple-darwin/release/WebRTC.framework target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks/
+rm -rf target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks/WebRTC.framework/Versions
+
 if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
     echo "Signing bundle with Apple-issued certificate"
     security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""