build 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. mkdir -p "$distdir/Tor/libstdc++"
  74. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libstdc++.so.6 "$distdir/Tor/libstdc++/"
  75. [% IF c("var/asan") -%]
  76. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libasan.so.5 "$distdir/Tor/"
  77. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libubsan.so.1 "$distdir/Tor/"
  78. [% END -%]
  79. chmod 700 "$distdir"/Tor/*.so*
  80. chmod 700 "$distdir"/Tor/libstdc++/*.so*
  81. # This is needed to make RPATH unavailable. See bug 9150.
  82. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$distdir/Tor/"
  83. [% END %]
  84. [% IF c("var/osx") %]
  85. cp $libeventdir/lib/libevent-*.dylib $TORBINDIR/
  86. [% END %]
  87. cd /var/tmp/build/[% project %]-[% c('version') %]
  88. # add git hash to micro-revision.i for #24995
  89. echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
  90. ./autogen.sh
  91. find -type f -print0 | xargs -0 [% c("var/touch") %]
  92. [% 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" \
  93. [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
  94. [% IF c("var/windows") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  95. [% IF c("var/osx") %]--enable-static-openssl[% END %] \
  96. [% IF !c("var/android") && c("var/nightly") %]--enable-rust[% END %] \
  97. --prefix="$distdir" [% c("var/configure_opt") %]
  98. [% IF c("var/osx") -%]
  99. export LD_PRELOAD=[% c("var/faketime_path") %]
  100. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  101. [% END -%]
  102. make -j[% c("buildconf/num_procs") %]
  103. make install
  104. [% IF c("var/osx") -%]
  105. unset LD_PRELOAD
  106. [% END -%]
  107. cp $distdir/share/tor/geoip $TORCONFIGDIR
  108. cp $distdir/share/tor/geoip6 $TORCONFIGDIR
  109. [% IF c("var/osx") %]
  110. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  111. cd $distdir
  112. cp bin/tor $TORBINDIR/
  113. cd $TORBINDIR/
  114. x86_64-apple-darwin-install_name_tool -change $libeventdir/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor
  115. [% END %]
  116. cd $distdir
  117. [% IF c("var/windows") %]
  118. install -s $distdir/bin/tor.exe $distdir/Tor/
  119. [% IF c("var/expert_bundle") %]
  120. install -s $distdir/bin/tor-gencert.exe $distdir/Tor/
  121. [% END %]
  122. [% END %]
  123. [% IF c("var/linux") %]
  124. # Strip and generate debuginfo for libs
  125. objcopy --only-keep-debug $distdir/bin/tor $distdir/Debug/Tor/tor
  126. install -s $distdir/bin/tor $distdir/Tor/
  127. objcopy --add-gnu-debuglink=./Debug/Tor/tor $distdir/Tor/tor
  128. for i in $distdir/Tor/*so*
  129. do
  130. LIB=`basename $i`
  131. objcopy --only-keep-debug $distdir/Tor/$LIB $distdir/Debug/Tor/$LIB
  132. strip $distdir/Tor/$LIB
  133. objcopy --add-gnu-debuglink=./Debug/Tor/$LIB $distdir/Tor/$LIB
  134. done
  135. [% END %]
  136. [% IF c("var/android") %]
  137. install -s --strip-program=[% c("var/cross_prefix") %]-strip $distdir/bin/tor $libsdir/libTor.so
  138. [% END %]
  139. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  140. [%
  141. IF c("var/expert_bundle");
  142. SET win_arch = c('var/windows-x86_64') ? 'win64' : 'win32';
  143. c('zip', {
  144. zip_src => [ 'Data', 'Tor', ],
  145. zip_args => dest_dir _ '/' _ c('filename') _ '/tor-' _ win_arch _ '-' _ c("version") _ '.zip',
  146. });
  147. ELSE;
  148. IF c("var/osx");
  149. SET tarsrcdir = [ 'Contents' ];
  150. ELSIF c("var/android");
  151. SET tarsrcdir = [ 'assets', 'jniLibs' ];
  152. ELSE;
  153. SET tarsrcdir = [ 'Data', 'Tor', ];
  154. END;
  155. c('tar', {
  156. tar_src => tarsrcdir,
  157. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor.tar.gz',
  158. });
  159. END;
  160. %]
  161. [% IF c("var/linux") %]
  162. [% c('tar', {
  163. tar_src => [ 'Debug' ],
  164. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-debug.tar.xz',
  165. }) %]
  166. [% END %]