├── .gitignore ├── tools └── win │ └── 7z │ ├── 7z.dll │ ├── 7z.exe │ └── LICENSE ├── resource └── pkgconfig │ └── libwebrtc_full.pc.in ├── circle.yml ├── LICENSE ├── test ├── run_tests.sh └── simple_app.cc ├── README.md └── util.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.local 2 | out 3 | depot_tools 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /tools/win/7z/7z.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcey/webrtc-builds/HEAD/tools/win/7z/7z.dll -------------------------------------------------------------------------------- /tools/win/7z/7z.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcey/webrtc-builds/HEAD/tools/win/7z/7z.exe -------------------------------------------------------------------------------- /resource/pkgconfig/libwebrtc_full.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${WEBRTC_LOCAL} 2 | libdir=${prefix}/lib 3 | includedir=${prefix}/include 4 | 5 | Name: libwebrtc_full 6 | Description: The WebRTC library 7 | Version: 0.0.1 8 | Requires: libcrypto, nss 9 | Cflags: -DWEBRTC_POSIX -I${includedir} -std=gnu++11 10 | # Libs: ${libdir}/x64/$CONFIG/libboringssl.a ${libdir}/x64/$CONFIG/libprotobuf_full.a ${libdir}/x64/$CONFIG/libsystem_wrappers.a ${libdir}/x64/$CONFIG/libwebrtc.a -ldl -lX11 -lexpat 11 | Libs: ${libdir}/x64/$CONFIG/libwebrtc_full.a -ldl -lX11 -lexpat 12 | 13 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | pre: 3 | - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test 4 | - sudo apt-get update 5 | - sudo apt-get install -qq --no-install-recommends unzip pkg-config libssl-dev libnss3-dev libx11-dev libexpat1-dev libasound2 6 | - sudo apt-get install --yes gcc-5 g++-5 7 | - sudo apt-get install --yes binutils-2.26 8 | - sudo update-alternatives --install /usr/bin/ld ld /usr/lib/binutils-2.26/bin/ld 90 9 | # Use prebuilt WebRTC while CI builds are disabled 10 | - mkdir -p out/webrtc-22215-ab42706-linux-x64; curl -sSL https://github.com/sourcey/webrtc-precompiled-builds/raw/master/webrtc-22215-ab42706-linux-x64.tar.gz | sudo tar -xzC out/webrtc-22215-ab42706-linux-x64 11 | test: 12 | override: 13 | # Disable builds since it exceeds the 4GB memory limit 14 | # - ./build.sh -n Release 15 | # - cd out; tar -xvzf *.tar.gz; cd - 16 | - test/run_tests.sh $(ls -d -1 out/webrtc*/) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Vicken Simonian 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /tools/win/7z/LICENSE: -------------------------------------------------------------------------------- 1 | 7-Zip 2 | ~~~~~ 3 | License for use and distribution 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | 7-Zip Copyright (C) 1999-2012 Igor Pavlov. 7 | 8 | Licenses for files are: 9 | 10 | 1) 7z.dll: GNU LGPL + unRAR restriction 11 | 2) All other files: GNU LGPL 12 | 13 | The GNU LGPL + unRAR restriction means that you must follow both 14 | GNU LGPL rules and unRAR restriction rules. 15 | 16 | 17 | Note: 18 | You can use 7-Zip on any computer, including a computer in a commercial 19 | organization. You don't need to register or pay for 7-Zip. 20 | 21 | 22 | GNU LGPL information 23 | -------------------- 24 | 25 | This library is free software; you can redistribute it and/or 26 | modify it under the terms of the GNU Lesser General Public 27 | License as published by the Free Software Foundation; either 28 | version 2.1 of the License, or (at your option) any later version. 29 | 30 | This library is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 | Lesser General Public License for more details. 34 | 35 | You can receive a copy of the GNU Lesser General Public License from 36 | http://www.gnu.org/ 37 | 38 | 39 | unRAR restriction 40 | ----------------- 41 | 42 | The decompression engine for RAR archives was developed using source 43 | code of unRAR program. 44 | All copyrights to original unRAR code are owned by Alexander Roshal. 45 | 46 | The license for original unRAR code has the following restriction: 47 | 48 | The unRAR sources cannot be used to re-create the RAR compression algorithm, 49 | which is proprietary. Distribution of modified unRAR sources in separate form 50 | or as a part of other software is permitted, provided that it is clearly 51 | stated in the documentation and source comments that the code may 52 | not be used to develop a RAR (WinRAR) compatible archiver. 53 | 54 | 55 | -- 56 | Igor Pavlov 57 | 58 | -------------------------------------------------------------------------------- /test/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 8 | WEBRTCBUILDS_FOLDER="$1" 9 | WEBRTCBUILDS_FOLDER=$(cd $WEBRTCBUILDS_FOLDER && pwd -P) 10 | CONFIGS=${2:-Debug Release} 11 | 12 | # This is for handling breaking changes between WebRTC versions in our test 13 | WEBRTC_REVISION_NUMBER=$(echo $WEBRTCBUILDS_FOLDER | cut -d- -f2) 14 | echo $WEBRTCBUILDS_FOLDER 15 | echo echo $WEBRTCBUILDS_FOLDER | cut -d- -f2 16 | 17 | tmpdir=$(mktemp -d) 18 | trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP 19 | pushd $tmpdir >/dev/null 20 | for CONFIG in $CONFIGS; do 21 | if [[ $(uname) = Linux ]]; then 22 | export PKG_CONFIG_PATH=$WEBRTCBUILDS_FOLDER/lib/x64/$CONFIG/pkgconfig 23 | #../out/src/third_party/llvm-build/Release+Asserts/bin/clang++ -v -Wall -pthread -o simple_app $DIR/simple_app.cc \ 24 | #-DWEBRTC_REVISION_NUMBER=$WEBRTC_REVISION_NUMBER \ 25 | #$(pkg-config --cflags --libs --define-variable=WEBRTC_LOCAL=$WEBRTCBUILDS_FOLDER libwebrtc_full) \ 26 | #-lpthread 27 | c++ -o simple_app $DIR/simple_app.cc \ 28 | -DWEBRTC_REVISION_NUMBER=$WEBRTC_REVISION_NUMBER \ 29 | $(pkg-config --cflags --libs --define-variable=WEBRTC_LOCAL=$WEBRTCBUILDS_FOLDER libwebrtc_full) \ 30 | -lpthread 31 | elif [[ $(uname) = Darwin ]]; then 32 | clang++ -o simple_app $DIR/simple_app.cc -DWEBRTC_POSIX -DWEBRTC_MAC \ 33 | -DWEBRTC_REVISION_NUMBER=$WEBRTC_REVISION_NUMBER \ 34 | -I$WEBRTCBUILDS_FOLDER/include -std=c++11 -stdlib=libc++ \ 35 | $WEBRTCBUILDS_FOLDER/lib/$CONFIG/x64/libwebrtc_full.a \ 36 | -framework Cocoa -framework Foundation -framework IOKit \ 37 | -framework Security -framework SystemConfiguration \ 38 | -framework ApplicationServices -framework CoreServices \ 39 | -framework CoreVideo -framework CoreAudio -framework AudioToolbox \ 40 | -framework QTKit -framework AVFoundation -framework CoreMedia 41 | else 42 | echo No test currently exists for this platform 43 | exit 1 44 | fi 45 | ./simple_app 46 | done 47 | popd >/dev/null 48 | -------------------------------------------------------------------------------- /test/simple_app.cc: -------------------------------------------------------------------------------- 1 | // Revision 19846 is the following, where upstream moved src/webrtc to src/ 2 | // https://webrtc.googlesource.com/src/+/92ea95e34af5966555903026f45164afbd7e2088 3 | // #if WEBRTC_REVISION_NUMBER && WEBRTC_REVISION_NUMBER < 19846 4 | // #include "webrtc/rtc_base/thread.h" 5 | // #include "webrtc/p2p/base/basicpacketsocketfactory.h" 6 | // #include "webrtc/api/peerconnectioninterface.h" 7 | // #include "webrtc/api/test/fakeconstraints.h" 8 | // #include "webrtc/media/engine/webrtcvideocapturerfactory.h" 9 | // #include "webrtc/base/ssladapter.h" 10 | // #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 11 | // #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" 12 | // #else 13 | #include "rtc_base/thread.h" 14 | #include "p2p/base/basicpacketsocketfactory.h" 15 | #include "api/peerconnectioninterface.h" 16 | #include "api/test/fakeconstraints.h" 17 | #include "media/engine/webrtcvideocapturerfactory.h" 18 | #include "rtc_base/ssladapter.h" 19 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" 20 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" 21 | // #endif 22 | 23 | 24 | class VideoPacketSource : public cricket::VideoCapturer 25 | { 26 | public: 27 | VideoPacketSource() 28 | { 29 | std::vector formats; 30 | SetSupportedFormats(formats); 31 | } 32 | 33 | virtual cricket::CaptureState Start(const cricket::VideoFormat& capture_format) override { return cricket::CS_RUNNING; } 34 | virtual void Stop() override {}; 35 | virtual bool GetPreferredFourccs(std::vector* fourccs) override { return true; }; 36 | virtual bool IsRunning() override { return true; }; 37 | virtual bool IsScreencast() const override { return false; }; 38 | }; 39 | 40 | 41 | int main(int argc, char* argv[]) { 42 | 43 | // logging 44 | rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); // LS_VERBOSE, LS_INFO, LERROR 45 | 46 | rtc::InitializeSSL(); 47 | 48 | // something from base 49 | rtc::Thread* thread = rtc::Thread::Current(); 50 | 51 | // something from p2p 52 | std::unique_ptr socket_factory( 53 | new rtc::BasicPacketSocketFactory()); 54 | 55 | // something from api 56 | // rtc::scoped_refptr audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); 57 | // rtc::scoped_refptr audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); 58 | // rtc::scoped_refptr 59 | // peer_connection_factory = webrtc::CreatePeerConnectionFactory(audio_encoder_factory, audio_decoder_factory); 60 | 61 | // custom video source 62 | // VideoPacketSource video_source; 63 | 64 | // something from api/test 65 | webrtc::FakeConstraints constraints; 66 | 67 | // something from media/engine 68 | cricket::WebRtcVideoDeviceCapturerFactory factory; 69 | auto capturer = factory.Create(cricket::Device("", 0)); 70 | // cricket::VideoCapturer* capturer = factory.Create(cricket::Device("", 0)); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebRTC Automated Builds 2 | 3 | [![CircleCI](https://circleci.com/gh/sourcey/webrtc-builds.svg?style=svg)](https://circleci.com/gh/sourcey/webrtc-builds) 4 | 5 | These cross platform build scripts automate the hard work of building and packaging WebRTC. Big thanks to @vsimon for laying the foundation for these scripts. 6 | 7 | ## Supported platforms 8 | 9 | * **OSX**: [Homebrew](http://brew.sh/) recommend. Build for 'mac' and 'ios'. 10 | * **Windows**: Visual Studio Community 2015 Update 3 or newer 11 | with a bash shell such as [Git for Windows](https://msysgit.github.io) or [MSYS](http://www.mingw.org/wiki/msys) 12 | installed. 13 | * **Linux**: Debian or Ubuntu flavour with `apt-get` available. Build for 'linux' and 'android'. 14 | 15 | ## Usage 16 | 17 | To build the latest version of WebRTC just type: 18 | 19 | ``` 20 | # Build latest WebRTC for current platform: 21 | ./build.sh 22 | 23 | # To compile a specific branch with both x64 and x86 libraries you would run: 24 | ./build.sh -c x64 -b branch-heads/66 25 | ./build.sh -c x86 -b branch-heads/66 -x 26 | 27 | # To cross compile both x64 and x86 libraries for iOS you would run (on MacOS): 28 | ./build.sh -c x64 -t ios 29 | ./build.sh -c x86 -t ios -x 30 | ``` 31 | 32 | Or with options: 33 | 34 | ``` 35 | Usage: 36 | $0 [OPTIONS] 37 | 38 | WebRTC automated build script. 39 | 40 | OPTIONS: 41 | -o OUTDIR Output directory. Default is 'out' 42 | -b BRANCH Latest revision on git branch. Overrides -r. Common branch names are 'branch-heads/nn', where 'nn' is the release number. 43 | -r REVISION Git SHA revision. Default is latest revision. 44 | -t TARGET OS The target os for cross-compilation. Default is the host OS such as 'linux', 'mac', 'win'. Other values can be 'android', 'ios'. 45 | -c TARGET CPU The target cpu for cross-compilation. Default is 'x64'. Other values can be 'x86', 'arm64', 'arm'. 46 | -l BLACKLIST List *.o objects to exclude from the static library. 47 | -e Compile WebRTC with RTII enabled. 48 | -f Build only mode. Skip repo sync and dependency checks, just build, compile and package. 49 | -d Debug mode. Print all executed commands. 50 | -h Show this message 51 | EOF 52 | ``` 53 | 54 | The output packages will be saved to `{OUTDIR}/webrtcbuilds----.`, where `` is the revision number of the commit, `` is the short git SHA 55 | of the commit, and `-` is the OS (linux, mac, win) and CPU (x64, x86) of the target environment. 56 | 57 | On Windows `7-Zip` is used for compressing packages, which produces vastly superiour output file size. On mac and linux the output file is `tar.gz`. 58 | 59 | ## Running tests 60 | 61 | Once you have compiled the libraries you can run a quick compile test to ensure build integrity: 62 | 63 | ``` 64 | ./test/run_tests.sh out/webrtc-17657-02ba69d-linux-x64 65 | ``` 66 | 67 | ## Further reading 68 | 69 | The following links point to official WebRTC related documentation: 70 | 71 | * [https://webrtc.org/native-code/development/](https://webrtc.org/native-code/development/) 72 | * [https://webrtc.org/native-code/development/prerequisite-sw/](https://webrtc.org/native-code/development/prerequisite-sw/) 73 | * [http://dev.chromium.org/developers/how-tos/install-depot-tools](http://dev.chromium.org/developers/how-tos/install-depot-tools) 74 | * [https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md](https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md) 75 | * [https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/quick_start.md](https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/quick_start.md) 76 | -------------------------------------------------------------------------------- /util.sh: -------------------------------------------------------------------------------- 1 | # Detect the host platform. 2 | # Set PLATFORM environment variable to override default behavior. 3 | # Supported platform types - 'linux', 'win', 'mac' 4 | # 'msys' is the git bash shell, built using mingw-w64, running under Microsoft 5 | # Windows. 6 | function detect-platform() { 7 | # set PLATFORM to android on linux host to build android 8 | case "$OSTYPE" in 9 | darwin*) PLATFORM=${PLATFORM:-mac} ;; 10 | linux*) PLATFORM=${PLATFORM:-linux} ;; 11 | win32*|msys*) PLATFORM=${PLATFORM:-win} ;; 12 | *) echo "Building on unsupported OS: $OSTYPE"; exit 1; ;; 13 | esac 14 | } 15 | 16 | # Cleanup the output directory. 17 | # 18 | # $1: The output directory. 19 | function clean() { 20 | local outdir="$1" 21 | rm -rf $outdir/* $outdir/.gclient* 22 | } 23 | 24 | # Make sure depot tools are present. 25 | # 26 | # $1: The platform type. 27 | # $2: The depot tools url. 28 | # $3: The depot tools directory. 29 | function check::depot-tools() { 30 | local platform="$1" 31 | local depot_tools_url="$2" 32 | local depot_tools_dir="$3" 33 | 34 | if [ ! -d $depot_tools_dir ]; then 35 | git clone -q $depot_tools_url $depot_tools_dir 36 | if [ $platform = 'win' ]; then 37 | # run gclient.bat to get python 38 | pushd $depot_tools_dir >/dev/null 39 | ./gclient.bat 40 | popd >/dev/null 41 | fi 42 | else 43 | pushd $depot_tools_dir >/dev/null 44 | git reset --hard -q 45 | popd >/dev/null 46 | fi 47 | } 48 | 49 | # Make sure a package is installed. Depends on sudo to be installed first. 50 | # 51 | # $1: The name of the package 52 | # $2: Existence check binary. Defaults to name of the package. 53 | function ensure-package() { 54 | local name="$1" 55 | local binary="${2:-$1}" 56 | if ! which $binary > /dev/null ; then 57 | sudo apt-get update -qq 58 | sudo apt-get install -y $name 59 | fi 60 | } 61 | 62 | # Check if any of the arguments is executable (logical OR condition). 63 | # Using plain "type" without any option because has-binary is intended 64 | # to know if there is a program that one can call regardless if it is 65 | # an alias, builtin, function, or a disk file that would be executed. 66 | function has-binary () { 67 | type "$1" &> /dev/null ; 68 | } 69 | 70 | # Setup Visual Studio build environment variables. 71 | function init-msenv() { 72 | 73 | # Rudimentary support for VS2017 in default install location due to 74 | # lack of VS1S0COMNTOOLS environment variable. 75 | if [ -d "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" ]; then 76 | vcvars_path="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" 77 | elif [ ! -z "$VS140COMNTOOLS" ]; then 78 | vcvars_path="${VS140COMNTOOLS}../../VC" 79 | else 80 | echo "Building under Microsoft Windows requires Microsoft Visual Studio 2015 Update 3" 81 | exit 1 82 | fi 83 | 84 | export DEPOT_TOOLS_WIN_TOOLCHAIN=0 85 | pushd "$vcvars_path" >/dev/null 86 | OLDIFS=$IFS 87 | IFS=$'\n' 88 | msvars=$(cmd //c "vcvarsall.bat $TARGET_CPU && set") 89 | 90 | for line in $msvars; do 91 | case $line in 92 | INCLUDE=*|LIB=*|LIBPATH=*) 93 | export $line ;; 94 | PATH=*) 95 | PATH=$(echo $line | sed \ 96 | -e 's/PATH=//' \ 97 | -e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \ 98 | -e 's/\\/\//g' \ 99 | -e 's/;\//:\//g'):$PATH 100 | export PATH 101 | ;; 102 | esac 103 | done 104 | IFS=$OLDIFS 105 | popd >/dev/null 106 | } 107 | 108 | # Make sure all build dependencies are present and platform specific 109 | # environment variables are set. 110 | # 111 | # $1: The platform type. 112 | function check::build::env() { 113 | local platform="$1" 114 | local target_cpu="$2" 115 | 116 | case $platform in 117 | mac) 118 | # for GNU version of cp: gcp 119 | which gcp || brew install coreutils 120 | ;; 121 | linux) 122 | if ! grep -v \# /etc/apt/sources.list | grep -q multiverse ; then 123 | echo "*** Warning: The Multiverse repository is probably not enabled ***" 124 | echo "*** which is required for things like msttcorefonts. ***" 125 | fi 126 | if ! which sudo > /dev/null ; then 127 | apt-get update -qq 128 | apt-get install -y sudo 129 | fi 130 | ensure-package curl 131 | ensure-package git 132 | ensure-package python 133 | ensure-package lbzip2 134 | ensure-package lsb-release lsb_release 135 | ;; 136 | win) 137 | init-msenv 138 | 139 | # Required programs that may be missing on Windows 140 | # TODO: check before running platform specific commands 141 | REQUIRED_PROGS=( 142 | bash 143 | sed 144 | git 145 | openssl 146 | find 147 | grep 148 | xargs 149 | pwd 150 | curl 151 | rm 152 | cat 153 | # strings 154 | ) 155 | 156 | # Check that required programs exist on the system. 157 | # If they are missing, we abort. 158 | for f in "${REQUIRED_PROGS[@]}" ; do 159 | if ! has-binary "$f" ; then 160 | echo "Error: '$f' is not installed." >&2 161 | exit 1 162 | fi 163 | done 164 | ;; 165 | esac 166 | } 167 | 168 | # Make sure all WebRTC build dependencies are present. 169 | # $1: The platform type. 170 | function check::webrtc::deps() { 171 | local platform="$1" 172 | local outdir="$2" 173 | local target_os="$3" 174 | 175 | case $platform in 176 | linux) 177 | # Automatically accepts ttf-mscorefonts EULA 178 | echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections 179 | sudo $outdir/src/build/install-build-deps.sh --no-syms --no-arm --no-chromeos-fonts --no-nacl --no-prompt 180 | ;; 181 | esac 182 | 183 | if [ $target_os = 'android' ]; then 184 | sudo $outdir/src/build/install-build-deps-android.sh 185 | fi 186 | } 187 | 188 | # Check out a specific revision. 189 | # 190 | # $1: The target OS type. 191 | # $2: The output directory. 192 | # $3: Revision represented as a git SHA. 193 | function checkout() { 194 | local target_os="$1" 195 | local outdir="$2" 196 | local revision="$3" 197 | 198 | pushd $outdir >/dev/null 199 | local prev_target_os=$(cat $outdir/.webrtcbuilds_target_os 2>/dev/null) 200 | if [[ -n "$prev_target_os" && "$target_os" != "$prev_target_os" ]]; then 201 | echo The target OS has changed. Refetching sources for the new target OS 202 | rm -rf src .gclient* 203 | fi 204 | 205 | # Fetch only the first-time, otherwise sync. 206 | if [ ! -d src ]; then 207 | case $target_os in 208 | android) 209 | yes | fetch --nohooks webrtc_android 210 | ;; 211 | ios) 212 | fetch --nohooks webrtc_ios 213 | ;; 214 | *) 215 | fetch --nohooks webrtc 216 | ;; 217 | esac 218 | fi 219 | 220 | # Remove all unstaged files that can break gclient sync 221 | # NOTE: need to redownload resources 222 | pushd src >/dev/null 223 | # git reset --hard 224 | git clean -f 225 | popd >/dev/null 226 | 227 | # Checkout the specific revision after fetch 228 | gclient sync --force --revision $revision 229 | 230 | # Cache the target OS 231 | echo $target_os > $outdir/.webrtcbuilds_target_os 232 | popd >/dev/null 233 | } 234 | 235 | # Patch a checkout for before building libraries. 236 | # 237 | # $1: The platform type. 238 | # $2: The output directory. 239 | function patch() { 240 | local platform="$1" 241 | local outdir="$2" 242 | 243 | pushd $outdir/src >/dev/null 244 | # This removes the examples from being built. 245 | sed -i.bak 's|"//webrtc/examples",|#"//webrtc/examples",|' BUILD.gn 246 | 247 | # This patches a GN error with the video_loopback executable depending on a 248 | # test but since we disable building tests GN detects a dependency error. 249 | # Replacing the outer conditional with 'rtc_include_tests' works around this. 250 | # sed -i.bak 's|if (!build_with_chromium)|if (rtc_include_tests)|' webrtc/BUILD.gn 251 | 252 | # Enable RTTI if required by removing the 'no_rtti' compiler flag. 253 | # This fixes issues when compiling WebRTC with other libraries that have RTTI enabled. 254 | # if [ $ENABLE_RTTI = 1 ]; then 255 | # echo "Enabling RTTI" 256 | # sed -i.bak 's|"//build/config/compiler:no_rtti",|#"//build/config/compiler:no_rtti",|' \ 257 | # build/config/BUILDCONFIG.gn 258 | # fi 259 | popd >/dev/null 260 | } 261 | 262 | # Compile using ninja. 263 | # 264 | # $1 The output directory, 'out/$TARGET_CPU/Debug', or 'out/$TARGET_CPU/Release' 265 | # $2 Additional gn arguments 266 | function compile::ninja() { 267 | local outputdir="$1" 268 | local gn_args="$2" 269 | 270 | echo "Generating project files with: $gn_args" 271 | gn gen $outputdir --args="$gn_args" 272 | pushd $outputdir >/dev/null 273 | # ninja -v -C . 274 | ninja -C . 275 | popd >/dev/null 276 | } 277 | 278 | # Combine build artifact objects into one library. 279 | # 280 | # The Microsoft Windows tools use different file extensions than the other tools: 281 | # '.obj' as the object file extension, instead of '.o' 282 | # '.lib' as the static library file extension, instead of '.a' 283 | # '.dll' as the shared library file extension, instead of '.so' 284 | # 285 | # The Microsoft Windows tools have different names than the other tools: 286 | # 'lib' as the librarian, instead of 'ar'. 'lib' must be found through the path 287 | # variable $VS140COMNTOOLS. 288 | # 289 | # $1: The platform 290 | # $2: The list of object file paths to be combined 291 | # $3: The output library name 292 | function combine::objects() { 293 | local platform="$1" 294 | local outputdir="$2" 295 | local libname="libwebrtc_full" 296 | 297 | # if [ $platform = 'win' ]; then 298 | # local extname='obj' 299 | # else 300 | # local extname='o' 301 | # fi 302 | 303 | pushd $outputdir >/dev/null 304 | rm -f $libname.* 305 | 306 | # Prevent blacklisted objects such as ones containing a main function from 307 | # being combined. 308 | # Blacklist objects from video_capture_external and device_info_external so 309 | # that the internal video capture module implementations get linked. 310 | # unittest_main because it has a main function defined. 311 | local blacklist="unittest|examples|tools|yasm/|protobuf_lite|main.o|video_capture_external.o|device_info_external.o" 312 | 313 | # Method 1: Collect all .o files from .ninja_deps and some missing intrinsics 314 | local objlist=$(strings .ninja_deps | grep -o ".*\.o") 315 | local extras=$(find \ 316 | obj/third_party/libvpx/libvpx_* \ 317 | obj/third_party/libjpeg_turbo/simd_asm \ 318 | obj/third_party/boringssl/boringssl_asm -name "*\.o") 319 | echo "$objlist" | tr ' ' '\n' | grep -v -E $blacklist >$libname.list 320 | echo "$extras" | tr ' ' '\n' | grep -v -E $blacklist >>$libname.list 321 | 322 | # Method 2: Collect all .o files from output directory 323 | # local objlist=$(find . -name '*.o' | grep -v -E $blacklist) 324 | # echo "$objlist" >$libname.list 325 | 326 | # Combine all objects into one static library 327 | case $platform in 328 | win) 329 | # TODO: Support VS 2017 330 | "$VS140COMNTOOLS../../VC/bin/lib" /OUT:$libname.lib @$libname.list 331 | ;; 332 | *) 333 | # Combine *.o objects using ar 334 | cat $libname.list | xargs ar -crs $libname.a 335 | 336 | # Combine *.o objects into a thin library using ar 337 | # cat $libname.list | xargs ar -ccT $libname.a 338 | 339 | ranlib $libname.a 340 | ;; 341 | esac 342 | popd >/dev/null 343 | } 344 | 345 | # Combine built static libraries into one library. 346 | # 347 | # NOTE: This method is currently preferred since combining .o objects is 348 | # causing undefined references to libvpx intrinsics on both Linux and Windows. 349 | # 350 | # The Microsoft Windows tools use different file extensions than the other tools: 351 | # '.obj' as the object file extension, instead of '.o' 352 | # '.lib' as the static library file extension, instead of '.a' 353 | # '.dll' as the shared library file extension, instead of '.so' 354 | # 355 | # The Microsoft Windows tools have different names than the other tools: 356 | # 'lib' as the librarian, instead of 'ar'. 'lib' must be found through the path 357 | # variable $VS140COMNTOOLS. 358 | # 359 | # $1: The platform 360 | # $2: The list of object file paths to be combined 361 | # $3: The output library name 362 | function combine::static() { 363 | local platform="$1" 364 | local outputdir="$2" 365 | local libname="$3" 366 | 367 | echo $libname 368 | pushd $outputdir >/dev/null 369 | rm -f $libname.* 370 | 371 | # Find only the libraries we need 372 | if [ $platform = 'win' ]; then 373 | local whitelist="boringssl.dll.lib|protobuf_lite.dll.lib|webrtc\.lib|field_trial_default.lib|metrics_default.lib" 374 | else 375 | local whitelist="boringssl\.a|protobuf_full\.a|webrtc\.a|field_trial_default\.a|metrics_default\.a" 376 | fi 377 | cat .ninja_log | tr '\t' '\n' | grep -E $whitelist | sort -u >$libname.list 378 | 379 | # Combine all objects into one static library 380 | case $platform in 381 | win) 382 | # TODO: Support VS 2017 383 | "$VS140COMNTOOLS../../VC/bin/lib" /OUT:$libname.lib @$libname.list 384 | ;; 385 | *) 386 | # Combine *.a static libraries 387 | echo "CREATE $libname.a" >$libname.ar 388 | while read a; do 389 | echo "ADDLIB $a" >>$libname.ar 390 | done <$libname.list 391 | echo "SAVE" >>$libname.ar 392 | echo "END" >>$libname.ar 393 | ar -M < $libname.ar 394 | ranlib $libname.a 395 | ;; 396 | esac 397 | popd >/dev/null 398 | } 399 | 400 | # Compile the libraries. 401 | # 402 | # $1: The platform type. 403 | # $2: The output directory. 404 | function compile() { 405 | local platform="$1" 406 | local outdir="$2" 407 | local target_os="$3" 408 | local target_cpu="$4" 409 | local configs="$5" 410 | local blacklist="$5" 411 | 412 | # Set default default common and target args. 413 | # `rtc_include_tests=false`: Disable all unit tests 414 | # `treat_warnings_as_errors=false`: Don't error out on compiler warnings 415 | local common_args="rtc_include_tests=false treat_warnings_as_errors=false" 416 | local target_args="target_os=\"$target_os\" target_cpu=\"$target_cpu\"" 417 | 418 | # Build WebRTC with RTII enbled. 419 | [ $ENABLE_RTTI = 1 ] && common_args+=" use_rtti=true" 420 | 421 | # Static vs Dynamic CRT: When `is_component_build` is false static CTR will be 422 | # enforced.By default Debug builds are dynamic and Release builds are static. 423 | [ $ENABLE_STATIC_LIBS = 1 ] && common_args+=" is_component_build=false" 424 | 425 | # `enable_iterator_debugging=false`: Disable libstdc++ debugging facilities 426 | # unless all your compiled applications and dependencies define _GLIBCXX_DEBUG=1. 427 | # This will cause errors like: undefined reference to `non-virtual thunk to 428 | # cricket::VideoCapturer::AddOrUpdateSink(rtc::VideoSinkInterface*, 429 | # rtc::VideoSinkWants const&)' 430 | [ $ENABLE_ITERATOR_DEBUGGING = 0 ] && common_args+=" enable_iterator_debugging=false" 431 | 432 | # Use clang or gcc to compile WebRTC. 433 | # The default compiler used by Chromium/WebRTC is clang, so there are frequent 434 | # bugs and incompatabilities with gcc, especially with newer versions >= 4.8. 435 | # Use gcc at your own risk, but it may be necessary if your compiler doesn't 436 | # like the clang compiled libraries, so the option is there. 437 | # Set `is_clang=false` and `use_sysroot=false` to build using gcc. 438 | if [ $ENABLE_CLANG = 0 ]; then 439 | common_args+=" is_clang=false" 440 | [ $platform = 'linux' ] && common_args+=" use_sysroot=false linux_use_bundled_binutils=false use_custom_libcxx=false use_custom_libcxx_for_host=false" 441 | fi 442 | 443 | pushd $outdir/src >/dev/null 444 | for cfg in $configs; do 445 | [ "$cfg" = 'Release' ] && common_args+=' is_debug=false strip_debug_info=true symbol_level=0' 446 | compile::ninja "out/$target_cpu/$cfg" "$common_args $target_args" 447 | 448 | if [ $COMBINE_LIBRARIES = 1 ]; then 449 | # Method 1: Merge the static .a/.lib libraries. 450 | combine::static $platform "out/$target_cpu/$cfg" libwebrtc_full 451 | 452 | # Method 2: Merge .o/.obj objects to create the library, although results 453 | # have been inconsistent so the static merging method is default. 454 | # combine::objects $platform "out/$target_cpu/$cfg" libwebrtc_full 455 | fi 456 | done 457 | popd >/dev/null 458 | } 459 | 460 | # Package a compiled build into an archive file in the output directory. 461 | # 462 | # $1: The platform type. 463 | # $2: The output directory. 464 | # $3: The package filename. 465 | # $4: The project's resource dirctory. 466 | # $5: The build configurations. 467 | # $6: The revision number. 468 | function package::prepare() { 469 | local platform="$1" 470 | local outdir="$2" 471 | local package_filename="$3" 472 | local resource_dir="$4" 473 | local configs="$5" 474 | local revision_number="$6" 475 | 476 | if [ $platform = 'mac' ]; then 477 | CP='gcp' 478 | else 479 | CP='cp' 480 | fi 481 | 482 | pushd $outdir >/dev/null 483 | 484 | # Create directory structure 485 | mkdir -p $package_filename/include packages 486 | pushd src >/dev/null 487 | 488 | # Find and copy header files 489 | local header_source_dir=webrtc 490 | 491 | # Revision 19846 moved src/webrtc to src/ 492 | # https://webrtc.googlesource.com/src/+/92ea95e34af5966555903026f45164afbd7e2088 493 | [ $revision_number -ge 19846 ] && header_source_dir=. 494 | 495 | # Copy header files, skip third_party dir 496 | find $header_source_dir -path './third_party' -prune -o -type f \( -name '*.h' \) -print | \ 497 | xargs -I '{}' $CP --parents '{}' $outdir/$package_filename/include 498 | 499 | # Find and copy dependencies 500 | # The following build dependencies were excluded: 501 | # gflags, ffmpeg, openh264, openmax_dl, winsdk_samples, yasm 502 | find $header_source_dir -name '*.h' -o -name README -o -name LICENSE -o -name COPYING | \ 503 | grep './third_party' | \ 504 | grep -E 'boringssl|expat/files|jsoncpp/source/json|libjpeg|libjpeg_turbo|libsrtp|libyuv|libvpx|opus|protobuf|usrsctp/usrsctpout/usrsctpout' | \ 505 | xargs -I '{}' $CP --parents '{}' $outdir/$package_filename/include 506 | 507 | popd >/dev/null 508 | 509 | # Find and copy libraries 510 | for cfg in $configs; do 511 | mkdir -p $package_filename/lib/$TARGET_CPU/$cfg 512 | pushd src/out/$TARGET_CPU/$cfg >/dev/null 513 | mkdir -p $outdir/$package_filename/lib/$TARGET_CPU/$cfg 514 | if [ $COMBINE_LIBRARIES = 1 ]; then 515 | find . -name '*.so' -o -name '*.dll' -o -name '*.lib' -o -name '*.a' -o -name '*.jar' | \ 516 | grep -E 'webrtc_full' | \ 517 | xargs -I '{}' $CP '{}' $outdir/$package_filename/lib/$TARGET_CPU/$cfg 518 | else 519 | find . -name '*.so' -o -name '*.dll' -o -name '*.lib' -o -name '*.a' -o -name '*.jar' | \ 520 | grep -E 'webrtc\.|boringssl|protobuf|system_wrappers' | \ 521 | xargs -I '{}' $CP '{}' $outdir/$package_filename/lib/$TARGET_CPU/$cfg 522 | fi 523 | popd >/dev/null 524 | done 525 | 526 | # Create pkgconfig files on linux 527 | if [ $platform = 'linux' ]; then 528 | for cfg in $configs; do 529 | mkdir -p $package_filename/lib/$TARGET_CPU/$cfg/pkgconfig 530 | CONFIG=$cfg envsubst '$CONFIG' < $resource_dir/pkgconfig/libwebrtc_full.pc.in > \ 531 | $package_filename/lib/$TARGET_CPU/$cfg/pkgconfig/libwebrtc_full.pc 532 | done 533 | fi 534 | 535 | popd >/dev/null 536 | } 537 | 538 | # This packages a compiled build into a archive file in the output directory. 539 | # $1: The platform type. 540 | # $2: The output directory. 541 | # $3: The package filename. 542 | function package::archive() { 543 | local platform="$1" 544 | local outdir="$2" 545 | local package_filename="$3" 546 | 547 | if [ $platform = 'win' ]; then 548 | OUTFILE=$package_filename.7z 549 | else 550 | OUTFILE=$package_filename.tar.gz #.tar.bz2 551 | fi 552 | 553 | pushd $outdir >/dev/null 554 | 555 | # Archive the package 556 | rm -f $OUTFILE 557 | pushd $package_filename >/dev/null 558 | if [ $platform = 'win' ]; then 559 | $TOOLS_DIR/win/7z/7z.exe a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -ir!lib/$TARGET_CPU -ir!include -r ../packages/$OUTFILE 560 | else 561 | tar -czvf ../packages/$OUTFILE lib/$TARGET_CPU include 562 | # tar cvf - lib/$TARGET_CPU include | gzip --best > ../packages/$OUTFILE 563 | # zip -r $package_filename.zip $package_filename >/dev/null 564 | fi 565 | popd >/dev/null 566 | 567 | popd >/dev/null 568 | } 569 | 570 | # This packages into a debian package in the output directory. 571 | # $1: The output directory. 572 | # $2: The package filename. 573 | # $3: The package name. 574 | # $4: The package version. 575 | # $5: The architecture. 576 | function package::debian() { 577 | local outdir="$1" 578 | local package_filename="$2" 579 | local package_name="$3" 580 | local package_version="$4" 581 | local arch="$5" 582 | local debianize="debianize/$package_filename" 583 | 584 | echo "Debianize WebRTC" 585 | pushd $outdir >/dev/null 586 | mkdir -p $debianize/DEBIAN 587 | mkdir -p $debianize/opt 588 | mv $package_filename $debianize/opt/webrtc 589 | cat << EOF > $debianize/DEBIAN/control 590 | Package: $package_name 591 | Architecture: $arch 592 | Maintainer: Sourcey 593 | Depends: debconf (>= 0.5.00) 594 | Priority: optional 595 | Version: $package_version 596 | Description: webrtc static library 597 | This package provides webrtc library generated with webrtcbuilds 598 | EOF 599 | fakeroot dpkg-deb --build $debianize 600 | mv debianize/*.deb . 601 | rm -rf debianize 602 | popd >/dev/null 603 | } 604 | 605 | # Build and merge the output manifest. 606 | # 607 | # $1: The platform type. 608 | # $2: The output directory. 609 | # $3: The package filename. 610 | function package::manifest() { 611 | local platform="$1" 612 | local outdir="$2" 613 | local package_filename="$3" 614 | 615 | if [ $platform = 'win' ]; then 616 | OUTFILE=$package_filename.7z 617 | else 618 | OUTFILE=$package_filename.tar.gz 619 | fi 620 | 621 | mkdir -p $outdir/packages 622 | pushd $outdir/packages >/dev/null 623 | # Create a JSON manifest 624 | rm -f $package_filename.json 625 | cat << EOF > $package_filename.json 626 | { 627 | "file": "$OUTFILE", 628 | "date": "$(current-rev-date)", 629 | "branch": "${BRANCH}", 630 | "revision": "${REVISION_NUMBER}", 631 | "sha": "${REVISION}", 632 | "crc": "$(file-crc $OUTFILE)", 633 | "target_os": "${TARGET_OS}", 634 | "target_cpu": "${TARGET_CPU}" 635 | } 636 | EOF 637 | 638 | # # Merge JSON manifests 639 | # # node manifest.js 640 | # rm -f manifest.json 641 | # echo '[' > manifest.json 642 | # files=(*.json) 643 | # ( 644 | # set -- "${files[@]}" 645 | # until (( $# == 1 )); do 646 | # if [ ! $1 = 'manifest.json' ]; then 647 | # cat $1 >> manifest.json 648 | # echo ',' >> manifest.json 649 | # fi 650 | # shift 651 | # done 652 | # cat $1 >> manifest.json 653 | # ) 654 | # sed -i ':a;N;$!ba;s/\n//g' manifest.json 655 | # sed -i 's/{/\n {/g' manifest.json 656 | # echo ']' >> manifest.json 657 | 658 | popd >/dev/null 659 | } 660 | 661 | # This interprets a pattern and returns the interpreted one. 662 | # $1: The pattern. 663 | # $2: The output directory. 664 | # $3: The platform type. 665 | # $4: The target os for cross-compilation. 666 | # $5: The target cpu for cross-compilation. 667 | # $6: The branch. 668 | # $7: The revision. 669 | # $8: The revision number. 670 | function interpret-pattern() { 671 | local pattern="$1" 672 | local platform="$2" 673 | local outdir="$3" 674 | local target_os="$4" 675 | local target_cpu="$5" 676 | local branch="$6" 677 | local revision="$7" 678 | local revision_number="$8" 679 | local debian_arch="$(debian-arch $target_cpu)" 680 | local short_revision="$(short-rev $revision)" 681 | 682 | pattern=${pattern//%p%/$platform} 683 | pattern=${pattern//%to%/$target_os} 684 | pattern=${pattern//%tc%/$target_cpu} 685 | pattern=${pattern//%b%/$branch} 686 | pattern=${pattern//%r%/$revision} 687 | pattern=${pattern//%rn%/$revision_number} 688 | pattern=${pattern//%da%/$debian_arch} 689 | pattern=${pattern//%sr%/$short_revision} 690 | 691 | echo "$pattern" 692 | } 693 | 694 | # Return the latest revision date from the current git repo. 695 | function current-rev-date() { 696 | git log -1 --format=%cd 697 | } 698 | 699 | # Return the latest revision from the git repo. 700 | # 701 | # $1: The git repo URL 702 | function file-crc() { 703 | local file_path="$1" 704 | md5sum $file_path | grep -o '^\S*' 705 | } 706 | 707 | # Return the latest revision from the git repo. 708 | # 709 | # $1: The git repo URL 710 | function latest-rev() { 711 | local repo_url="$1" 712 | git ls-remote $repo_url HEAD | cut -f1 713 | } 714 | 715 | # Return the associated revision number for a given git sha revision. 716 | # 717 | # $1: The git repo URL 718 | # $2: The revision git sha string 719 | function revision-number() { 720 | local repo_url="$1" 721 | local revision="$2" 722 | # This says curl the revision log with text format, base64 decode it using 723 | # openssl since its more portable than just 'base64', take the last line which 724 | # contains the commit revision number and output only the matching {#nnn} part 725 | openssl base64 -d -A <<< $(curl --silent $repo_url/+/$revision?format=TEXT) \ 726 | | tail -1 | egrep -o '{#([0-9]+)}' | tr -d '{}#' 727 | } 728 | 729 | # Return a short revision sha. 730 | # 731 | # $1: The revision string 732 | function short-rev() { 733 | local revision="$1" 734 | echo $revision | cut -c -7 735 | } 736 | 737 | # This returns a short revision sha. 738 | # $1: The target cpu for cross-compilation. 739 | function debian-arch() { 740 | local target_cpu="$1" 741 | # set PLATFORM to android on linux host to build android 742 | case "$target_cpu" in 743 | x86*) echo "i386" ;; 744 | x64*) echo "amd64" ;; 745 | *) echo "$target_cpu" ;; 746 | esac 747 | } 748 | --------------------------------------------------------------------------------