From e07f4f3f53320a31a53813cb8f487e71cfb227d8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 16 Sep 2022 18:09:11 +0200 Subject: [PATCH] Copy WebRTC.framework in the `deps` directory Also, define the `rpath` on `live_kit` to avoid errors when running tests. --- crates/live_kit/build.rs | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/live_kit/build.rs b/crates/live_kit/build.rs index e34b4e2a3e..79d7d84cdd 100644 --- a/crates/live_kit/build.rs +++ b/crates/live_kit/build.rs @@ -1,5 +1,9 @@ use serde::Deserialize; -use std::{env, path::PathBuf, process::Command}; +use std::{ + env, + path::{Path, PathBuf}, + process::Command, +}; const SWIFT_PACKAGE_NAME: &'static str = "LiveKitBridge"; @@ -88,20 +92,16 @@ fn link_webrtc_framework(swift_target: &SwiftTarget) { "cargo:rustc-link-search=framework={}", swift_out_dir_path.display() ); + // Find WebRTC.framework as a sibling of the executable when running tests. + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path"); let source_path = swift_out_dir_path.join("WebRTC.framework"); - let target_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("../../../WebRTC.framework"); - assert!( - Command::new("cp") - .arg("-r") - .args(&[&source_path, &target_path]) - .status() - .unwrap() - .success(), - "could not copy WebRTC.framework from {:?} to {:?}", - source_path, - target_path - ); + let deps_dir_path = + PathBuf::from(env::var("OUT_DIR").unwrap()).join("../../../deps/WebRTC.framework"); + let target_dir_path = + PathBuf::from(env::var("OUT_DIR").unwrap()).join("../../../WebRTC.framework"); + copy_dir(&source_path, &deps_dir_path); + copy_dir(&source_path, &target_dir_path); } fn get_swift_target() -> SwiftTarget { @@ -124,6 +124,20 @@ fn swift_package_root() -> PathBuf { env::current_dir().unwrap().join(SWIFT_PACKAGE_NAME) } +fn copy_dir(source: &Path, destination: &Path) { + assert!( + Command::new("cp") + .arg("-r") + .args(&[source, destination]) + .status() + .unwrap() + .success(), + "could not copy {:?} to {:?}", + source, + destination + ); +} + impl SwiftTarget { fn out_dir_path(&self) -> PathBuf { swift_package_root()