From 381a9b28c07e98925b21772b619f7d216c5415d5 Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Thu, 17 Sep 2020 14:12:41 -0700 Subject: [PATCH] Add build-coredistools.cmd build-coredistools.sh build-tblgen.cmd --- build-coredistools.cmd | 66 ++++++++++++++++++++++++++++++++ build-coredistools.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ build-tblgen.cmd | 45 ++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 build-coredistools.cmd create mode 100755 build-coredistools.sh create mode 100644 build-tblgen.cmd diff --git a/build-coredistools.cmd b/build-coredistools.cmd new file mode 100644 index 00000000..64a473ef --- /dev/null +++ b/build-coredistools.cmd @@ -0,0 +1,66 @@ +@echo off +setlocal + +set RootDirectory=%~dp0 +set SourcesDirectory=%RootDirectory%src +set BinariesDirectory=%RootDirectory%obj +set TargetOSArchitecture=%1 + +if /i "%TargetOSArchitecture%" == "windows-arm" ( + set GeneratorPlatform=ARM +) else if /i "%TargetOSArchitecture%" == "windows-arm64" ( + set GeneratorPlatform=ARM64 +) else if /i "%TargetOSArchitecture%" == "windows-x64" ( + set GeneratorPlatform=x64 +) else if /i "%TargetOSArchitecture%" == "windows-x86" ( + set GeneratorPlatform=Win32 +) else ( + echo "Unknown target OS and architecture: %TargetOSArchitecture%" + exit /b 1 +) + +where /q llvm-tblgen.exe + +if %ERRORLEVEL% neq 0 ( + echo llvm-tblgen.exe is not found in the PATH + exit /b 1 +) + +for /f %%I in ('where llvm-tblgen.exe') do ( + set LLVMTableGen=%%~I +) + +if not exist "%BinariesDirectory%" ( + mkdir "%BinariesDirectory%" +) + +pushd "%BinariesDirectory%" + +cmake.exe ^ + -G "Visual Studio 16 2019" ^ + -A %GeneratorPlatform% ^ + -DCMAKE_INSTALL_PREFIX="%RootDirectory%\" ^ + -DLLVM_EXTERNAL_PROJECTS=coredistools ^ + -DLLVM_EXTERNAL_COREDISTOOLS_SOURCE_DIR="%SourcesDirectory%\coredistools" ^ + -DLLVM_TABLEGEN="%LLVMTableGen%" ^ + -DLLVM_TARGETS_TO_BUILD=AArch64;ARM;X86 ^ + -DLLVM_TOOL_COREDISTOOLS_BUILD=ON ^ + "%SourcesDirectory%\llvm-project\llvm" + +popd + +cmake.exe ^ + --build "%BinariesDirectory%" ^ + --target coredistools ^ + --config Release + +if %ERRORLEVEL% neq 0 ( + echo coredistools compilation has failed + exit /b 1 +) + +cmake.exe ^ + --install "%BinariesDirectory%" ^ + --component coredistools + +exit /b 0 diff --git a/build-coredistools.sh b/build-coredistools.sh new file mode 100755 index 00000000..2760d21c --- /dev/null +++ b/build-coredistools.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +RootDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +SourcesDirectory=$RootDirectory/src +BinariesDirectory=$RootDirectory/obj +TargetOSArchitecture=$1 +CrossRootfsDirectory=$2 + +case "$TargetOSArchitecture" in + linux-arm) + CrossCompiling=1 + TargetTriple=arm-linux-gnueabihf + ;; + + linux-arm64) + CrossCompiling=1 + TargetTriple=aarch64-linux-gnu + ;; + + linux-x64|macos-x64) + CrossCompiling=0 + ;; + + *) + echo "Unknown target OS and architecture: $TargetOSArchitecture" + exit 1 +esac + +if [[ $CrossCompiling -eq 1 && ! -d $CrossRootfsDirectory ]]; then + echo "Invalid or unspecified CrossRootfsDirectory: $CrossRootfsDirectory" + exit 1 +fi + +if [ ! -d $BinariesDirectory ]; then + mkdir -p $BinariesDirectory +fi + +pushd "$BinariesDirectory" + +if [ "$CrossCompiling" -eq 1 ]; then + cmake \ + -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CROSSCOMPILING=ON \ + -DCMAKE_C_COMPILER=$(which clang) \ + -DCMAKE_C_FLAGS="-target $TargetTriple --sysroot=$CrossRootfsDirectory" \ + -DCMAKE_CXX_COMPILER=$(which clang++) \ + -DCMAKE_CXX_FLAGS="-target $TargetTriple --sysroot=$CrossRootfsDirectory" \ + -DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \ + -DCMAKE_INSTALL_PREFIX=$RootDirectory \ + -DCMAKE_LIBRARY_PATH=$CrossRootfsDirectory/usr/lib/$TargetTriple \ + -DLLVM_EXTERNAL_PROJECTS=coredistools \ + -DLLVM_EXTERNAL_COREDISTOOLS_SOURCE_DIR=$SourcesDirectory/coredistools \ + -DLLVM_HOST_TRIPLE=$TargetTriple \ + -DLLVM_TABLEGEN=$(which llvm-tblgen) \ + -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \ + -DLLVM_TOOL_COREDISTOOLS_BUILD=ON \ + $SourcesDirectory/llvm-project/llvm +else + cmake \ + -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=$(which clang) \ + -DCMAKE_CXX_COMPILER=$(which clang++) \ + -DCMAKE_INSTALL_PREFIX=$RootDirectory \ + -DLLVM_EXTERNAL_PROJECTS=coredistools \ + -DLLVM_EXTERNAL_COREDISTOOLS_SOURCE_DIR=$SourcesDirectory/coredistools \ + -DLLVM_TABLEGEN=$(which llvm-tblgen) \ + -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \ + -DLLVM_TOOL_COREDISTOOLS_BUILD=ON \ + $SourcesDirectory/llvm-project/llvm +fi + +popd + +cmake \ + --build $BinariesDirectory \ + --target coredistools + +if [ "$?" -ne 0 ]; then + echo "coredistools compilation has failed" + exit 1 +fi + +cmake \ + --install $BinariesDirectory \ + --component coredistools diff --git a/build-tblgen.cmd b/build-tblgen.cmd new file mode 100644 index 00000000..500d1217 --- /dev/null +++ b/build-tblgen.cmd @@ -0,0 +1,45 @@ +@echo off +setlocal + +set RootDirectory=%~dp0 +set SourcesDirectory=%RootDirectory%src +set BinariesDirectory=%RootDirectory%obj +set StagingDirectory=%RootDirectory%bin + +if not exist "%BinariesDirectory%" ( + mkdir "%BinariesDirectory%" +) + +pushd "%BinariesDirectory%" + +cmake.exe ^ + -G "Visual Studio 16 2019" ^ + -DCMAKE_INSTALL_PREFIX="%RootDirectory%\" ^ + -DLLVM_TARGETS_TO_BUILD=AArch64;ARM;X86 ^ + "%SourcesDirectory%\llvm-project\llvm" + +popd + +cmake.exe ^ + --build %BinariesDirectory% ^ + --target llvm-tblgen ^ + --config Release + +if %ERRORLEVEL% neq 0 ( + echo llvm-tblgen compilation has failed + exit /b 1 +) + +if not exist "%StagingDirectory%" ( + mkdir "%StagingDirectory%" +) + +for /r "%BinariesDirectory%" %%I in (llvm-tblgen.ex?) do ( + if "%%~nxI" == "llvm-tblgen.exe" ( + xcopy "%%~I" "%StagingDirectory%" + exit /b 0 + ) +) + +echo llvm-tblgen.exe is not found in "%BinariesDirectory%" +exit /b 1