build 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% IF ! c("var/linux-cross") %]
  4. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  5. [% END %]
  6. [% IF c("var/linux-ppc64le") %]
  7. [% pc(c('var/compiler'), 'var/setup', {
  8. compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')),
  9. hardened_gcc => 0
  10. }) %]
  11. [% pc('gcc', 'var/setup', {
  12. compiler_tarfile => c('input_files_by_name/' _ 'gcc-host'),
  13. hardened_gcc => 0,
  14. target => [ c('var/channel'), 'torbrowser-linux-x86_64' ]
  15. }) %]
  16. # GCC's cc1 expects Jessie libmpfr; we feed it a symlink to Buster's instead
  17. # as a stupid compat cludge. TODO: Maybe copy in the actual Jessie version
  18. # from the GCC build container?
  19. mkdir -p /var/tmp/dist/libmpfr
  20. ln -s -T /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /var/tmp/dist/libmpfr/libmpfr.so.4
  21. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/libmpfr"
  22. # Required for fontconfig
  23. cp -a /usr/include/fontconfig /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/fontconfig
  24. cp /usr/lib/[% c('var/crosstarget') %]/libfontconfig.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  25. # Required for X
  26. cp -a /usr/include/X11 /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/X11
  27. cp /usr/lib/[% c('var/crosstarget') %]/libX11.* /usr/lib/[% c('var/crosstarget') %]/libX11-xcb.* /usr/lib/[% c('var/crosstarget') %]/libxcb.* /usr/lib/[% c('var/crosstarget') %]/libxcb-shm.* /usr/lib/[% c('var/crosstarget') %]/libXext.* /usr/lib/[% c('var/crosstarget') %]/libXt.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  28. # Required for wayland
  29. cp -a /usr/include/wayland-*.h /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/
  30. cp /usr/lib/[% c('var/crosstarget') %]/libwayland-*.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  31. # Required for xkbcommon
  32. cp -a /usr/include/xkbcommon /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/xkbcommon
  33. cp /usr/lib/[% c('var/crosstarget') %]/libxkbcommon.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  34. # Required for xcb
  35. cp -a /usr/include/xcb /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/xcb
  36. cp /usr/lib/[% c('var/crosstarget') %]/libxcb.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  37. # Required for zlib
  38. cp /usr/lib/[% c('var/crosstarget') %]/libz.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  39. cp /lib/[% c('var/crosstarget') %]/libz.* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  40. [% END %]
  41. mkdir -p /var/tmp/dist
  42. distdir=/var/tmp/dist/[% project %]
  43. mkdir -p /var/tmp/build
  44. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  45. [% IF c("var/windows") %]
  46. # Setting up fxc2
  47. tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
  48. export PATH="/var/tmp/dist/fxc2/bin:$PATH"
  49. # Setting up stack protector support
  50. tar -C /var/tmp/dist -xf [% c('input_files_by_name/mingw-w64') %]
  51. cp /var/tmp/dist/mingw-w64/gcclibs/{libssp.a,libssp_nonshared.a} /var/tmp/dist/mingw-w64-clang/[% c("arch") %]-w64-mingw32/lib/
  52. [% END -%]
  53. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  54. [% IF c("var/linux-cross") %]
  55. # Rust expects Jessie OpenSSL, so we provide it here
  56. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/rust/lib_host"
  57. [% END %]
  58. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
  59. tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
  60. tar -C /var/tmp/dist -xf [% c('input_files_by_name/node') %]
  61. export PATH="/var/tmp/dist/rust/bin:/var/tmp/dist/cbindgen:/var/tmp/dist/nasm/bin:/var/tmp/dist/node/bin:$PATH"
  62. tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
  63. [% IF c("var/linux-cross") && ! c("var/linux-ppc64le") %]
  64. # clang expects self-built libstdc++, so we provide it here
  65. tar -C /var/tmp/dist -xf [% c('input_files_by_name/gcc-host') %]
  66. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/gcc/lib64:/var/tmp/dist/gcc/lib32"
  67. [% END %]
  68. export LLVM_CONFIG="/var/tmp/dist/clang/bin/llvm-config"
  69. [% IF c("var/linux") %]
  70. tar -C /var/tmp/dist -xf [% c('input_files_by_name/python') %]
  71. export PATH="/var/tmp/dist/python/bin:$PATH"
  72. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  73. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  74. # Use clang for everything on Linux now if we don't build with ASan.
  75. [% IF ! c("var/asan") -%]
  76. export PATH="/var/tmp/dist/clang/bin:$PATH"
  77. [% END -%]
  78. [% IF c("var/linux-i686") %]
  79. # Exporting `PKG_CONFIG_PATH` in the mozconfig file is causing build
  80. # breakage in Rust code. It seems that environment variable is not passed
  81. # down properly in that case. Thus, we set it here in the build script.
  82. export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib/i386-linux-gnu/pkgconfig"
  83. [% END -%]
  84. [% END -%]
  85. [% IF c("var/rlbox") -%]
  86. tar -C /var/tmp/dist -xf [% c('input_files_by_name/wasi-sysroot') %]
  87. # XXX: We need the libclang_rt.builtins-wasm32.a in our clang lib directory.
  88. # Copy it over.
  89. # https://searchfox.org/mozilla-central/source/build/build-clang/build-clang.py#890,
  90. # include it directly in our clang
  91. rtdir=/var/tmp/dist/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  92. [% IF c("var/osx") -%]
  93. rtdir=/var/tmp/dist/macosx-toolchain/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  94. [% END-%]
  95. mkdir -p $rtdir
  96. cp /var/tmp/dist/wasi-sysroot/lib/clang/11.0.0/lib/wasi/libclang_rt.builtins-wasm32.a $rtdir
  97. tar -C /var/tmp/dist -xf [% c('input_files_by_name/lucetc') %]
  98. export PATH="/var/tmp/dist/lucetc/bin:$PATH"
  99. export WASM_SANDBOXED_LIBRARIES=graphite,ogg
  100. export WASI_SYSROOT=/var/tmp/dist/wasi-sysroot/share/wasi-sysroot
  101. [% END -%]
  102. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  103. [% IF c("var/osx") %]
  104. mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
  105. [% ELSE %]
  106. mkdir -p $distdir/Browser
  107. [% END %]
  108. cd /var/tmp/build/[% project %]-[% c("version") %]
  109. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  110. [% IF c("var/asan") -%]
  111. # Without disabling LSan our build is blowing up:
  112. # https://bugs.torproject.org/10599#comment:52
  113. export ASAN_OPTIONS="detect_leaks=0"
  114. [% END -%]
  115. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  116. if [ -z $MOZ_BUILD_DATE ]
  117. then
  118. echo "MOZ_BUILD_DATE is not set"
  119. exit 1
  120. fi
  121. [% IF c("var/windows") %]
  122. # Make sure widl is not inserting random timestamps, see #21837.
  123. export WIDL_TIME_OVERRIDE="0"
  124. patch -p1 < $rootdir/nsis-uninstall.patch
  125. # mingw-w64 does not support SEH on 32bit systems. Be explicit about that.
  126. export LDFLAGS="[% c('var/flag_noSEH') %]"
  127. [% END -%]
  128. [% IF c("var/linux-arm") %]
  129. patch -p1 < $rootdir/linux-arm-neon.patch
  130. [% END %]
  131. [% IF c("var/namecoin") %]
  132. patch -p1 < $rootdir/namecoin-etld.patch
  133. [% END -%]
  134. # Place a copy of the Tor Launcher sources under browser/extensions
  135. tar -C browser/extensions -xf $rootdir/[% c('input_files_by_name/tor-launcher') %]
  136. [% IF c("var/namecoin") %]
  137. pushd toolkit/torproject/torbutton
  138. patch -p1 < $rootdir/namecoin-torbutton.patch
  139. popd
  140. [% END %]
  141. [% IF c("var/nightly") -%]
  142. # Set update url for nightly (#33402 / #40033)
  143. sed -i 's|^URL=https://aus1\.torproject\.org/.*|URL=https://nightlies.tbb.torproject.org/nightly-updates/updates/nightly-[% c("var/osname") %]/%CHANNEL%/%BUILD_TARGET%/%VERSION%/%LOCALE%|' build/application.ini.in
  144. [% END -%]
  145. [% IF c("var/linux-ppc64le") %]
  146. cp -a js/src/ctypes/libffi /var/tmp/build/libffi
  147. pushd /var/tmp/build/libffi
  148. ./configure --host=[% c('var/crosstarget') %]
  149. # Always errors on this step, but still produces the .so files we want.
  150. make || true
  151. cp /var/tmp/build/libffi/powerpc64le-unknown-linux-gnu/include/*.h /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include/
  152. cp /var/tmp/build/libffi/powerpc64le-unknown-linux-gnu/.libs/* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  153. popd
  154. [% END %]
  155. rm -f configure
  156. rm -f js/src/configure
  157. export MACH_USE_SYSTEM_PYTHON=1
  158. # Android does not support --enable-bundled-fonts option
  159. ./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/channel") %] --enable-bundled-fonts --with-branding=[% c("var/branding_directory") %]
  160. ./mach build --verbose
  161. ./mach build stage-package
  162. [% IF c("var/osx") %]
  163. cp -a obj-macos/dist/firefox/* $distdir
  164. # Remove firefox-bin (we don't use it, see ticket #10126)
  165. rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
  166. # Adjust the Info.plist file
  167. INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  168. mv "$INFO_PLIST" tmp.plist
  169. python3 $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  170. rm -f tmp.plist
  171. [% END %]
  172. [% IF c("var/linux") %]
  173. [% IF c("var/linux-x86_64") && !c("var/asan") %]
  174. cp obj-*/testing/geckodriver/x86_64-unknown-linux-gnu/release/geckodriver $distdir
  175. [% END %]
  176. cp -a obj-*/dist/firefox/* $distdir/Browser/
  177. # Remove firefox-bin (we don't use it, see ticket #10126)
  178. rm -f $distdir/Browser/firefox-bin
  179. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  180. # subsequent builds could test to see if they've been uploaded before...
  181. # But let's find out if it actually matters first..
  182. rm -f $distdir/Browser/*.chk
  183. # Replace firefox by a wrapper script (#25485)
  184. mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  185. mv $rootdir/start-firefox $distdir/Browser/firefox
  186. chmod 755 $distdir/Browser/firefox
  187. [% END %]
  188. [% IF c("var/windows") %]
  189. cp -a obj-*/dist/firefox/* $distdir/Browser/
  190. [% IF c("var/windows-i686") %]
  191. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47_32.dll $distdir/Browser/d3dcompiler_47.dll
  192. [% ELSE %]
  193. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47.dll $distdir/Browser
  194. [% END %]
  195. [% END %]
  196. [% IF c("var/linux-ppc64le") -%]
  197. cp -a /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib64/libssp.so* $distdir/Browser
  198. cp -a /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libffi.so* $distdir/Browser
  199. cp $distdir/Browser/libffi.so $distdir/Browser/libffi.so.6
  200. [% END %]
  201. # Make MAR-based update tools available for use during the bundle phase.
  202. # Note that mar and mbsdiff are standalone tools, compiled for the build
  203. # host's architecture. We also include signmar, certutil, and the libraries
  204. # they require; these utilities and libraries are built for the target
  205. # architecture.
  206. MARTOOLS=$distdir/mar-tools
  207. mkdir -p $MARTOOLS
  208. cp -p config/createprecomplete.py $MARTOOLS/
  209. cp -p tools/update-packaging/*.sh $MARTOOLS/
  210. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  211. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  212. [% IF c("var/linux") || c("var/osx") %]
  213. cp -p obj-*/dist/bin/signmar $MARTOOLS/
  214. cp -p obj-*/dist/bin/certutil $MARTOOLS/
  215. cp -p obj-*/dist/bin/modutil $MARTOOLS/
  216. cp -p obj-*/dist/bin/pk12util $MARTOOLS/
  217. cp -p obj-*/dist/bin/shlibsign $MARTOOLS/
  218. [% IF c("var/linux") %]
  219. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  220. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  221. [% ELSE %]
  222. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libsoftokn3.dylib"
  223. # No NSPR_LIBS for macOS
  224. NSPR_LIBS=""
  225. [% END %]
  226. for LIB in $NSS_LIBS $NSPR_LIBS; do
  227. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  228. done
  229. [% END %]
  230. [% IF c("var/windows") %]
  231. cp -p obj-*/dist/bin/signmar.exe $MARTOOLS/
  232. cp -p obj-*/dist/bin/certutil.exe $MARTOOLS/
  233. cp -p obj-*/dist/bin/modutil.exe $MARTOOLS/
  234. cp -p obj-*/dist/bin/pk12util.exe $MARTOOLS/
  235. cp -p obj-*/dist/bin/shlibsign.exe $MARTOOLS/
  236. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll softokn3.dll"
  237. for LIB in $NSS_LIBS; do
  238. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  239. done
  240. [% END %]
  241. cd $distdir
  242. [% IF c("var/linux-x86_64") %]
  243. [% IF !c("var/asan") %]
  244. # No need for an unstripped geckodriver
  245. strip geckodriver
  246. [% END %]
  247. mkdir -p $distdir/Debug/Browser
  248. [% IF c("var/linux-cross") %]
  249. TARGET_OBJCOPY=[% c("var/crosstarget") %]-objcopy
  250. TARGET_STRIP=[% c("var/crosstarget") %]-strip
  251. [% ELSE %]
  252. TARGET_OBJCOPY=objcopy
  253. TARGET_STRIP=strip
  254. [% END %]
  255. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  256. # files, the plugin-container, and the updater (see ticket #10126)
  257. for LIB in Browser/*.so Browser/firefox.real Browser/plugin-container Browser/updater
  258. do
  259. $TARGET_OBJCOPY --only-keep-debug $LIB Debug/$LIB
  260. $TARGET_STRIP $LIB
  261. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/$LIB $LIB
  262. done
  263. [% END %]
  264. # Re-zipping the omni.ja files is not needed to make them reproductible,
  265. # however if we don't re-zip them, the files become corrupt when we
  266. # update them using 'zip' and firefox will silently fail to load some
  267. # parts.
  268. [% IF c("var/windows") || c("var/linux") %]
  269. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  270. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  271. [% ELSIF c("var/osx") %]
  272. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  273. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
  274. [% END %]
  275. [%
  276. IF c("var/osx");
  277. SET browserdir='"Tor Browser.app/Contents"';
  278. ELSE;
  279. SET browserdir='Browser';
  280. END;
  281. %]
  282. [% IF c("var/linux") %]
  283. # TODO: abicheck doesn't work on linux-cross yet
  284. [% IF ! c("var/linux-cross") %]
  285. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck -std=c++17
  286. [% END %]
  287. [% END %]
  288. [% c('tar', {
  289. tar_src => [ browserdir ],
  290. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  291. }) %]
  292. [% IF c("var/linux-x86_64") %]
  293. [% c('tar', {
  294. tar_src => [ 'Debug' ],
  295. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  296. }) %]
  297. [% IF !c("var/asan") %]
  298. [% c('tar', {
  299. tar_src => [ 'geckodriver' ],
  300. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/geckodriver-linux64.tar.xz',
  301. }) %]
  302. [% END %]
  303. [% END %]
  304. [% c('zip', {
  305. zip_src => [ 'mar-tools' ],
  306. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  307. }) %]
  308. [% IF c("var/build_infos_json") -%]
  309. cat > "[% dest_dir _ '/' _ c('filename') _ '/build-infos.json' %]" << EOF_BUILDINFOS
  310. {
  311. "firefox_platform_version" : "[% c("var/firefox_platform_version") %]",
  312. "firefox_buildid" : "$MOZ_BUILD_DATE"
  313. }
  314. EOF_BUILDINFOS
  315. [% END -%]