diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1a8e965 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,164 @@ + +# use the packages for Go +.ubuntu-template: &ubuntu-template + variables: + DEBIAN_FRONTEND: noninteractive + GOPATH: /usr/share/gocode + before_script: + - apt-get -qy update + - apt-get -qy install --no-install-recommends + build-essential + git + golang-github-smartystreets-goconvey-dev + golang-race-detector-runtime + libx11-dev + locales + pkg-config + - mkdir -p $GOPATH + +# use Go installed as part of the official, Debian-based Docker images +.golang-docker-debian-template: &golang-docker-debian-template + variables: + DEBIAN_FRONTEND: noninteractive + before_script: + - apt-get -qy update + - apt-get -qy install --no-install-recommends + ca-certificates + git + lbzip2 + libx11-dev + locales + pkg-config + wget + xz-utils + - go get github.com/smartystreets/goconvey/convey + +.build_env_setup: &build_env_setup | + set -x + cat /etc/apt/sources.list | sed 's,^deb,deb-src,' >> /etc/apt/sources.list + apt-get -qy update + apt-get -qy install --no-install-recommends git locales + apt-get -qy build-dep chromium-browser + # libwebrtc build wants en_US.UTF-8 + grep '^en_US.UTF-8 UTF-8' /etc/locale.gen || echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen + locale-gen + # Create symbolic links under $GOPATH, this is needed for local build + export src=$GOPATH/src + mkdir -p $src/github.com/keroserene + mkdir -p $src/gitlab.com/$CI_PROJECT_NAMESPACE + ln -s $CI_PROJECT_DIR $src/github.com/keroserene/go-webrtc + ln -s $CI_PROJECT_DIR $src/gitlab.com/$CI_PROJECT_PATH + # build libwebrtc binaries + git config --global user.name "John Doe" + git config --global user.email "jdoe@email.com" + git config --global core.autocrlf false + git config --global core.filemode false + rm -rf include/ lib/ + set +x + +.artifacts-template: &artifacts-template + artifacts: + name: "${CI_PROJECT_PATH}_${CI_JOB_STAGE}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}" + paths: + - include/ + - lib/ + when: + always + expire_in: 1 day + after_script: + - echo "Download debug artifacts from https://gitlab.com/${CI_PROJECT_PATH}/-/jobs" + +.script-template: &script-template + except: + - schedules + script: + # Create symbolic links under $GOPATH, this is needed for local build + - export src=$GOPATH/src + - mkdir -p $src/github.com/keroserene + - mkdir -p $src/gitlab.com/$CI_PROJECT_NAMESPACE + - ln -s $CI_PROJECT_DIR $src/github.com/keroserene/go-webrtc + - ln -s $CI_PROJECT_DIR $src/gitlab.com/$CI_PROJECT_PATH + + # build it for go + - cd $src/github.com/keroserene/go-webrtc + - go get -v . + - go build -v -x . + - go vet -v . + - go test -v -race . + + +# -- jobs ------------------------------------------------------------ + +debian-stretch_go-1.10: + image: golang:1.10-stretch + <<: *golang-docker-debian-template + <<: *artifacts-template + <<: *script-template + +debian-stretch_go-1.11: + image: golang:1.11-stretch + <<: *golang-docker-debian-template + <<: *artifacts-template + <<: *script-template + +ubuntu-devel: + image: ubuntu:devel + <<: *ubuntu-template + <<: *artifacts-template + <<: *script-template + +ubuntu-rolling: + image: ubuntu:rolling + <<: *ubuntu-template + <<: *artifacts-template + <<: *script-template + +ubuntu-lts: + image: ubuntu:latest + <<: *ubuntu-template + <<: *artifacts-template + <<: *script-template + +libwebrtc-linux-amd64-magic: + only: + - schedules + image: debian:stretch + # this job needs 20+ gigs of disk + tags: + - largedisk + <<: *artifacts-template + script: + - *build_env_setup + - GOOS=linux GOARCH=amd64 ./build.sh + +libwebrtc-linux-arm-magic: + only: + - schedules + image: debian:stretch + # this job needs 20+ gigs of disk + tags: + - largedisk + <<: *artifacts-template + script: + - *build_env_setup + - apt-get -qy install --no-install-recommends binutils-arm-linux-gnueabihf + - GOOS=linux GOARCH=arm ./build.sh + +android: + image: golang:1.11-stretch + # this job needs 20+ gigs of disk + tags: + - largedisk + only: + - schedules + <<: *golang-docker-debian-template + <<: *artifacts-template + script: + - *build_env_setup + - apt-get -qy install --no-install-recommends lsb-release sudo + - export WEBRTC_SRC="$CI_PROJECT_DIR/third_party/webrtc/src" + - export ANDROID_HOME=$WEBRTC_SRC/third_party/android_tools/sdk + - GOOS=android GOARCH=arm ./build.sh || ( $WEBRTC_SRC/build/install-build-deps-android.sh && GOOS=android GOARCH=arm ./build.sh ) + after_script: + - cat third_party/webrtc/.gclient || true + - cat third_party/webrtc/.gclient_entries || true diff --git a/build.sh b/build.sh index f12936c..14efd10 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,10 @@ # For a cross compile: # GOOS=linux GOARCH=amd64 ./build.sh # GOOS=linux GOARCH=arm ./build.sh -# (For a cross-compile from linux-amd64 to linux-arm, you may need to install the binutils-arm-linux-gnueabihf package.) +# GOOS=android GOARCH=arm ./build.sh # For macOS (GOOS=darwin GOARCH=amd64), you can currently only do a native compile. +# For a cross-compile to linux-arm, you need to install the binutils-arm-linux-gnueabihf package. +# For a cross-compile to android-arm, first run third_party/webrtc/src/build/install-build-deps-android.sh to install needed dependencies. PROJECT_DIR=$(pwd) THIRD_PARTY_DIR="$PROJECT_DIR/third_party" @@ -21,7 +23,11 @@ COMMIT="88f5d9180eae78a6162cccd78850ff416eb82483" # branch-heads/64 # Values are from, # https://github.com/golang/go/blob/master/src/go/build/syslist.go -# https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/reference.md +# https://gn.googlesource.com/gn/+/master/docs/reference.md +# +# Android steps from: +# https://www.chromium.org/developers/gn-build-configuration +# https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md oses=",linux:linux,darwin:mac,windows:win,android:android," cpus=",386:x86,amd64:x64,arm:arm," @@ -53,8 +59,22 @@ else git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS_DIR || exit 1 fi -if [[ -d $WEBRTC_DIR ]]; then - echo "Syncing webrtc ..." +if [[ ! -d $WEBRTC_DIR ]]; then + echo "Getting webrtc ..." + mkdir -p $WEBRTC_DIR + pushd $WEBRTC_DIR + gclient config --name src $WEBRTC_REPO || exit 1 + popd +fi + +if [[ $TARGET_OS == 'android' ]]; then + echo "Setting gclient target_os to android" + # Whacky sed to append 'android' to the target_os list, without clobbering what may be there already. + sed -i "/^target_os *= *.*\\/{p;h;d}; /^target_os *= */{s/ *]/, 'android'&/;p;h;d}; \${x;s/^target_os/&/;tx;atarget_os = [ 'android' ]"$'\n'";:x x}" $WEBRTC_DIR/.gclient +fi + +echo "Syncing webrtc ..." +if [[ -d $WEBRTC_SRC ]]; then pushd $WEBRTC_SRC || exit 1 if ! git diff-index --quiet HEAD --; then echo -en "\nOpen files present in $WEBRTC_SRC\nReset them? (y/N): " @@ -66,18 +86,18 @@ if [[ -d $WEBRTC_DIR ]]; then git reset --hard HEAD || exit 1 fi popd - - pushd $WEBRTC_DIR - gclient sync --with_branch_heads -r $COMMIT || exit 1 - popd -else - echo "Getting webrtc ..." - mkdir -p $WEBRTC_DIR - pushd $WEBRTC_DIR - gclient config --name src $WEBRTC_REPO || exit 1 - gclient sync --with_branch_heads -r $COMMIT || exit 1 - popd fi +pushd $WEBRTC_DIR +# "echo n" is to say "no" to the Google Play services license agreement and download. +echo n | gclient sync --with_branch_heads -r $COMMIT || exit 1 +# Delete where the Google Play services downloads to, just to be sure. +# First check that an ancestor directory of what we're deleting exists, so we're more likely to notice a source reorganization. +if [[ $TARGET_OS == 'android' && ! -d "$WEBRTC_SRC/third_party/android_tools/sdk/extras/google/m2repository" ]]; then + echo "Didn't find Google Play services directory for removal, please check" 1>&2 + exit 1 +fi +rm -rf "$WEBRTC_SRC/third_party/android_tools/sdk/extras/google/m2repository/com/google/android/gms" +popd if [ "$ARCH" = "arm" ]; then echo "Manually fetching arm sysroot" @@ -98,7 +118,7 @@ popd echo "Building webrtc ..." pushd $WEBRTC_SRC -gn gen out/$CONFIG --args="target_os=\"$TARGET_OS\" target_cpu=\"$TARGET_CPU\" is_debug=false use_custom_libcxx=false" || exit 1 +gn gen out/$CONFIG --args="target_os=\"$TARGET_OS\" target_cpu=\"$TARGET_CPU\" is_debug=false symbol_level=0 use_custom_libcxx=false" || exit 1 ninja -C out/$CONFIG webrtc field_trial metrics_default pc_test_utils || exit 1 popd @@ -121,12 +141,15 @@ if [ "$OS" = "darwin" ]; then find obj -name '*.o' -print0 \ | xargs -0 -- libtool -static -o libwebrtc-magic.a strip -S -x -o libwebrtc-magic.a libwebrtc-magic.a +elif [ "$OS" = "android" ]; then + find obj -name '*.o' -print0 | sort -z \ + | xargs -0 -- $WEBRTC_SRC/third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar crsD libwebrtc-magic.a elif [ "$ARCH" = "arm" ]; then find obj -name '*.o' -print0 | sort -z \ - | xargs -0 -- arm-linux-gnueabihf-ar crs libwebrtc-magic.a + | xargs -0 -- arm-linux-gnueabihf-ar crsD libwebrtc-magic.a else find obj -name '*.o' -print0 | sort -z \ - | xargs -0 -- ar crs libwebrtc-magic.a + | xargs -0 -- ar crsD libwebrtc-magic.a fi OUT_LIBRARY=$LIB_DIR/libwebrtc-$OS-$ARCH-magic.a mv libwebrtc-magic.a ${OUT_LIBRARY} diff --git a/datachannel.go b/datachannel.go index 7ac64f4..651f6d0 100644 --- a/datachannel.go +++ b/datachannel.go @@ -9,6 +9,7 @@ package webrtc /* #cgo CXXFLAGS: -std=c++0x #cgo LDFLAGS: -L${SRCDIR}/lib +#cgo android pkg-config: webrtc-android-armeabi-v7a.pc #cgo linux,arm pkg-config: webrtc-linux-arm.pc #cgo linux,386 pkg-config: webrtc-linux-386.pc #cgo linux,amd64 pkg-config: webrtc-linux-amd64.pc diff --git a/lib/libwebrtc-android-arm-magic.a b/lib/libwebrtc-android-arm-magic.a new file mode 100644 index 0000000..09c2038 Binary files /dev/null and b/lib/libwebrtc-android-arm-magic.a differ diff --git a/peerconnection.go b/peerconnection.go index 11d9d54..e1f1726 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -32,6 +32,7 @@ package webrtc /* #cgo CXXFLAGS: -std=c++0x #cgo LDFLAGS: -L${SRCDIR}/lib +#cgo android pkg-config: webrtc-android-armeabi-v7a.pc #cgo linux,arm pkg-config: webrtc-linux-arm.pc #cgo linux,386 pkg-config: webrtc-linux-386.pc #cgo linux,amd64 pkg-config: webrtc-linux-amd64.pc diff --git a/webrtc-android-armeabi-v7a.pc b/webrtc-android-armeabi-v7a.pc new file mode 100644 index 0000000..36e41e1 --- /dev/null +++ b/webrtc-android-armeabi-v7a.pc @@ -0,0 +1,17 @@ +pc=${pcfiledir} + +Name: webrtc +Description: webrtc +Version: 1 + +Cflags: \ + -I${pc}/include \ + -DPOSIX \ + -DWEBRTC_ANDROID + +Libs: \ + -L${pc}/lib \ + -lwebrtc-android-arm-magic \ + -lOpenSLES \ + -llog \ + -ldl