build 3.4 KB

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