"""Bundle the local development app. Distribution signing is a separate step.""" import json from pathlib import Path import plistlib import shutil import subprocess import sys configuration = sys.argv[1] if len(sys.argv) > 1 else 'debug' if configuration not in ('debug', 'release'): raise ValueError('invalid build configuration') root = Path(__file__).resolve().parent.parent products = Path(subprocess.check_output(['swift', 'build', '--package-path', str(root / 'apple'), '--configuration', configuration, '--show-bin-path'], text=True).strip()) bundle = root / 'build/Calls.app/Contents' if bundle.parent.exists(): shutil.rmtree(bundle.parent) (bundle / 'MacOS').mkdir(parents=True, exist_ok=True) (bundle / 'Frameworks').mkdir(parents=True, exist_ok=True) (bundle / 'Resources').mkdir(parents=True, exist_ok=True) shutil.copy2(products / 'CallsMac', bundle / 'MacOS/CallsMac') subprocess.run(['swift', str(root / 'scripts/generate-mac-icon.swift')], check=True) icon = root / 'apple/Sources/CallsMac/Resources/MacIcon.png' shutil.copy2(icon, bundle / 'Resources/MacIcon.png') shutil.copy2(root / 'LICENSE.lucide', bundle / 'Resources/LICENSE.lucide') shutil.copy2(root / 'LICENSE.rnnoise', bundle / 'Resources/LICENSE.rnnoise') shutil.copy2(root / 'LICENSE.deepfilternet', bundle / 'Resources/LICENSE.deepfilternet') # The Rust crates libdf links (scripts/deepfilter-notices.py) and WebRTC's # own licence, for the LiveKitWebRTC framework embedded below. shutil.copy2(root / 'LICENSE.deepfilternet-crates', bundle / 'Resources/LICENSE.deepfilternet-crates') shutil.copy2(root / 'LICENSE.webrtc', bundle / 'Resources/LICENSE.webrtc') shutil.copy2(root / 'PATENTS.webrtc', bundle / 'Resources/PATENTS.webrtc') # The Mac's noise suppressor model (scripts/build-deepfilter.sh). Without # it the app falls back to RNNoise. shutil.copy2(root / 'build/DeepFilterNet3_onnx.tar.gz', bundle / 'Resources/DeepFilterNet3_onnx.tar.gz') # macOS 26 and later draw an app's icon from an asset catalog: full-bleed # artwork that the system masks, lights and tints itself. An app with only an # ICNS is legacy there, its artwork shrunk onto a plain squircle. So compile # the square master (the iPhone's, which is opaque and unrounded) as an Icon # Composer .icon into Assets.car, named by CFBundleIconName. actool also # flattens it into renditions on the 824-point grid for macOS 14 and 15. icon_package = root / 'build/AppIcon.icon' if icon_package.exists(): shutil.rmtree(icon_package) (icon_package / 'Assets').mkdir(parents=True) shutil.copy2(root / 'ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png', icon_package / 'Assets/calls.png') (icon_package / 'icon.json').write_text(json.dumps({ 'fill': 'automatic', 'groups': [{'layers': [{'glass': False, 'image-name': 'calls.png', 'name': 'calls'}], 'shadow': {'kind': 'neutral', 'opacity': 0.5}, 'translucency': {'enabled': False, 'value': 0}}], 'supported-platforms': {'squares': ['macOS']}, }, indent=2)) catalog = root / 'build/AssetCatalog' if catalog.exists(): shutil.rmtree(catalog) catalog.mkdir(parents=True) subprocess.run(['xcrun', 'actool', str(icon_package), '--compile', str(catalog), '--platform', 'macosx', '--minimum-deployment-target', '14.0', '--app-icon', 'AppIcon', '--output-partial-info-plist', str(catalog / 'partial.plist'), '--errors', '--warnings'], check=True, stdout=subprocess.DEVNULL) if not (catalog / 'Assets.car').exists(): raise SystemExit('actool wrote no Assets.car: an Xcode that compiles .icon (26 or later) is required') shutil.copy2(catalog / 'Assets.car', bundle / 'Resources/Assets.car') # The ICNS stays as CFBundleIconFile for anything that reads only that key. # The PNG is the Dock icon for a run outside a bundle (CallsMac.swift). iconset = root / 'build/AppIcon.iconset' iconset.mkdir(parents=True, exist_ok=True) for size in (16, 32, 128, 256, 512): for scale in (1, 2): name = f'icon_{size}x{size}' + ('@2x' if scale == 2 else '') + '.png' subprocess.run(['sips', '-z', str(size * scale), str(size * scale), str(icon), '--out', str(iconset / name)], check=True, stdout=subprocess.DEVNULL) subprocess.run(['iconutil', '-c', 'icns', str(iconset), '-o', str(bundle / 'Resources/CallsMac.icns')], check=True) info = { 'CFBundleURLTypes': [{'CFBundleURLName': 'net.amadan.oficina.calls.join', 'CFBundleURLSchemes': ['oficina-calls']}], 'CFBundleName': 'Calls', 'CFBundleDisplayName': 'Calls', 'CFBundleIdentifier': 'net.amadan.oficina.calls', 'CFBundleExecutable': 'CallsMac', 'CFBundlePackageType': 'APPL', 'CFBundleIconFile': 'CallsMac.icns', 'CFBundleIconName': 'AppIcon', 'CFBundleShortVersionString': '0.1.0', 'CFBundleVersion': '1', 'LSMinimumSystemVersion': '14.0', 'NSHighResolutionCapable': True, 'NSCameraUseContinuityCameraDeviceType': True, 'NSCameraUsageDescription': 'Calls uses your camera to share video in a meeting.', 'NSMicrophoneUsageDescription': 'Calls uses your microphone so people in the meeting can hear you.', } (bundle / 'Info.plist').write_bytes(plistlib.dumps(info)) # SwiftPM links dynamic binary dependencies using @rpath. Embed just the macOS # slice rather than shipping iOS and simulator frameworks inside the Mac app. for xc in [root / 'build/CallsBridge.xcframework', *list((root / 'apple/.build/artifacts').rglob('LiveKitWebRTC.xcframework'))]: manifest = plistlib.loads((xc / 'Info.plist').read_bytes()) for lib in manifest['AvailableLibraries']: if lib['SupportedPlatform'] != 'macos': continue source = xc / lib['LibraryIdentifier'] / lib['LibraryPath'] binary = source / source.stem if 'dynamically linked' not in subprocess.check_output(['file', str(binary)], text=True): continue dest = bundle / 'Frameworks' / source.name if dest.exists(): shutil.rmtree(dest) shutil.copytree(source, dest, symlinks=True) for resource in products.glob('*.bundle'): shutil.copytree(resource, bundle / 'Resources' / resource.name, symlinks=True) subprocess.run(['install_name_tool', '-add_rpath', '@executable_path/../Frameworks', str(bundle / 'MacOS/CallsMac')], check=True)