Sunday, October 1, 2017

Compiling WebRTC on Ubuntu

In this topic I want to share an experience in details. Maybe it helps someone trying to compile WebRTC. If you do not know aht is WebRTC then this topic is definitely not interested for you.

Compiling WebRTC is a nightmare experience that you do not need to go through in order to use WebRTC in your application. But some rare times you have to and this where this topic becomes vital.


The following steps are for compiling WebRTC branch 50 on Ubuntu 16.04.


1- Preparing Environment:


     1.1 Goto page: https://cs.chromium.org/chromium/src/build/install-build-deps.sh and download script from it named install-build-deps.sh you cannot use wget, you need to open the page and copy the script into a file.
     1.2 Run this script that will install all prerequisites needed for compiling process.
    $ ./build/install-build-deps.sh  --no-chromeos-fonts 


2-   Install Depot Tools

     1.1 Download depot_tools
     
$ git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
     
     1.2 now add path of depot tools to $PATH by running the following command  
      
export PATH=`pwd`/depot_tools:"$PATH"



3- Download & Compile WebRTC


 1.1 Download Source Code 

this steps takes looooong time to download source code, without a good Internet connection you have no hope in completing this. I myself decided to get a VPS on net with extra 50GB HD for about $10 per month to be able to compile this code. 

$ mkdir webrtc-checkout

$ cd webrtc-checkout

$ gclient config https://chromium.googlesource.com/external/webrtc.git@branch-heads/50 --name=src

$ gclient sync --force --with_branch_heads 

$ gclient sync --force --with_branch_heads --nohooks 


1.2 Define Building Parameters


$ export GYP_DEFINES="target_arch=x64 host_arch=x64 build_with_chromium=0 use_openssl=0 use_gtk=0 use_x11=0 include_examples=0 include_tests=1 fastbuild=1 remove_webcore_debug_symbols=1 include_pulse_audio=0 include_internal_video_render=0 clang=1 "

given you are in ./webrtc-checkout

$ cd src

$ git checkout branch-heads/50

1.3 Generate Build Script 

$ gclient runhooks 

1.4 Compile Code

after running above commands you can find two folders ./webrtc-checkout/src/out/Release and  ./webrtc-checkout/src/out/Debug contain build scripts for building WebRTC based on the GYP_DEFINES that you chose above.

$ ninja -C ./out/Release 
or
$ninja -C ./out/Debug 

You will wait for a 2923 files to be compiled. On that small machine I used it took around 30 min to compile.


1.5 Generate Headers & Libraries


Now you finally have WebRTC compiled. Assuming you chose to compile Release the you will find  binaries in /src/out/Release

Now you need to archive all .o objects into libwebrtc_full.a  and you need to have .h headers in a directory.

to generate libwebrtc_full.a in a folder lib assuming you are still in ./webrtc-checkout/src



$ mkdir ../lib/

$ find  ./ -name "*.o" -and -not -name do_not_use -and -not -name protoc -and -not -name genperf -exec ar crs ../lib/libwebrtc_full.a {} +

$ mkdir ../include


$ find ./ -name *.h -exec cp --parents '{}' ../include ';'




Please Check GitHUB for more details on sources & samples covering this topic 



For higher branch numbers such as 58, 60 ...etc. you need to replace step "1.3 Generate Build Scripts" commands with:


$ gn clean out/Release 

$ rm -rf ./out

$ gn gen out/Release




Problems does not end here... but above steps should work straight forward .





1 comment:

  1. Now I can do compiling very easily using this github repository https://github.com/sourcey/webrtc-builds.git

    ReplyDelete