build 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. builddir=/var/tmp/build
  4. mkdir $builddir
  5. distdir=/var/tmp/dist/[% project %]
  6. mkdir -p "$distdir"
  7. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cmake') %]
  8. tar -C /var/tmp/dist -xf [% c('input_files_by_name/ninja') %]
  9. tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
  10. tar -C $distdir -xf [% c('input_files_by_name/SDK') %]
  11. tar -C $distdir -xf [% c('input_files_by_name/cctools') %]
  12. tar -C $builddir -xf [% c('input_files_by_name/clang-source') %]
  13. clangdir=/var/tmp/dist/clang/bin
  14. cctoolsdir=$distdir/cctools/bin
  15. sysrootdir=$distdir/MacOSX10.11.sdk/
  16. # We still need to put the cctoolsdir on the path. That's because of `lipo`. See
  17. # the respective comment in the cctools build script.
  18. export PATH="/var/tmp/dist/ninja:/var/tmp/dist/cmake/bin:$cctoolsdir:$PATH"
  19. export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]
  20. cd $builddir/clang-source/projects
  21. patch -p1 < $rootdir/compiler-rt-cross-compile.patch
  22. patch -p1 < $rootdir/compiler-rt-no-codesign.patch
  23. cd ..
  24. mkdir build
  25. cd build
  26. # We follow quite closely Mozilla's build/build-clang/build-clang.py with the
  27. # clang-macosx64.json flavor. This currently implies disabling Xray as it
  28. # requires an OSX 10.12 SDK (see: https://bugs.llvm.org/show_bug.cgi?id=38959).
  29. cmake -GNinja \
  30. -DCMAKE_C_COMPILER=$clangdir/clang \
  31. -DCMAKE_CXX_COMPILER=$clangdir/clang++ \
  32. -DCMAKE_ASM_COMPILER=$clangdir/clang \
  33. -DCMAKE_LINKER=$clangdir/clang \
  34. -DCMAKE_AR=$cctoolsdir/x86_64-apple-darwin-ar \
  35. -DCMAKE_C_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  36. -DCMAKE_CXX_FLAGS="-stdlib=libc++ [% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  37. -DCMAKE_ASM_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  38. -DCMAKE_EXE_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  39. -DCMAKE_SHARED_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  40. -DCMAKE_BUILD_TYPE=Release \
  41. -DCMAKE_INSTALL_PREFIX=$distdir/clang \
  42. -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
  43. -DLLVM_ENABLE_ASSERTIONS=OFF \
  44. -DPYTHON_EXECUTABLE=/usr/bin/python2.7 \
  45. -DLLVM_TOOL_LIBCXX_BUILD=ON \
  46. -DLLVM_ENABLE_BINDINGS=OFF \
  47. -DLLVM_ENABLE_LIBXML2=FORCE_ON \
  48. -DLLVM_LINK_LLVM_DYLIB=ON \
  49. -DCMAKE_RANLIB=$cctoolsdir/x86_64-apple-darwin-ranlib \
  50. -DCMAKE_LIBTOOL=$cctoolsdir/x86_64-apple-darwin-libtool \
  51. -DCMAKE_SYSTEM_NAME=Darwin \
  52. -DCMAKE_SYSTEM_VERSION=10.10 \
  53. -DLLVM_ENABLE_THREADS=OFF \
  54. -DCOMPILER_RT_BUILD_XRAY=OFF \
  55. -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/clang-source/projects/libcxx/include \
  56. -DCMAKE_OSX_SYSROOT=$sysrootdir \
  57. -DCMAKE_FIND_ROOT_PATH=$sysrootdir \
  58. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
  59. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  60. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  61. -DCMAKE_MACOSX_RPATH=ON \
  62. -DCMAKE_OSX_ARCHITECTURES=x86_64 \
  63. -DDARWIN_osx_ARCHS=x86_64 \
  64. -DDARWIN_osx_SYSROOT=$sysrootdir \
  65. -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin $builddir/clang-source
  66. ninja install -v
  67. # We now have a native macosx64 toolchain.
  68. # What we want is a native linux64 toolchain which can target macosx64.
  69. # Overlay the linux64 toolchain that we used for this build. Note: we don't do
  70. # any ASan builds for macOS (yet). Once we do that we need to preserve at least
  71. # `llvm-symbolizer` as that one seems to get shipped with sanitizer builds (at
  72. # least that's what Mozilla claims).
  73. cd $distdir
  74. cp --remove-destination -lr /var/tmp/dist/clang/* clang/
  75. cd cctools/bin
  76. ln -s ../../clang/bin/clang x86_64-apple-darwin-clang
  77. ln -s ../../clang/bin/clang++ x86_64-apple-darwin-clang++
  78. cd /var/tmp/dist
  79. [% c('tar', {
  80. tar_src => [ project ],
  81. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  82. }) %]