WebRTC bazel build system integration
![]() |
3 years ago | |
---|---|---|
builder | 3 years ago | |
.gitignore | 3 years ago | |
BUILD | 3 years ago | |
README.md | 3 years ago | |
WORKSPACE | 3 years ago | |
android.BUILD | 3 years ago | |
android.WORKSPACE | 3 years ago | |
build.sh | 3 years ago | |
ios.BUILD | 3 years ago | |
ios.WORKSPACE | 3 years ago | |
linux.BUILD | 3 years ago | |
linux.WORKSPACE | 3 years ago | |
server.sh | 3 years ago |
The WebRTC library relies upon a relatively non-standard set of build tools from the chromium codebase (depot_tools, GN, ninja, etc). To avoid introducing dependencies on these tools in your build, this project pre-builds a copy of WebRTC and exposes corresponding bazel targets. This makes it trivial to use WebRTC in your bazel Linux (C++), iOS (Swift / Objective-C) and Android (Java) projects.
Add the following to your WORKSPACE
file:
http_archive(
name = "taxi_code_socialworkout_webrtc_linux",
sha256 = "a21516985f438a23ee57d85fd87cdf8d99e4e6cfa29b6ff6a18685310d7a01f2",
url = "https://code.taxi/download/webrtc-58-5-linux.tar.gz",
)
Then add deps
to the WebRTC package from the appropriate cc_library()
or
cc_binary()
targets in your BUILD
files:
cc_library(
...
copts = ["-fno-rtti"],
deps = [ "@taxi_code_socialworkout_webrtc_linux//:rtc" ],
...
)
# or
cc_binary(
...
copts = ["-fno-rtti"],
deps = [ "@taxi_code_socialworkout_webrtc_linux//:rtc" ],
...
)
Upstream WebRTC allows clients to
gather and aggregate statistics
as well as perform
field trials
by turning on feature code in binaries out in the field. This project links the
default implementation (system_wrappers:metrics_default and
system_wrappers:field_trial_default) for metrics and field trails. However,
you can also provide your own implementation by not linking the two *.o
files.
Additionally, WebRTC is compiled without runtime type information. Therefore,
it is required that your client code be compiled with -fno-rtti
to avoid
linking errors
(error: undefined reference to 'typeinfo for rtc::MessageHandler'
).
Note, this target can only be compiled from linux (not darwin). Depending on
the platforms you build on, it may be desirable to omit relevant cc_library()
and cc_binary
targets from your bazel build
command on darwin. If you want
to build all targets omitting a single sub-tree run a command similar to
bazel build -- ... -//foo/bar/...
.
Download the Android SDK
command line tools.
Then point bazel to the location of your android SDK using the ANDROID_HOME
environment variable or the
path
attribute of the
android_sdk_repository
rule in your WORKSPACE
file.
Next, add the following to your WORKSPACE
file:
http_archive(
name = "taxi_code_socialworkout_webrtc_android",
sha256 = "20444fc5bb6d653f04e504d60701a786ff40d436e23a8210949d62e3482189e6",
url = "https://code.taxi/download/webrtc-58-5-android.tar.gz",
)
android_sdk_repository(
name = "androidsdk",
api_level = 24,
build_tools_version = "24.0.3",
# set $ANDROID_HOME environment variable or specify `path`
# path = __workspace_dir__ + "/android_sdk_folder",
)
Finally, add deps
to the WebRTC package from the appropriate
android_library()
or android_binary()
targets in your BUILD
files:
android_library(
...
deps = [ "@taxi_code_socialworkout_webrtc_android//:rtc" ],
...
)
# or
android_binary(
...
deps = [ "@taxi_code_socialworkout_webrtc_android//:rtc" ],
...
)
To test your application on a physical device run
bazel mobile-install [android_target]
with a connected device that has
USB debugging enabled.
The default *_unsigned.apk
file generated by android_binary()
include
debug symbols, are not zipaligned and are unsigned. To prepare a
release build
for upload to the Google Play Store run:
$ bazel -c opt [android_target] # compile "optimized" without debug symbols
$ [build_tools_dir]/zipalign -v -p 4 ./bazel-bin/[android_target]_unsigned.apk \
/tmp/android_aligned.apk
$ [build_tools_dir]/apksigner sign --ks [keystore.jks] \
--out /tmp/android_release.apk /tmp/android_aligned.apk
Building a android_binary()
on macOS currently requires
--strategy=AndroidAapt=standalone
due to
#2597.
Install XCode and the "iOS 8.4 Simulator" (XCode > Preferences > Components).
Then, add the following to your WORKSPACE
file:
http_archive(
name = "taxi_code_socialworkout_webrtc_ios",
sha256 = "40bd5af5af047da0d8cb4c08cfdbda76f0191e32b208cfcbd7f1d47fc15a632d",
url = "https://code.taxi/download/webrtc-58-19-ios.tar.gz",
)
Next, add deps
to the WebRTC package from the appropriate swift_library()
or objc_library()
targets in your BUILD
files:
swift_library(
...
deps = [ "@taxi_code_socialworkout_webrtc_ios//:rtc" ],
...
)
# or
objc_library(
...
deps = [ "@taxi_code_socialworkout_webrtc_ios//:rtc" ],
...
)
When importing framework headers use the WebRTC
framework prefix. For example:
#import <WebRTC/RTCLogging.h>
Embedded frameworks are only supported on iOS 8.0+. Therefore set the minimum iOS version during build:
bazel build --ios_minimum_os=8.0
Also, when using Tulsi to build in Xcode and run using the ensure your build is configured for iOS 8.0+ only.
When building for a device (vs the simulator) specify the CPU architecture:
bazel build --ios_minimum_os=8.0 --ios_multi_cpus=armv7,arm64