Skip to content

Commit

Permalink
Add build-coredistools.cmd build-coredistools.sh build-tblgen.cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
echesakov committed Sep 17, 2020
1 parent b6e1253 commit 381a9b2
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
66 changes: 66 additions & 0 deletions build-coredistools.cmd
Original file line number Diff line number Diff line change
@@ -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
87 changes: 87 additions & 0 deletions build-coredistools.sh
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions build-tblgen.cmd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 381a9b2

Please sign in to comment.