build 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/llvm-project') %]
  13. arch=x86_64
  14. clangdir=/var/tmp/dist/clang/bin
  15. cctoolsdir=$distdir/cctools/bin
  16. sysrootdir=$distdir/MacOSX[% c("version") %].sdk/
  17. target=x86_64-apple-darwin
  18. # We still need to put the cctoolsdir on the path. That's because of `lipo`. See
  19. # the respective comment in the cctools build script.
  20. export PATH="/var/tmp/dist/ninja:/var/tmp/dist/cmake/bin:$cctoolsdir:$PATH"
  21. export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]
  22. export MACH_USE_SYSTEM_PYTHON=1
  23. cd $builddir/clang-source
  24. patch -p1 < $rootdir/compiler-rt-cross-compile.patch
  25. patch -p1 < $rootdir/compiler-rt-no-codesign.patch
  26. cd ..
  27. mkdir build_clang
  28. pushd build_clang
  29. # We follow quite closely Mozilla's build/build-clang/build-clang.py with the
  30. # clang-macosx64.json flavor.
  31. cmake -GNinja \
  32. -DCMAKE_C_COMPILER=$clangdir/clang \
  33. -DCMAKE_CXX_COMPILER=$clangdir/clang++ \
  34. -DCMAKE_ASM_COMPILER=$clangdir/clang \
  35. -DCMAKE_LINKER=$clangdir/clang \
  36. -DCMAKE_AR=$cctoolsdir/$target-ar \
  37. -DCMAKE_C_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  38. -DCMAKE_CXX_FLAGS="-stdlib=libc++ [% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  39. -DCMAKE_ASM_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  40. -DCMAKE_EXE_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  41. -DCMAKE_SHARED_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  42. -DCMAKE_BUILD_TYPE=Release \
  43. -DCMAKE_INSTALL_PREFIX=$distdir/clang \
  44. -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
  45. -DLLVM_ENABLE_ASSERTIONS=OFF \
  46. -DPYTHON_EXECUTABLE=/usr/bin/python3 \
  47. -DLLVM_TOOL_LIBCXX_BUILD=ON \
  48. -DLLVM_ENABLE_BINDINGS=OFF \
  49. -DLLVM_ENABLE_LIBXML2=FORCE_ON \
  50. -DLLVM_LINK_LLVM_DYLIB=ON \
  51. -DCMAKE_RANLIB=$cctoolsdir/$target-ranlib \
  52. -DCMAKE_LIBTOOL=$cctoolsdir/$target-libtool \
  53. -DCMAKE_SYSTEM_NAME=Darwin \
  54. -DCMAKE_SYSTEM_VERSION=$MACOSX_DEPLOYMENT_TARGET \
  55. -DLLVM_ENABLE_THREADS=OFF \
  56. -DCOMPILER_RT_BUILD_XRAY=OFF \
  57. -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/clang-source/projects/libcxx/include \
  58. -DCMAKE_OSX_SYSROOT=$sysrootdir \
  59. -DCMAKE_FIND_ROOT_PATH=$sysrootdir \
  60. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
  61. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  62. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  63. -DCMAKE_MACOSX_RPATH=ON \
  64. -DCMAKE_OSX_ARCHITECTURES=$arch \
  65. -DDARWIN_macosx_OVERRIDE_SDK_VERSION=$MACOSX_DEPLOYMENT_TARGET \
  66. -DDARWIN_osx_ARCHS=$arch \
  67. -DDARWIN_osx_SYSROOT=$sysrootdir \
  68. -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin $builddir/clang-source/llvm
  69. ninja install -v
  70. popd
  71. mkdir build_compiler_rt
  72. pushd build_compiler_rt
  73. # And we build compiler-rt by following taskcluster/scripts/misc/build-compiler-rt.sh.
  74. cmake -GNinja \
  75. -DCMAKE_C_COMPILER=$clangdir/clang \
  76. -DCMAKE_CXX_COMPILER=$clangdir/clang++ \
  77. -DCMAKE_C_COMPILER_TARGET=$target \
  78. -DCMAKE_CXX_COMPILER_TARGET=$target \
  79. -DCMAKE_ASM_COMPILER_TARGET=$target \
  80. -DCMAKE_AR=$clangdir/llvm-ar \
  81. -DCMAKE_RANLIB=$clangdir/llvm-ranlib \
  82. -DCMAKE_C_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  83. -DCMAKE_CXX_FLAGS="-stdlib=libc++ [% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  84. -DCMAKE_ASM_FLAGS="[% c('var/FLAGS') %] -I$sysrootdir/usr/include -iframework $sysrootdir/System/Library/Frameworks" \
  85. -DCMAKE_EXE_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  86. -DCMAKE_SHARED_LINKER_FLAGS="[% c('var/LDFLAGS') %]" \
  87. -DCMAKE_BUILD_TYPE=Release \
  88. -DLLVM_ENABLE_ASSERTIONS=OFF \
  89. -DCMAKE_INSTALL_PREFIX=$distdir/clang/lib/clang/[% pc("clang", "version") %]/ \
  90. -DLLVM_CONFIG_PATH=$clangdir/llvm-config \
  91. -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
  92. -DCMAKE_LINKER=$cctoolsdir/$target-ld \
  93. -DCMAKE_LIPO=$cctoolsdir/lipo \
  94. -DCMAKE_SYSTEM_NAME=Darwin \
  95. -DCMAKE_SYSTEM_VERSION=$MACOSX_DEPLOYMENT_TARGET \
  96. -DDARWIN_macosx_OVERRIDE_SDK_VERSION=$MACOSX_DEPLOYMENT_TARGET \
  97. -DDARWIN_osx_ARCHS=$arch \
  98. -DDARWIN_osx_SYSROOT=$sysrootdir \
  99. -DDARWIN_osx_BUILTIN_ARCHS=$arch \
  100. -DCMAKE_OSX_SYSROOT=$sysrootdir \
  101. -DCMAKE_FIND_ROOT_PATH=$sysrootdir \
  102. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
  103. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  104. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  105. -DDARWIN_osx_BUILTIN_ARCHS=$arch \
  106. $builddir/clang-source/compiler-rt
  107. ninja install -v
  108. # We now have a native macosx64 toolchain.
  109. # What we want is a native linux64 toolchain which can target macosx64.
  110. # Overlay the linux64 toolchain that we used for this build. Note: we don't do
  111. # any ASan builds for macOS (yet). Once we do that we need to preserve at least
  112. # `llvm-symbolizer` as that one seems to get shipped with sanitizer builds (at
  113. # least that's what Mozilla claims).
  114. cd $distdir
  115. cp --remove-destination -lr /var/tmp/dist/clang/* clang/
  116. cd cctools/bin
  117. ln -s ../../clang/bin/clang x86_64-apple-darwin-clang
  118. ln -s ../../clang/bin/clang++ x86_64-apple-darwin-clang++
  119. cd /var/tmp/dist
  120. [% c('tar', {
  121. tar_src => [ project ],
  122. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  123. }) %]