9

How can I compile WebRTC iOS framework with Bitcode enabled. Currently I have to disable the Bitcode of my project due to WebRTC framework.

clemens
  • 16,716
  • 11
  • 50
  • 65
abhimanyu jindal
  • 658
  • 8
  • 18

2 Answers2

13

You will need to build it yourself.
Something like:

# Clone the depot tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# Add the tools to the path
export PATH=$PATH:"`pwd`/depot_tools"
# Download the WebRTC source code
mkdir webrtc_ios
cd webrtc_ios
# This will take some time
fetch --nohooks webrtc_ios
gclient sync
# Let's start building
cd src
# Build the framework, remove --arch "arm64 x64" to build ALL architectures, including 32 bit
tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 x64
# The framework is at out_ios_libs/WebRTC.framework

Documentation: https://webrtc.github.io/webrtc-org/native-code/ios/

Update:
Starting with Xcode 14, bitcode is no longer required (see release notes), and no longer supported in submissions.
The google WebRTC neglected to fix an ARM build issue with bitcode for so long, they just waited it out... the --bitcode option is no longer supported by the build script.
To continue building using my instructions, remove it:
tools_webrtc/ios/build_ios_libs.py --arch arm64 x64

Moshe Gottlieb
  • 3,963
  • 25
  • 41
  • it fails on fetch --nohooks webrtc_ios – Nasir Khan Jul 18 '19 at 11:29
  • 1
    @NasirKhan Fetch works fine, however, it seems that the last command had changed a bit. I updated it to match the new behavior. – Moshe Gottlieb Jul 18 '19 at 14:04
  • it says: Could not find gn executable at: .../webrtc_ios/src/buildtools/mac/gn – Nasir Khan Jul 19 '19 at 09:32
  • @NasirKhan All I can tell you is to make sure you copy pasted everything correctly, did the whole process yesterday (latest Xcode, latest macOS, latest command line build tools) and it worked just fine. – Moshe Gottlieb Jul 19 '19 at 11:19
  • i have created a folder, in that folder i run these all commands, just let me know is this how it would work? – Nasir Khan Jul 19 '19 at 11:32
  • 1
    Thanks! This works great, although the build for all architectures is huge (over 1GB). What would be the best way to include it in production? (btw. after stripping the bitcode it's 22MB) – bojan Jun 07 '20 at 02:09
  • @bojan In production, the actual binary downloaded to devices does not include bitcode, the user only downloads sliced and stripped code, so that shouldn't be a problem. Takes a bit longer to upload to the iTunes Store though :-( – Moshe Gottlieb Jun 11 '20 at 07:03
  • @MosheGottlieb Thanks! I already read about it:) Plus I actually found a build script to remove unused architectures from the library. The issue now is, what would be the best way to keep it in the project between team members, as the building takes forever. – bojan Jun 12 '20 at 01:57
  • @bojan Building takes forever, it's true, I'd keep `--arch arm64 x64` to make sure it only builds for these architectures (and then you don't need to strip it), as for sharing this file - I have a bootstrap script that either copies it from a file server or, builds it, based on it's parameters. Even copying it from a fileserver takes a bit :-) – Moshe Gottlieb Jun 12 '20 at 07:49
  • @MosheGottlieb "I have a bootstrap script that either copies it from a file server or, builds it, based on it's parameters" good idea! Thanks again! Just one more question do you find the library reliable in production? :) – bojan Jun 12 '20 at 17:12
  • @bojan So far, it works fine for me, so yes, I find it reliable. The thing is, I still don't know how to checkout a specific version, and my script pulls the latest, so it's hard to stick to a known and trusted version, unless you save a working copy on your server, like I do. – Moshe Gottlieb Jun 15 '20 at 14:23
  • @MosheGottlieb thank you a lot, a build follow your instruction but get error in the last step, can you help me to resolve this: "../../stats/rtc_stats.cc:30:17: error: loop variable 'element' is always a copy because the range of type 'const std::vector' does not return a reference [-Werror,-Wrange-loop-analysis]" – goat_herd Sep 28 '20 at 07:12
  • 1
    @goat_herd Unfortunately, this is an issue with the latest clang that comes with Xcode and that specific file, we'll need to wait for google to fix this, or append `use_xcode_clang=false` to the build script, but that will mean we'll use google's specific clang version which does not support bitcode, so there's not much sense doing that. – Moshe Gottlieb Sep 28 '20 at 14:36
  • 4
    Anyone facing this `clang++: error: -mllvm is not supported with -fembed-bitcode` while running `tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 x64`? – tanmoy Jan 09 '22 at 05:05
  • @MuhtasimUlfatTanmoy Yes. Im facing the same issue too – Sampath D Jan 18 '22 at 21:42
  • @SampathD These links might help - [link](https://stackoverflow.com/questions/70648366/bitcode-enable-for-ios-webrtc-framework-error-mllvm-is-not-supported-with-fe), [link](https://bugs.chromium.org/p/webrtc/issues/detail?id=13440#c4). – tanmoy Jan 20 '22 at 18:12
6

according to the official doc, you have to compile manually. More details there:

bottom of the page (last paragraph) includes instructions to build with bitcode support:

To build the framework with bitcode support, pass the --bitcode flag to the script like so

python build_ios_libs.py --bitcode

Dr. Alex Gouaillard
  • 2,078
  • 14
  • 13