build 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  4. distdir=/var/tmp/dist/[% project %]
  5. mkdir -p /var/tmp/build
  6. [% IF c("var/android") %]
  7. TORCONFIGDIR="$distdir/assets/common"
  8. libsdir=$distdir/jniLibs/[% c("var/abi") %]
  9. mkdir -p $libsdir $TORCONFIGDIR "$distdir/Tor"
  10. # We need to make sure our ZSTD dependencey is properly picked up.
  11. # --enable-zstd is not enough.
  12. export ZSTD_CFLAGS=-I/var/tmp/dist/zstd/include
  13. export ZSTD_LIBS=/var/tmp/dist/zstd/lib/libzstd.a
  14. [% END %]
  15. [% IF c("var/linux") || c("var/windows") %]
  16. TORCONFIGDIR="$distdir/Data/Tor"
  17. mkdir -p $TORCONFIGDIR
  18. mkdir -p "$distdir/Tor"
  19. [% END %]
  20. [% IF c("var/osx") %]
  21. [% IF c("var/nightly") %]
  22. # We are compiling Tor with Rust enabled for nightlies.
  23. export TOR_RUST_TARGET=x86_64-apple-darwin
  24. [% END %]
  25. TORBINDIR="$distdir/Contents/MacOS/Tor"
  26. TORCONFIGDIR="$distdir/Contents/Resources/TorBrowser/Tor"
  27. mkdir -p $distdir/bin
  28. mkdir -p $TORBINDIR
  29. mkdir -p $TORCONFIGDIR
  30. [% END %]
  31. [% IF c("var/windows") || c("var/android") %]
  32. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zlib') %]
  33. zlibdir=/var/tmp/dist/zlib
  34. [% END %]
  35. [% IF c("var/android") %]
  36. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zstd') %]
  37. [% END %]
  38. [% IF !c("var/android") && c("var/nightly") %]
  39. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  40. export PATH=/var/tmp/dist/rust/bin:$PATH
  41. [% END %]
  42. tar -C /var/tmp/dist -xf [% c('input_files_by_name/openssl') %]
  43. tar -C /var/tmp/dist -xf [% c('input_files_by_name/libevent') %]
  44. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  45. libeventdir=/var/tmp/dist/libevent
  46. openssldir=/var/tmp/dist/openssl/openssl
  47. [% IF c("var/windows") %]
  48. [% IF c("var/nightly") %]
  49. # We are compiling Tor with Rust enabled for nightlies.
  50. export TOR_RUST_TARGET=[% c("arch") %]-pc-windows-gnu
  51. [% END %]
  52. # XXX: It's a bit unfortunate but we need the pthread dll here as libevent
  53. # gets compiled with pthread support once it is enabled in GCC, which we need
  54. # to do as otherwise the Rust compilaton breaks.
  55. mingwlibs=/var/tmp/dist/mingw-w64/[% c("arch") %]-w64-mingw32/bin/
  56. cp $zlibdir/lib/*.dll $openssldir/bin/*.dll $libeventdir/bin/*.dll \
  57. $gcclibs/*.dll $mingwlibs/libwinpthread-1.dll $distdir/Tor/
  58. [% END %]
  59. [% IF c("var/linux-i686") && c("var/nightly") -%]
  60. export TOR_RUST_TARGET=i686-unknown-linux-gnu
  61. [% END -%]
  62. [% IF c("var/linux") %]
  63. mkdir -p "$distdir/Debug/Tor"
  64. cp $openssldir/lib/libssl.so.1.1 "$distdir/Tor/"
  65. cp $openssldir/lib/libcrypto.so.1.1 "$distdir/Tor/"
  66. cp $libeventdir/lib/libevent-2.1.so.7 "$distdir/Tor/"
  67. # We need to copy the libstdc++.so.6 for Tor Browser on older Linux distros.
  68. # Copying it into /Browser, which feels more natural, and amending
  69. # LD_LIBRARY_PATH breaks updates from a Tor Browser with the old
  70. # LD_LIBRARY_PATH value to the Tor Browser with the newer one. Thus, we copy
  71. # the libstdc++ into the directory with the libs tor depends on, too. See bug
  72. # 13359 for further details.
  73. libstdc_dir="$distdir/Tor/libstdc++"
  74. mkdir -p $libstdc_dir
  75. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libstdc++.so.6 $libstdc_dir/
  76. [% IF c("var/asan") -%]
  77. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libasan.so.5 "$distdir/Tor/"
  78. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libubsan.so.1 "$distdir/Tor/"
  79. [% END -%]
  80. chmod 700 "$distdir"/Tor/*.so*
  81. chmod 700 $libstdc_dir/libstdc++.so.6
  82. strip $libstdc_dir/libstdc++.so.6
  83. # This is needed to make RPATH unavailable. See bug 9150.
  84. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$distdir/Tor/"
  85. [% END %]
  86. [% IF c("var/osx") %]
  87. cp $libeventdir/lib/libevent-*.dylib $TORBINDIR/
  88. [% END %]
  89. cd /var/tmp/build/[% project %]-[% c('version') %]
  90. # add git hash to micro-revision.i for #24995
  91. echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
  92. ./autogen.sh
  93. find -type f -print0 | xargs -0 [% c("var/touch") %]
  94. [% IF !c("var/android") && c("var/nightly") %]TOR_RUST_DEPENDENCIES=`pwd`/src/ext/rust/crates[% END %] ./configure --disable-asciidoc --with-libevent-dir="$libeventdir" --with-openssl-dir="$openssldir" \
  95. [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
  96. [% IF c("var/windows") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  97. [% IF c("var/osx") %]--enable-static-openssl[% END %] \
  98. [% IF !c("var/android") && c("var/nightly") %]--enable-rust[% END %] \
  99. --prefix="$distdir" [% c("var/configure_opt") %]
  100. [% IF c("var/osx") -%]
  101. export LD_PRELOAD=[% c("var/faketime_path") %]
  102. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  103. [% END -%]
  104. make -j[% c("buildconf/num_procs") %]
  105. make install
  106. [% IF c("var/osx") -%]
  107. unset LD_PRELOAD
  108. [% END -%]
  109. cp $distdir/share/tor/geoip $TORCONFIGDIR
  110. cp $distdir/share/tor/geoip6 $TORCONFIGDIR
  111. [% IF c("var/osx") %]
  112. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  113. cd $distdir
  114. cp bin/tor $TORBINDIR/
  115. cd $TORBINDIR/
  116. x86_64-apple-darwin-install_name_tool -change $libeventdir/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor
  117. [% END %]
  118. cd $distdir
  119. [% IF c("var/windows") %]
  120. install -s $distdir/bin/tor.exe $distdir/Tor/
  121. [% IF c("var/expert_bundle") %]
  122. install -s $distdir/bin/tor-gencert.exe $distdir/Tor/
  123. [% END %]
  124. [% END %]
  125. [% IF c("var/linux") %]
  126. # Strip and generate debuginfo for libs
  127. objcopy --only-keep-debug $distdir/bin/tor $distdir/Debug/Tor/tor
  128. install -s $distdir/bin/tor $distdir/Tor/
  129. objcopy --add-gnu-debuglink=./Debug/Tor/tor $distdir/Tor/tor
  130. for i in $distdir/Tor/*so*
  131. do
  132. LIB=`basename $i`
  133. objcopy --only-keep-debug $distdir/Tor/$LIB $distdir/Debug/Tor/$LIB
  134. strip $distdir/Tor/$LIB
  135. objcopy --add-gnu-debuglink=./Debug/Tor/$LIB $distdir/Tor/$LIB
  136. done
  137. [% END %]
  138. [% IF c("var/android") %]
  139. install -s --strip-program=[% c("var/cross_prefix") %]-strip $distdir/bin/tor $libsdir/libTor.so
  140. [% END %]
  141. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  142. [%
  143. IF c("var/expert_bundle");
  144. SET win_arch = c('var/windows-x86_64') ? 'win64' : 'win32';
  145. c('zip', {
  146. zip_src => [ 'Data', 'Tor', ],
  147. zip_args => dest_dir _ '/' _ c('filename') _ '/tor-' _ win_arch _ '-' _ c("version") _ '.zip',
  148. });
  149. ELSE;
  150. IF c("var/osx");
  151. SET tarsrcdir = [ 'Contents' ];
  152. ELSIF c("var/android");
  153. SET tarsrcdir = [ 'assets', 'jniLibs' ];
  154. ELSE;
  155. SET tarsrcdir = [ 'Data', 'Tor', ];
  156. END;
  157. c('tar', {
  158. tar_src => tarsrcdir,
  159. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor.tar.gz',
  160. });
  161. END;
  162. %]
  163. [% IF c("var/linux") %]
  164. [% c('tar', {
  165. tar_src => [ 'Debug' ],
  166. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-debug.tar.xz',
  167. }) %]
  168. [% END %]