From 43846cf31356ba364a25a9eaf1d95881a101e917 Mon Sep 17 00:00:00 2001 From: Daniel McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Fri, 20 Apr 2018 13:30:59 -0700 Subject: [PATCH] add scripts to build new llvm package 6.0.0 (now with lld!) --- .../llvm/linux/x86_64/6.0.0/build-cmake.sh | 67 +++++++++ .../6.0.0/build-llvm-for-linux-with-cmake.sh | 25 ++++ .../bin/llvm/linux/x86_64/6.0.0/build-llvm.sh | 129 ++++++++++++++++++ .../bin/llvm/linux/x86_64/6.0.0/build.sh | 7 + build-support/bin/llvm/mac/10.10 | 1 + build-support/bin/llvm/mac/10.11 | 1 + build-support/bin/llvm/mac/10.12 | 1 + .../bin/llvm/mac/10.13/6.0.0/build-llvm.sh | 129 ++++++++++++++++++ .../bin/llvm/mac/10.13/6.0.0/build.sh | 5 + build-support/bin/llvm/mac/10.8 | 1 + build-support/bin/llvm/mac/10.9 | 1 + 11 files changed, 367 insertions(+) create mode 100755 build-support/bin/llvm/linux/x86_64/6.0.0/build-cmake.sh create mode 100755 build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm-for-linux-with-cmake.sh create mode 100755 build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm.sh create mode 100755 build-support/bin/llvm/linux/x86_64/6.0.0/build.sh create mode 120000 build-support/bin/llvm/mac/10.10 create mode 120000 build-support/bin/llvm/mac/10.11 create mode 120000 build-support/bin/llvm/mac/10.12 create mode 100755 build-support/bin/llvm/mac/10.13/6.0.0/build-llvm.sh create mode 100755 build-support/bin/llvm/mac/10.13/6.0.0/build.sh create mode 120000 build-support/bin/llvm/mac/10.8 create mode 120000 build-support/bin/llvm/mac/10.9 diff --git a/build-support/bin/llvm/linux/x86_64/6.0.0/build-cmake.sh b/build-support/bin/llvm/linux/x86_64/6.0.0/build-cmake.sh new file mode 100755 index 0000000..5e239e6 --- /dev/null +++ b/build-support/bin/llvm/linux/x86_64/6.0.0/build-cmake.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +source "$(git rev-parse --show-toplevel)/utils.v1.bash" + +set_strict_mode + +readonly CMAKE_VERSION_PATTERN='^([0-9]+\.[0-9]+)\.[0-9]+$' + +function extract_minor_version { + local -r version_string="$1" + + echo "$version_string" | sed -re "s#${CMAKE_VERSION_PATTERN}#\\1#g" +} + +function fetch_extract_cmake_binary_release { + local -r extracted_dirname="$1" + + local -r cmake_minor_version="$(extract_minor_version "$CMAKE_VERSION")" + + local -r archive_filename="${extracted_dirname}.tar.gz" + local -r release_url="https://cmake.org/files/v${cmake_minor_version}/${archive_filename}" + + local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")" + extract_for "$downloaded_archive" "$extracted_dirname" +} + +function package_cmake { + local -r installed_dir_abs="$1" + + with_pushd "$installed_dir_abs" \ + create_gz_package 'cmake' bin share +} + +function build_osx { + local -r cmake_platform_description="cmake-${CMAKE_VERSION}-Darwin-x86_64" + + local -r extracted_dir="$(fetch_extract_cmake_binary_release "$cmake_platform_description")" + + package_cmake "${extracted_dir}/CMake.app/Contents" +} + +function build_linux { + local -r cmake_platform_description="cmake-${CMAKE_VERSION}-Linux-x86_64" + + local -r extracted_dir="$(fetch_extract_cmake_binary_release "$cmake_platform_description")" + + package_cmake "$extracted_dir" +} + + +## Interpret arguments and execute build. + +readonly TARGET_PLATFORM="$1" CMAKE_VERSION="$2" + +case "$TARGET_PLATFORM" in + osx) + with_pushd "$(mkdirp_absolute_path "cmake-${CMAKE_VERSION}-osx")" \ + build_osx + ;; + linux) + with_pushd "$(mkdirp_absolute_path "cmake-${CMAKE_VERSION}-linux")" \ + build_linux + ;; + *) + die "cmake does not support building for '${TARGET_PLATFORM}'" + ;; +esac diff --git a/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm-for-linux-with-cmake.sh b/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm-for-linux-with-cmake.sh new file mode 100755 index 0000000..e1e026d --- /dev/null +++ b/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm-for-linux-with-cmake.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +source "$(git rev-parse --show-toplevel)/utils.v1.bash" + +set_strict_mode + +readonly CMAKE_VERSION_FOR_LLVM='3.9.5' + +function build_cmake_for_llvm_bootstrap { + local -r cmake_linux_archive_abs="$(./build-cmake.sh linux "$CMAKE_VERSION_FOR_LLVM")" + + local -r workdir='cmake-for-linux-packages' + + with_pushd "$(mkdirp_absolute_path "$workdir")" \ + extract_for "$cmake_linux_archive_abs" 'bin/cmake' +} + +function package_llvm { + local -r llvm_version="$1" + local -r cmake_linux_bin="$(build_cmake_for_llvm_bootstrap)" + + CMAKE_EXE="$cmake_linux_bin" ./build-llvm.sh linux "$llvm_version" +} + +package_llvm "$1" diff --git a/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm.sh b/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm.sh new file mode 100755 index 0000000..b530924 --- /dev/null +++ b/build-support/bin/llvm/linux/x86_64/6.0.0/build-llvm.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +source "$(git rev-parse --show-toplevel)/utils.v1.bash" + +set_strict_mode + +function package_llvm { + local -r installed_dir_abs="$1" + + with_pushd "$installed_dir_abs" \ + create_gz_package 'llvm' +} + +## Build for OSX from LLVM's binary release package. + +function build_osx { + + local -r normal_release_dirname="clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin" + # The top-level directory in the release archive is not always the same across + # releases. The `-final-` part may be to signify that this is the last release + # of that major version. + local -r final_release_dirname="clang+llvm-${LLVM_VERSION}-final-x86_64-apple-darwin" + + local -r archive_filename="${normal_release_dirname}.tar.xz" + local -r release_url="https://releases.llvm.org/${LLVM_VERSION}/${archive_filename}" + + local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")" + local -r extracted_dir="$(extract_for "$downloaded_archive" "$normal_release_dirname" "$final_release_dirname")" + + package_llvm "$extracted_dir" +} + + +## Build for Linux from LLVM's multi-part source release packages. + +function fetch_extract_llvm_source_release { + local -r extracted_dirname="$1" + + local -r archive_filename="${extracted_dirname}.tar.xz" + local -r release_url="https://releases.llvm.org/${LLVM_VERSION}/${archive_filename}" + + local -r downloaded_archive="$(curl_file_with_fail "$release_url" "$archive_filename")" + extract_for "$downloaded_archive" "$extracted_dirname" +} + +function build_llvm_with_cmake { + local -r cmake_exe="$1" install_dir="$2" llvm_dir="$3" cfe_dir="$4" lld_dir="$5" + + # This didn't immediately compile right off the bat -- I'd recommend to anyone + # watching that Homebrew formulas are good places to learn about how to provide + # high-quality toolchains on OSX. I found https://llvm.org/docs/CMake.html + # "helpful" for this line as well. + "$cmake_exe" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$install_dir_abs" \ + -DLLVM_EXTERNAL_CLANG_SOURCE_DIR="$cfe_dir" \ + -DLLVM_EXTERNAL_LLD_SOURCE_DIR="$lld_dir" \ + -DLLVM_EXTERNAL_PROJECTS='clang;lld' \ + -DLLVM_TARGETS_TO_BUILD='X86' \ + -DBACKEND_PACKAGE_STRING="Pants-packaged LLVM for ${TARGET_PLATFORM}, version ${LLVM_VERSION}" \ + "$llvm_dir" + + # NB: There appear to be race conditions when running make with any + # parallelism here in a Docker image. + make "-j${MAKE_JOBS}" + + make install +} + +function build_linux { + local -r cmake_exe="$1" + + # Properties of the downloaded release tarball. + local -r llvm_src_dirname="llvm-${LLVM_VERSION}.src" + local -r cfe_src_dirname="cfe-${LLVM_VERSION}.src" + local -r lld_src_dirname="lld-${LLVM_VERSION}.src" + + # Set up an out-of-tree build and install + local -r build_dir_abs="$(mkdirp_absolute_path 'clang-llvm-build')" + local -r install_dir_abs="$(mkdirp_absolute_path 'clang-llvm-install')" + + # LLVM requires you to download the source for LLVM and external projects + # (e.g. clang and lld) separately. One alternative is checking out their SVN + # repo and then check out individual subdirs, or using the git repo, but those + # both take much longer and are otherwise the same. + local -r llvm_src_extracted_abs="$(fetch_extract_llvm_source_release "$llvm_src_dirname")" + local -r cfe_src_extracted_abs="$(fetch_extract_llvm_source_release "$cfe_src_dirname")" + local -r lld_src_extracted_abs="$(fetch_extract_llvm_source_release "$lld_src_dirname")" + + # Redirect to stderr because we "return" a path to our .tar.gz by stdout. + with_pushd >&2 "$build_dir_abs" \ + build_llvm_with_cmake "$cmake_exe" "$install_dir_abs" \ + "$llvm_src_extracted_abs" \ + "$cfe_src_extracted_abs" \ + "$lld_src_extracted_abs" + + package_llvm "$install_dir_abs" +} + +function validate_cmake { + if [[ ! -f "$CMAKE_EXE" ]]; then + die_here <&2 "$build_dir_abs" \ + build_llvm_with_cmake "$cmake_exe" "$install_dir_abs" \ + "$llvm_src_extracted_abs" \ + "$cfe_src_extracted_abs" \ + "$lld_src_extracted_abs" + + package_llvm "$install_dir_abs" +} + +function validate_cmake { + if [[ ! -f "$CMAKE_EXE" ]]; then + die_here <