build 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. [% c('var/setarch') %]
  3. [% c("var/set_default_env") -%]
  4. distdir=/var/tmp/dist/[% project %]
  5. mkdir -p $distdir
  6. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cmake') %]
  7. export PATH="/var/tmp/dist/cmake/bin:$PATH"
  8. tar -C /var/tmp/dist -xf [% c('input_files_by_name/prev_rust') %]
  9. cd /var/tmp/dist/rust-[% c('var/prev_version') %]-[% c('var/rust_arch') %]-unknown-linux-gnu
  10. ./install.sh --prefix=$distdir-rust-old
  11. export PATH="$distdir-rust-old/bin:$PATH"
  12. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  13. [% IF c("var/osx") %]
  14. # We need to clear `CC` and `LDFLAGS` as they are used for the host platform
  15. # (i.e. Linux).
  16. unset CC
  17. unset LDFLAGS
  18. # Target 10.7 as our toolchain does. Without this explicit declaration Bad
  19. # Things will happen, as a lot of dependent code then assumes that the
  20. # official macOS target, x86_64-apple-darwin, essentially means 10.4.
  21. export MACOSX_DEPLOYMENT_TARGET=10.7
  22. # The Rust target for macOS is x86_64-apple-darwin, yet our toolchain is built
  23. # for x86_64-apple-darwin11. We can't mix those targets as clang gets confused
  24. # that way. Changing the Rust target to x86_64-apple-darwin11 would require a
  25. # fair amount of patching, thus we create symlinks to provide Rust with the
  26. # necessary tools while using our toolchain underneath, targeting 10.7.
  27. cd $cctoolsdir
  28. for f in `ls x86_64-apple-darwin11-*`; do
  29. ln -s $f ${f//x86_64-apple-darwin11/x86_64-apple-darwin}
  30. done
  31. cd ..
  32. ln -s x86_64-apple-darwin11 x86_64-apple-darwin
  33. mkdir $distdir/helper
  34. # We need to adapt our CFLAGS and make sure our flags are passed down to all
  35. # dependencies. Using `CFLAGS_x86_apple-darwin` did not do the trick, so resort
  36. # to a wrapper script.
  37. cat > $distdir/helper/x86_64-apple-darwin-clang << 'EOF'
  38. #!/bin/sh
  39. BASEDIR=/var/tmp/dist/macosx-toolchain
  40. $BASEDIR/cctools/bin/x86_64-apple-darwin-clang -target x86_64-apple-darwin -B $BASEDIR/cctools/bin -isysroot $BASEDIR/SDK/ -Wl,-syslibroot,$BASEDIR/SDK/ -Wl,-dead_strip -Wl,-pie "$@"
  41. EOF
  42. chmod +x $distdir/helper/x86_64-apple-darwin-clang
  43. export PATH=$distdir/helper:$PATH
  44. [% END %]
  45. cd $rootdir
  46. mkdir /var/tmp/build
  47. tar -C /var/tmp/build -xf [% c('input_files_by_name/rust') %]
  48. cd /var/tmp/build/rustc-[% c('version') %]-src
  49. [% IF c("var/windows-i686") %]
  50. # Cross-compiling for Windows 32bit is currently not possible without any
  51. # patches. The reason for that is libstd expecting DWARF unwinding while most
  52. # toolchains on Linux, targeting Windows 32bit, use SjLj unwinding.
  53. # See: https://github.com/rust-lang/rust/issues/12859 for discussion about
  54. # that and https://github.com/rust-lang/rust/pull/49633 for a newer attempt to
  55. # fix this problem. We apply the patch from neersighted.
  56. [% IF !c("input_file_var/unwind_128") %]
  57. patch -p1 < $rootdir/unwind.patch
  58. [% ELSE %]
  59. patch -p1 < $rootdir/unwind_128.patch
  60. [% END %]
  61. [% END %]
  62. [% IF c("var/android") %]
  63. patch -p1 < $rootdir/replace_pagesize_in_mmap.patch
  64. # The additional Rust patch is not necessary for x86.
  65. [% IF c("var/android-armv7") %]
  66. patch -p1 < $rootdir/0001-Make-sure-dl_iterate_phdr-is-undefined-on-Android.patch
  67. [% END %]
  68. [% END %]
  69. mkdir build
  70. cd build
  71. ../configure --prefix=$distdir [% c("var/configure_opt") %]
  72. # We need to disable Thin LTO due to reproducibility issues on macOS and
  73. # probably Linux. Alas, there is no direct option available in the config.toml
  74. # in 1.26.1 yet, so we need to toggle this indirectly via `codegen-units`.
  75. [% IF c("var/osx") || c("var/linux") %]
  76. # It seems hard to pass the proper value via ./configure so we resort to our
  77. # old friend `sed`.
  78. sed -i 's/#codegen-units = 1/codegen-units = 1/' config.toml
  79. [% END %]
  80. make -j[% c("buildconf/num_procs") %]
  81. make install
  82. cd /var/tmp/dist
  83. [% c('tar', {
  84. tar_src => [ project ],
  85. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  86. }) %]