Skip to content

Commit 47bd647

Browse files
committed
Full Apple script
1 parent c135d29 commit 47bd647

File tree

6 files changed

+312
-6
lines changed

6 files changed

+312
-6
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ jobs:
6262
fail-fast: false
6363
matrix:
6464
name:
65-
- macos_arm64
66-
- macos_x86_64
67-
- ios
65+
- apple
66+
- apple_prefixed
6867
runs-on: macos-15
6968
steps:
7069
- uses: actions/checkout@v4
@@ -76,8 +75,8 @@ jobs:
7675
- name: Upload Artifact
7776
uses: actions/upload-artifact@v4
7877
with:
79-
name: webrtc.${{ matrix.name }}.tar.gz
80-
path: build/_package/${{ matrix.name }}/webrtc.tar.gz
78+
name: ${{ matrix.name == 'apple_prefixed' && 'LiveKitWebRTC.xcframework.zip' || 'WebRTC.xcframework.zip' }}
79+
path: build/_package/${{ matrix.name }}/*.xcframework.zip
8180
build-linux:
8281
defaults:
8382
run:
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/bin/sh
2+
if [ ! -n "$1" ]; then
3+
echo "Usage: $0 'debug' | 'release' 'source_dir' 'out_dir' ['prefix']"
4+
exit 0
5+
fi
6+
7+
MODE=$1
8+
SOURCE_DIR=$2
9+
OUT_DIR=$3
10+
PREFIX=${4:-""}
11+
12+
if [ -z "$PREFIX" ]; then
13+
FRAMEWORK_NAME="WebRTC"
14+
else
15+
FRAMEWORK_NAME="${PREFIX}WebRTC"
16+
fi
17+
18+
DEBUG="false"
19+
if [ "$MODE" == "debug" ]; then
20+
DEBUG="true"
21+
fi
22+
23+
echo "build_xcframework_dynamic_livekit.sh: MODE=$MODE, DEBUG=$DEBUG, SOURCE_DIR=$SOURCE_DIR, OUT_DIR=$OUT_DIR, PREFIX=$PREFIX, FRAMEWORK_NAME=$FRAMEWORK_NAME"
24+
25+
start_group() {
26+
if [ "$CI" = "true" ]; then
27+
echo "::group::$1"
28+
else
29+
echo "=== $1 ==="
30+
fi
31+
}
32+
33+
end_group() {
34+
if [ "$CI" = "true" ]; then
35+
echo "::endgroup::"
36+
fi
37+
}
38+
39+
COMMON_ARGS="
40+
treat_warnings_as_errors = false
41+
ios_enable_code_signing = false
42+
is_component_build = false
43+
rtc_enable_symbol_export = true
44+
rtc_libvpx_build_vp9 = true
45+
rtc_include_tests = false
46+
rtc_build_examples = false
47+
rtc_use_h264 = false
48+
rtc_enable_protobuf = false
49+
enable_libaom = true
50+
rtc_include_dav1d_in_internal_decoder_factory = true
51+
use_rtti = true
52+
is_debug = $DEBUG
53+
enable_dsyms = $DEBUG
54+
enable_stripping = true"
55+
56+
PLATFORMS=(
57+
"tvOS-arm64-device:target_os=\"ios\" target_environment=\"appletv\" target_cpu=\"arm64\" ios_deployment_target=\"17.0\""
58+
"tvOS-arm64-simulator:target_os=\"ios\" target_environment=\"appletvsimulator\" target_cpu=\"arm64\" ios_deployment_target=\"17.0\""
59+
"xrOS-arm64-device:target_os=\"ios\" target_environment=\"xrdevice\" target_cpu=\"arm64\" ios_deployment_target=\"2.2.0\""
60+
"xrOS-arm64-simulator:target_os=\"ios\" target_environment=\"xrsimulator\" target_cpu=\"arm64\" ios_deployment_target=\"2.2.0\""
61+
"catalyst-arm64:target_os=\"ios\" target_environment=\"catalyst\" target_cpu=\"arm64\" ios_deployment_target=\"14.0\""
62+
"catalyst-x64:target_os=\"ios\" target_environment=\"catalyst\" target_cpu=\"x64\" ios_deployment_target=\"14.0\""
63+
"iOS-arm64-device:target_os=\"ios\" target_environment=\"device\" target_cpu=\"arm64\" ios_deployment_target=\"13.0\""
64+
"iOS-x64-simulator:target_os=\"ios\" target_environment=\"simulator\" target_cpu=\"x64\" ios_deployment_target=\"13.0\""
65+
"iOS-arm64-simulator:target_os=\"ios\" target_environment=\"simulator\" target_cpu=\"x64\" ios_deployment_target=\"13.0\""
66+
"macOS-x64:target_os=\"mac\" target_cpu=\"x64\" mac_deployment_target=\"10.15\""
67+
"macOS-arm64:target_os=\"mac\" target_cpu=\"arm64\" mac_deployment_target=\"10.15\""
68+
)
69+
70+
cd $SOURCE_DIR
71+
72+
for platform_config in "${PLATFORMS[@]}"; do
73+
platform="${platform_config%%:*}"
74+
config="${platform_config#*:}"
75+
76+
start_group "Building $platform"
77+
78+
echo "Generating configuration for $platform..."
79+
gn gen $OUT_DIR/$platform --args="$COMMON_ARGS $config" --ide=xcode
80+
81+
if [[ $platform == *"macOS"* ]]; then
82+
build_target="mac_framework_bundle"
83+
else
84+
build_target="ios_framework_bundle"
85+
fi
86+
87+
echo "Building $platform..."
88+
ninja -C $OUT_DIR/$platform $build_target -j 10 --quiet
89+
if [ $? -ne 0 ]; then
90+
echo "Build $platform failed"
91+
end_group
92+
exit 1
93+
fi
94+
echo "Build $platform completed"
95+
96+
end_group
97+
done
98+
99+
start_group "Creating Universal Binaries"
100+
101+
rm -rf $OUT_DIR/*-lib $OUT_DIR/$FRAMEWORK_NAME.*
102+
103+
echo "Creating macOS universal binary..."
104+
mkdir -p $OUT_DIR/macOS-lib
105+
cp -R $OUT_DIR/macOS-x64/$FRAMEWORK_NAME.framework $OUT_DIR/macOS-lib/$FRAMEWORK_NAME.framework
106+
lipo -create -output $OUT_DIR/macOS-lib/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/macOS-arm64/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/macOS-x64/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME
107+
108+
echo "Creating Catalyst universal binary..."
109+
mkdir -p $OUT_DIR/catalyst-lib
110+
cp -R $OUT_DIR/catalyst-arm64/$FRAMEWORK_NAME.framework $OUT_DIR/catalyst-lib/$FRAMEWORK_NAME.framework
111+
lipo -create -output $OUT_DIR/catalyst-lib/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/catalyst-arm64/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/catalyst-x64/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME
112+
113+
echo "Creating iOS device binary..."
114+
mkdir -p $OUT_DIR/iOS-device-lib
115+
cp -R $OUT_DIR/iOS-arm64-device/$FRAMEWORK_NAME.framework $OUT_DIR/iOS-device-lib/$FRAMEWORK_NAME.framework
116+
lipo -create -output $OUT_DIR/iOS-device-lib/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/iOS-arm64-device/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME
117+
118+
echo "Creating iOS simulator universal binary..."
119+
mkdir -p $OUT_DIR/iOS-simulator-lib
120+
cp -R $OUT_DIR/iOS-arm64-simulator/$FRAMEWORK_NAME.framework $OUT_DIR/iOS-simulator-lib/$FRAMEWORK_NAME.framework
121+
lipo -create -output $OUT_DIR/iOS-simulator-lib/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/iOS-arm64-simulator/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME $OUT_DIR/iOS-x64-simulator/$FRAMEWORK_NAME.framework/$FRAMEWORK_NAME
122+
123+
end_group
124+
125+
start_group "Creating XCFramework"
126+
127+
echo "Creating $FRAMEWORK_NAME.xcframework..."
128+
xcodebuild -create-xcframework \
129+
-framework $OUT_DIR/iOS-device-lib/$FRAMEWORK_NAME.framework \
130+
-framework $OUT_DIR/iOS-simulator-lib/$FRAMEWORK_NAME.framework \
131+
-framework $OUT_DIR/xrOS-arm64-device/$FRAMEWORK_NAME.framework \
132+
-framework $OUT_DIR/xrOS-arm64-simulator/$FRAMEWORK_NAME.framework \
133+
-framework $OUT_DIR/tvOS-arm64-device/$FRAMEWORK_NAME.framework \
134+
-framework $OUT_DIR/tvOS-arm64-simulator/$FRAMEWORK_NAME.framework \
135+
-framework $OUT_DIR/catalyst-lib/$FRAMEWORK_NAME.framework \
136+
-framework $OUT_DIR/macOS-lib/$FRAMEWORK_NAME.framework \
137+
-output $OUT_DIR/$FRAMEWORK_NAME.xcframework
138+
139+
cp ./src/LICENSE $OUT_DIR/$FRAMEWORK_NAME.xcframework/
140+
141+
end_group
142+
143+
start_group "Post-processing XCFramework"
144+
145+
echo "Setting up macOS framework symlinks..."
146+
cd $OUT_DIR/$FRAMEWORK_NAME.xcframework/macos-arm64_x86_64/$FRAMEWORK_NAME.framework/
147+
mv $FRAMEWORK_NAME Versions/A/$FRAMEWORK_NAME
148+
ln -s Versions/Current/$FRAMEWORK_NAME $FRAMEWORK_NAME
149+
cd ../../../../
150+
151+
echo "Setting up Catalyst framework symlinks..."
152+
cd $OUT_DIR/$FRAMEWORK_NAME.xcframework/ios-arm64_x86_64-maccatalyst/$FRAMEWORK_NAME.framework/
153+
mv $FRAMEWORK_NAME Versions/A/$FRAMEWORK_NAME
154+
ln -s Versions/Current/$FRAMEWORK_NAME $FRAMEWORK_NAME
155+
cd ../../../
156+
157+
echo "Creating archive..."
158+
zip --symlinks -9 -r $FRAMEWORK_NAME.xcframework.zip $FRAMEWORK_NAME.xcframework
159+
160+
echo "Generating checksum..."
161+
shasum -a 256 $FRAMEWORK_NAME.xcframework.zip >$FRAMEWORK_NAME.xcframework.zip.shasum
162+
cat $FRAMEWORK_NAME.xcframework.zip.shasum
163+
164+
end_group

build/build.apple.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
cd `dirname $0`
5+
python3 run.py build apple --commit "$1" --webrtc-fetch
6+
# Temporary solution for a complete XCFramework build
7+
export PATH="$PWD/_source/apple/depot_tools:$PATH"
8+
. apple/build_xcframework_dynamic_livekit.sh release _source/apple/webrtc/src _package/apple

build/build.apple_prefixed.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
cd `dirname $0`
5+
python3 run.py build apple_prefixed --commit "$1" --webrtc-fetch
6+
# Temporary solution for a complete XCFramework build
7+
export PATH="$PWD/_source/apple/depot_tools:$PATH"
8+
. apple/build_xcframework_dynamic_livekit.sh release _source/apple_prefixed/webrtc/src _package/apple_prefixed LiveKit # prefix

build/patches/apple_prefix.patch

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
diff --git forkSrcPrefix/sdk/objc/Info.plist forkDstPrefix/sdk/objc/Info.plist
2+
index 38c437e7feda9bfa1ee8aafb864174af1c891913..814989d53484f2b009f08ccfd2c6d0ad60e6f5ce 100644
3+
--- forkSrcPrefix/sdk/objc/Info.plist
4+
+++ forkDstPrefix/sdk/objc/Info.plist
5+
@@ -5,13 +5,13 @@
6+
<key>CFBundleDevelopmentRegion</key>
7+
<string>en</string>
8+
<key>CFBundleExecutable</key>
9+
- <string>WebRTC</string>
10+
+ <string>LiveKitWebRTC</string>
11+
<key>CFBundleIdentifier</key>
12+
- <string>org.webrtc.WebRTC</string>
13+
+ <string>io.livekit.LiveKitWebRTC</string>
14+
<key>CFBundleInfoDictionaryVersion</key>
15+
<string>6.0</string>
16+
<key>CFBundleName</key>
17+
- <string>WebRTC</string>
18+
+ <string>LiveKitWebRTC</string>
19+
<key>CFBundlePackageType</key>
20+
<string>FMWK</string>
21+
<key>CFBundleShortVersionString</key>
22+
diff --git forkSrcPrefix/tools_webrtc/apple/copy_framework_header.py forkDstPrefix/tools_webrtc/apple/copy_framework_header.py
23+
index 3574a67d2a243d4f95217b0a9e855f08b437c739..a68f22d887cbf798c4546ef4937fab75fd03e8ba 100755
24+
--- forkSrcPrefix/tools_webrtc/apple/copy_framework_header.py
25+
+++ forkDstPrefix/tools_webrtc/apple/copy_framework_header.py
26+
@@ -20,7 +20,7 @@ def _ReplaceDoubleQuote(line):
27+
if not match:
28+
return line
29+
30+
- return '%s#import <WebRTC/%sRTC%s.h>%s' % (match.group(1), match.group(3),
31+
+ return '%s#import <LiveKitWebRTC/%sRTC%s.h>%s' % (match.group(1), match.group(3),
32+
match.group(4), match.group(5))
33+
34+
35+
diff --git forkSrcPrefix/sdk/BUILD.gn forkDstPrefix/sdk/BUILD.gn
36+
index a710d600d671a97b355467269907c1cde4c50e0c..3af067c7929640b5afc443eefd95152315d90286 100644
37+
--- forkSrcPrefix/sdk/BUILD.gn
38+
+++ forkDstPrefix/sdk/BUILD.gn
39+
@@ -1409,7 +1409,7 @@ if (is_ios || is_mac) {
40+
if (is_ios) {
41+
apple_framework_bundle_with_umbrella_header("framework_objc") {
42+
info_plist = "objc/Info.plist"
43+
- output_name = "WebRTC"
44+
+ output_name = "LiveKitWebRTC"
45+
46+
common_objc_headers = [
47+
"objc/base/RTCCodecSpecificInfo.h",
48+
@@ -1579,7 +1579,7 @@ if (is_ios || is_mac) {
49+
50+
bundle_data("ios_framework_bundle") {
51+
deps = [ "../sdk:framework_objc" ]
52+
- sources = [ "$root_build_dir/WebRTC.framework" ]
53+
+ sources = [ "$root_build_dir/LiveKitWebRTC.framework" ]
54+
outputs = [ "{{bundle_resources_dir}}/Frameworks/{{source_file_part}}" ]
55+
}
56+
}
57+
@@ -1587,7 +1587,7 @@ if (is_ios || is_mac) {
58+
if (is_mac) {
59+
apple_framework_bundle_with_umbrella_header("mac_framework_objc") {
60+
info_plist = "objc/Info.plist"
61+
- output_name = "WebRTC"
62+
+ output_name = "LiveKitWebRTC"
63+
64+
sources = [
65+
"objc/api/peerconnection/RTCAudioDeviceModule.h",
66+
@@ -1735,7 +1735,7 @@ if (is_ios || is_mac) {
67+
68+
bundle_data("mac_framework_bundle") {
69+
deps = [ "../sdk:mac_framework_objc" ]
70+
- sources = [ "$root_build_dir/WebRTC.framework" ]
71+
+ sources = [ "$root_build_dir/LiveKitWebRTC.framework" ]
72+
outputs = [ "{{bundle_contents_dir}}/Frameworks/{{source_file_part}}" ]
73+
}
74+
}
75+
diff --git forkSrcPrefix/tools_webrtc/ios/generate_umbrella_header.py forkDstPrefix/tools_webrtc/ios/generate_umbrella_header.py
76+
index 1fd1eed38eedd64b11302c962d24c0cb0f60dc99..055732e044d61af98bec7c71949c18f84c54ea79 100644
77+
--- forkSrcPrefix/tools_webrtc/ios/generate_umbrella_header.py
78+
+++ forkDstPrefix/tools_webrtc/ios/generate_umbrella_header.py
79+
@@ -41,7 +41,7 @@ def GenerateUmbrellaHeader():
80+
*/\n\n""" % datetime.datetime.now().year))
81+
82+
for s in args.sources:
83+
- outfile.write("#import <WebRTC/{}>\n".format(os.path.basename(s)))
84+
+ outfile.write("#import <LiveKitWebRTC/{}>\n".format(os.path.basename(s)))
85+
86+
return 0
87+
88+
diff --git forkSrcPrefix/sdk/objc/base/RTCMacros.h forkDstPrefix/sdk/objc/base/RTCMacros.h
89+
index 09418b86ac77a1a1dc8672775ce05bca0061377d..16399cb0133f79ec0103b38693451cbceb0d52bc 100644
90+
--- forkSrcPrefix/sdk/objc/base/RTCMacros.h
91+
+++ forkDstPrefix/sdk/objc/base/RTCMacros.h
92+
@@ -40,9 +40,7 @@
93+
// problem.
94+
//
95+
// This macro must be defined uniformily across all the translation units.
96+
-#ifndef RTC_OBJC_TYPE_PREFIX
97+
-#define RTC_OBJC_TYPE_PREFIX
98+
-#endif
99+
+#define RTC_OBJC_TYPE_PREFIX LK
100+
101+
#ifndef RTC_CONSTANT_TYPE_PREFIX
102+
#define RTC_CONSTANT_TYPE_PREFIX k
103+
diff --git forkSrcPrefix/tools_webrtc/ios/build_ios_libs.py forkDstPrefix/tools_webrtc/ios/build_ios_libs.py
104+
index 50c9398e1739dd765f02e097e7d04544a70221bd..53dc1b12d775b348a40acbf35242a719ec731dc4 100755
105+
--- forkSrcPrefix/tools_webrtc/ios/build_ios_libs.py
106+
+++ forkDstPrefix/tools_webrtc/ios/build_ios_libs.py
107+
@@ -27,9 +27,9 @@ sys.path.append(os.path.join(SRC_DIR, 'build'))
108+
import find_depot_tools
109+
110+
SDK_OUTPUT_DIR = os.path.join(SRC_DIR, 'out_ios_libs')
111+
-SDK_FRAMEWORK_NAME = 'WebRTC.framework'
112+
-SDK_DSYM_NAME = 'WebRTC.dSYM'
113+
-SDK_XCFRAMEWORK_NAME = 'WebRTC.xcframework'
114+
+SDK_FRAMEWORK_NAME = 'LiveKitWebRTC.framework'
115+
+SDK_DSYM_NAME = 'LiveKitWebRTC.dSYM'
116+
+SDK_XCFRAMEWORK_NAME = 'LiveKitWebRTC.xcframework'
117+
118+
ENABLED_ARCHS = [
119+
'device:arm64', 'simulator:arm64', 'simulator:x64',

build/run.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def get_depot_tools(source_dir, fetch=False):
177177
}
178178

179179
PATCHES = {
180+
'apple': [],
181+
'apple_prefixed': [
182+
'apple_prefix.patch',
183+
],
180184
'windows_x86_64': [
181185
'add_license_dav1d.patch',
182186
'windows_add_deps.patch',
@@ -940,6 +944,8 @@ def package_webrtc(source_dir, build_dir, package_dir, target,
940944
'android',
941945
'android_prefixed',
942946
'ios',
947+
'apple',
948+
'apple_prefixed'
943949
]
944950

945951

@@ -951,7 +957,7 @@ def check_target(target):
951957
return target in ['windows_x86_64', 'windows_arm64']
952958
elif platform.system() == 'Darwin':
953959
logging.info(f'OS: {platform.system()}')
954-
return target in ('macos_x86_64', 'macos_arm64', 'ios')
960+
return target in ('macos_x86_64', 'macos_arm64', 'ios', 'apple', 'apple_prefixed')
955961
elif platform.system() == 'Linux':
956962
release = read_version_file('/etc/os-release')
957963
os = release['NAME']
@@ -1161,6 +1167,8 @@ def main():
11611167
overlap_build_dir=args.webrtc_overlap_ios_build_dir)
11621168
elif args.target in ['android', 'android_prefixed']:
11631169
build_webrtc_android(**build_webrtc_args, nobuild_aar=args.webrtc_nobuild_android_aar)
1170+
elif args.target in ['apple', 'apple_prefixed']:
1171+
pass
11641172
else:
11651173
build_webrtc(**build_webrtc_args, target=args.target)
11661174

0 commit comments

Comments
 (0)