build 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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://gn.googlesource.com/gn/+/master/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. # Use libstdc++, not libc++.
  94. GN_ARGS+=" use_custom_libcxx=false"
  95. [% IF c("var/linux") -%]
  96. GN_ARGS+=" target_os=\"linux\" target_cpu=\"[% IF c("var/linux-i686") %]x86[% ELSE %]x64[% END %]\""
  97. GN_ARGS+=" gold_path=\"$INSTDIR/binutils/bin\""
  98. # Make extra sure we don't use bundled binutils.
  99. rm -rf third_party/binutils/Linux_*
  100. # Avoid some dependencies.
  101. GN_ARGS+=" use_ozone=true use_gconf=false"
  102. GN_ARGS+=" rtc_include_opus=false rtc_include_ilbc=false rtc_include_internal_audio_device=false rtc_include_pulse_audio=false"
  103. # Included for "field_trial" below. Maybe "fieldtrial_testing_like_official_build" could help here?
  104. #GN_ARGS+=" rtc_include_tests=false"
  105. [% END -%]
  106. [% IF c("var/osx") -%]
  107. GN_ARGS+=" target_os=\"mac\" target_cpu=\"x64\" mac_deployment_target=\"10.7\""
  108. GN_ARGS+=" clang_use_chrome_plugins=false"
  109. GN_ARGS+=" clang_base_path=\"$clangdir\""
  110. # No lld in our toolchain currently.
  111. GN_ARGS+=" use_lld=false"
  112. # Avoid some dependencies.
  113. GN_ARGS+=" rtc_include_opus=false rtc_include_ilbc=false rtc_include_internal_audio_device=false"
  114. # Tests are needed for field_trial, metrics_default, and pc_test_utils targets
  115. # (which include code needed by go-webrtc).
  116. GN_ARGS+=" rtc_include_tests=true"
  117. # Make sure not to use bundled clang and binutils.
  118. rm -rf third_party/llvm-build
  119. rm -rf third_party/binutils
  120. [% END -%]
  121. rm -rf out/Release
  122. "$GN" gen out/Release --args="$GN_ARGS"
  123. ninja -C out/Release webrtc field_trial metrics_default pc_test_utils
  124. # The cctools ar doesn't have the 'D' deterministic option of GNU ar, but the
  125. # ZERO_AR_DATE environment variable similarly sets timestamps within the
  126. # archive to zero.
  127. # https://opensource.apple.com/source/cctools/cctools-886/ar/archive.c.auto.html
  128. # https://codereview.chromium.org/699083004/
  129. # .o files under out/Release/obj/ are the build outputs. Don't include .o
  130. # files from elsewhere under out/ because they are build helpers and things
  131. # like that, not necessarily of the target architecture, and anyway are not
  132. # needed.
  133. # https://bugs.torproject.org/22832
  134. find out/Release/obj -name '*.o' -print0 | sort -z \
  135. | [% IF c("var/osx") %]ZERO_AR_DATE=1 [% END %] xargs -0 -- "$AR" crs libwebrtc-magic.a
  136. mkdir -p $distdir
  137. cd $distdir
  138. mkdir -p include lib
  139. cp -f $builddir/libwebrtc-magic.a [% c("var/webrtc/lib_path") %]
  140. INCLUDE_DIR="$PWD/include"
  141. cd $builddir
  142. find . -type f -name '*.h' -print0 | while IFS= read -r -d '' h;
  143. do
  144. mkdir -p "$INCLUDE_DIR/$(dirname "$h")"
  145. cp -f "$h" "$INCLUDE_DIR/$h"
  146. done
  147. cd /var/tmp/dist
  148. [% c('tar', {
  149. tar_src => [ project ],
  150. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  151. }) %]