diff --git a/scripts/build-llvm/build.ps1 b/scripts/build-llvm/build.ps1 new file mode 100755 index 000000000..62277b859 --- /dev/null +++ b/scripts/build-llvm/build.ps1 @@ -0,0 +1,69 @@ +$LLVM_VERSION = $args[0] +$LLVM_REPO_URL = $args[1] + +if ([string]::IsNullOrEmpty($LLVM_REPO_URL)) { + $LLVM_REPO_URL = "https://github.com/llvm/llvm-project.git" +} + +if ([string]::IsNullOrEmpty($LLVM_VERSION)) { + Write-Output "Usage: $PSCommandPath " + Write-Output "" + Write-Output "# Arguments" + Write-Output " llvm-version The name of a LLVM release branch without the 'release/' prefix" + Write-Output " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)" + + exit 1 +} + +# Clone the LLVM project. +if (-not (Test-Path -Path "llvm-project" -PathType Container)) { + git clone "$LLVM_REPO_URL" llvm-project +} + +Set-Location llvm-project +git fetch origin +git checkout "release/$LLVM_VERSION" +git reset --hard origin/"release/$LLVM_VERSION" + +# Create a directory to build the project. +New-Item -Path "build" -Force -ItemType "directory" +Set-Location build + +# Create a directory to receive the complete installation. +New-Item -Path "install" -Force -ItemType "directory" + +# Adjust compilation based on the OS. +$CMAKE_ARGUMENTS = "" + +# Adjust cross compilation +$CROSS_COMPILE = "" + +# Run `cmake` to configure the project. +cmake ` + -G "Visual Studio 16 2019" ` + -DCMAKE_BUILD_TYPE=MinSizeRel ` + -DCMAKE_INSTALL_PREFIX=destdir ` + -DLLVM_ENABLE_PROJECTS="clang;lld" ` + -DLLVM_ENABLE_TERMINFO=OFF ` + -DLLVM_ENABLE_ZLIB=OFF ` + -DLLVM_INCLUDE_DOCS=OFF ` + -DLLVM_INCLUDE_EXAMPLES=OFF ` + -DLLVM_INCLUDE_GO_TESTS=OFF ` + -DLLVM_INCLUDE_TESTS=OFF ` + -DLLVM_INCLUDE_TOOLS=ON ` + -DLLVM_INCLUDE_UTILS=OFF ` + -DLLVM_OPTIMIZED_TABLEGEN=ON ` + -DLLVM_TARGETS_TO_BUILD="X86;AArch64" ` + $CROSS_COMPILE ` + $CMAKE_ARGUMENTS ` + ../llvm + +# Showtime! +cmake --build . --config Release + +# Not using DESTDIR here, quote from +# https://cmake.org/cmake/help/latest/envvar/DESTDIR.html +# > `DESTDIR` may not be used on Windows because installation prefix +# > usually contains a drive letter like in `C:/Program Files` which cannot +# > be prepended with some other prefix. +cmake --install . --strip --config Release diff --git a/scripts/build-llvm/build.sh b/scripts/build-llvm/build.sh new file mode 100755 index 000000000..56f05da22 --- /dev/null +++ b/scripts/build-llvm/build.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Display all commands before executing them. +set -o errexit +set -o errtrace + +LLVM_VERSION=$1 +LLVM_REPO_URL=${2:-https://github.com/llvm/llvm-project.git} +LLVM_CROSS="$3" + +if [[ -z "$LLVM_REPO_URL" || -z "$LLVM_VERSION" ]] +then + echo "Usage: $0 [aarch64]" + echo + echo "# Arguments" + echo " llvm-version The name of a LLVM release branch without the 'release/' prefix" + echo " llvm-repository-url The URL used to clone LLVM sources (default: https://github.com/llvm/llvm-project.git)" + echo " aarch64 To cross-compile an aarch64 version of LLVM" + + exit 1 +fi + +# Clone the LLVM project. +if [ ! -d llvm-project ] +then + git clone "$LLVM_REPO_URL" llvm-project +fi + + +cd llvm-project +git fetch origin +git checkout "release/$LLVM_VERSION" +git reset --hard origin/"release/$LLVM_VERSION" + +# Create a directory to build the project. +mkdir -p build +cd build + +# Create a directory to receive the complete installation. +mkdir -p install + +# Adjust compilation based on the OS. +CMAKE_ARGUMENTS="" + +case "${OSTYPE}" in + darwin*) ;; + linux*) ;; + *) ;; +esac + +# Adjust cross compilation +CROSS_COMPILE="" + +case "${LLVM_CROSS}" in + aarch64*) CROSS_COMPILE="-DLLVM_HOST_TRIPLE=aarch64-linux-gnu" ;; + *) ;; +esac + +# Run `cmake` to configure the project. +cmake \ + -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=MinSizeRel \ + -DCMAKE_INSTALL_PREFIX="/" \ + -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_ZLIB=OFF \ + -DLLVM_INCLUDE_DOCS=OFF \ + -DLLVM_INCLUDE_EXAMPLES=OFF \ + -DLLVM_INCLUDE_GO_TESTS=OFF \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_TOOLS=ON \ + -DLLVM_INCLUDE_UTILS=OFF \ + -DLLVM_OPTIMIZED_TABLEGEN=ON \ + -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \ + "${CROSS_COMPILE}" \ + "${CMAKE_ARGUMENTS}" \ + ../llvm + +# Showtime! +cmake --build . --config MinSizeRel +DESTDIR=destdir cmake --install . --strip --config MinSizeRel + +# move usr/bin/* to bin/ or llvm-config will be broken +mv destdir/usr/bin/* destdir/bin/