build 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/bash
  2. set -e
  3. [% c("var/set_default_env") -%]
  4. [% c("var/setarch") -%]
  5. distdir=/var/tmp/dist/[% project %]
  6. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  7. mkdir -p /var/tmp/dist
  8. [% IF c("var/linux") %]
  9. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  10. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  11. [% END -%]
  12. [% IF c("var/osx") -%]
  13. # src/build/toolchain/mac/filter_libtool.py wants libtool to be called exactly "libtool".
  14. ln -sf x86_64-apple-darwin11-libtool $cctoolsdir/libtool
  15. export AR=x86_64-apple-darwin11-ar
  16. # Certain cross-compiling flags are set in webrtc-mac.patch because the build
  17. # system doesn't honor CFLAGS etc. environment variables.
  18. [% ELSE -%]
  19. AR=ar
  20. [% END -%]
  21. # Setting up depot_tools
  22. # https://dev.chromium.org/developers/how-tos/install-depot-tools
  23. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/depot_tools') %]
  24. export PATH="$PATH:/var/tmp/dist/depot_tools"
  25. # Disable automatic updating.
  26. export DEPOT_TOOLS_UPDATE=0
  27. mkdir -p /var/tmp/build
  28. tar -C /var/tmp/build -xf webrtc-sources-[% c('version') %].tar.gz
  29. builddir=/var/tmp/build/[% project %]/src
  30. cd $builddir
  31. [% IF c("var/linux") -%]
  32. patch -p1 < $rootdir/webrtc-linux.patch
  33. [% END -%]
  34. [% IF c("var/osx") -%]
  35. patch -p1 < $rootdir/webrtc-mac.patch
  36. [% END -%]
  37. [% IF c("var/linux") -%]
  38. # First, build a copy of GN, rather than use the prebuilt copy in buildtools/linux64.
  39. cd tools/gn
  40. # __STDC_FORMAT_MACROS is needed for a definition of PRIxPTR from inttypes.h.
  41. CXXFLAGS=-D__STDC_FORMAT_MACROS=1 LDFLAGS=-latomic ./bootstrap/bootstrap.py --no-rebuild --no-clean
  42. cd ../..
  43. # This is where bootstrap.py stashes the built gn.
  44. GN="$PWD/out_bootstrap/gn"
  45. [% END -%]
  46. [% IF c("var/osx") -%]
  47. # The linux descriptor builds its own copy of gn, using tools/gn/bootstrap/bootstrap.py.
  48. # I tried that here, but for some reason the gn so built doesn't work. On "gn gen",
  49. # it crashes with this error:
  50. # [0624/022439.767916:FATAL:command_gen.cc(59)] Check failed: !rule.empty().
  51. # Instead, use the gn packaged with depot_tools.
  52. GN="/var/tmp/dist/depot_tools/gn"
  53. # Hardcode the output of some utility programs that otherwise require Xcode
  54. # tools, like xcode-select, xcodebuild, sw_vers, and xcrun. This probably
  55. # needs to be kept in sync with the SDK version.
  56. cat <<EOF > build/mac/find_sdk.py
  57. print("$sysrootdir")
  58. print("10.11")
  59. EOF
  60. cat <<EOF > build/config/mac/sdk_info.py
  61. print("machine_os_build=\"10.7\"")
  62. print("sdk_build=\"10.11\"")
  63. print("sdk_path=\"$sysrootdir\"")
  64. print("sdk_platform_path=\"$sysrootdir\"")
  65. print("sdk_version=\"10.11\"")
  66. print("xcode_build=\"7.3\"")
  67. print("xcode_version=\"0730\"")
  68. EOF
  69. [% END -%]
  70. [% IF c("var/linux") -%]
  71. export CC=gcc
  72. export CXX=g++
  73. [% END -%]
  74. [% IF c("var/linux-i686") -%]
  75. GYP_DEFINES+=" target_arch=ia32"
  76. export CC='gcc -m32'
  77. export CXX='g++ -m32'
  78. export CFLAGS=-m32
  79. export CXXFLAGS=-m32
  80. export LDFLAGS=-m32
  81. [% END -%]
  82. export GN_ARGS=""
  83. # For a list of all possible GN args, do "gn gen out/Release; gn args --list out/Release".
  84. # https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/cross_compiles.md
  85. # Not debug.
  86. GN_ARGS+=" is_debug=false"
  87. # There are warnings from unused returns.
  88. GN_ARGS+=" treat_warnings_as_errors=false"
  89. # Build static libraries.
  90. GN_ARGS+=" is_component_build=false"
  91. # Do not use bundled utilities.
  92. GN_ARGS+=" is_clang=false use_sysroot=false"
  93. [% IF c("var/linux") -%]
  94. GN_ARGS+=" target_os=\"linux\" target_cpu=\"[% IF c("var/linux-i686") %]x86[% ELSE %]x64[% END %]\""
  95. GN_ARGS+=" gold_path=\"$INSTDIR/binutils/bin\""
  96. # Make extra sure we don't use bundled binutils.
  97. rm -rf third_party/binutils/Linux_*
  98. # Avoid some dependencies.
  99. GN_ARGS+=" use_ozone=true use_gconf=false"
  100. GN_ARGS+=" rtc_include_opus=false rtc_include_ilbc=false rtc_include_internal_audio_device=false rtc_include_pulse_audio=false"
  101. # Included for "field_trial" below. Maybe "fieldtrial_testing_like_official_build" could help here?
  102. #GN_ARGS+=" rtc_include_tests=false"
  103. [% END -%]
  104. [% IF c("var/osx") -%]
  105. GN_ARGS+=" target_os=\"mac\" target_cpu=\"x64\" mac_deployment_target=\"10.7\""
  106. GN_ARGS+=" clang_use_chrome_plugins=false"
  107. GN_ARGS+=" clang_base_path=\"$clangdir\""
  108. # Avoid some dependencies.
  109. GN_ARGS+=" rtc_include_opus=false rtc_include_ilbc=false rtc_include_internal_audio_device=false"
  110. # Tests are needed for field_trial, metrics_default, and pc_test_utils targets
  111. # (which include code needed by go-webrtc).
  112. GN_ARGS+=" rtc_include_tests=true"
  113. # Make sure not to use bundled clang and binutils.
  114. rm -rf third_party/llvm-build
  115. rm -rf third_party/binutils
  116. [% END -%]
  117. rm -rf out/Release
  118. "$GN" gen out/Release --args="$GN_ARGS"
  119. ninja -C out/Release webrtc field_trial metrics_default pc_test_utils
  120. # The cctools ar doesn't have the 'D' deterministic option of GNU ar, but the
  121. # ZERO_AR_DATE environment variable similarly sets timestamps within the
  122. # archive to zero.
  123. # https://opensource.apple.com/source/cctools/cctools-886/ar/archive.c.auto.html
  124. # https://codereview.chromium.org/699083004/
  125. # .o files under out/Release/obj/ are the build outputs. Don't include .o
  126. # files from elsewhere under out/ because they are build helpers and things
  127. # like that, not necessarily of the target architecture, and anyway are not
  128. # needed.
  129. # https://bugs.torproject.org/22832
  130. [% IF c("var/osx") %]ZERO_AR_DATE=1 [% END %]"$AR" crs libwebrtc-magic.a $(find out/Release/obj -name '*.o' | sort)
  131. mkdir -p $distdir
  132. cd $distdir
  133. mkdir -p include lib
  134. cp -f $builddir/libwebrtc-magic.a [% c("var/webrtc/lib_path") %]
  135. INCLUDE_DIR="$PWD/include"
  136. cd $builddir
  137. for h in $(find talk/ webrtc/ -type f -name '*.h');
  138. do
  139. mkdir -p "$INCLUDE_DIR/$(dirname $h)"
  140. cp -f "$h" "$INCLUDE_DIR/$h"
  141. done
  142. cd /var/tmp/dist
  143. [% c('tar', {
  144. tar_src => [ project ],
  145. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  146. }) %]