build 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/binutils') %]
  8. export PATH=/var/tmp/dist/binutils/bin:$PATH
  9. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust_prebuilt') %]
  10. cd /var/tmp/dist/rust-[% c('version') %]-x86_64-unknown-linux-gnu
  11. ./install.sh --prefix=$distdir-rust-prebuilt
  12. export PATH="$distdir-rust-prebuilt/bin:$PATH"
  13. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  14. [% IF c("var/linux") || c("var/android") || c("var/windows") -%]
  15. # See the config file for more details on why we do that also on Windows
  16. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/clang') %]
  17. export PATH=/var/tmp/dist/clang/bin:$PATH
  18. [% END -%]
  19. [% IF c("var/linux") -%]
  20. [% pc('python', 'var/setup', { python_tarfile => c('input_files_by_name/python') }) %]
  21. export LLVM_CONFIG="/var/tmp/dist/clang/bin/llvm-config"
  22. export CC=clang
  23. export CXX=clang++
  24. export CFLAGS='--gcc-toolchain=/var/tmp/dist/gcc'
  25. export CXXFLAGS='--gcc-toolchain=/var/tmp/dist/gcc'
  26. export RUSTFLAGS="-L/var/tmp/dist/gcc/lib64"
  27. [% END -%]
  28. [% IF c("var/macos") %]
  29. # We need to clear `CC` and `LDFLAGS` as they are used for the host platform
  30. # (i.e. Linux).
  31. unset CC
  32. unset LDFLAGS
  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/[% c("var/build_target") %]-clang << 'EOF'
  38. #!/bin/sh
  39. BASEDIR=/var/tmp/dist/macosx-toolchain
  40. $BASEDIR/cctools/bin/[% c("var/build_target") %]-clang -target [% c("var/build_target") %] -B $BASEDIR/cctools/bin -isysroot $sysrootdir -Wl,-syslibroot,$sysrootdir -Wl,-dead_strip -Wl,-pie [% IF c('var/macos-aarch64') %]-mcpu=apple-m1[% END %] "$@"
  41. EOF
  42. chmod +x $distdir/helper/[% c("var/build_target") %]-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. mkdir build
  50. cd build
  51. ../configure --prefix=$distdir --disable-docs --disable-compiler-docs [% c("var/configure_opt") %]
  52. make -j[% c("num_procs") %]
  53. make install
  54. cd /var/tmp/dist
  55. [% IF c("var/linux") -%]
  56. # When we compile some Rust-only projects such as cbindgen, we do not include
  57. # the C/C++ compilers and their modern libstdc++ library.
  58. # For simplicity, we keep it also with Rust, and add it to LD_LIBRARY_PATH
  59. # if needed.
  60. cp gcc/lib64/libstdc++.so* rust/lib/
  61. [% END -%]
  62. [% c('tar', {
  63. tar_src => [ project ],
  64. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  65. }) %]