yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4721b6ef2
master
1# PowerShell script to fetch, build, and install LLVM for Slang 2 3# Set script to fail on errors 4$ErrorActionPreference ="Stop" 5 6function Show-Help { 7Write-Host "Fetch, build and install LLVM for Slang 8 9Options: 10--repo: The source git repo, default: $repo 11--branch: The branch (or tag) to fetch, default: $branch 12--source-dir: Unpack and build in this directory: default $source_dir 13--config: The configuration to build, default $config 14--install-prefix: Install under this prefix 15--: Any following arguments will be passed to the CMake configuration command 16" 17} 18 19function Msg { 20Write-Host " $args " -ForegroundColor Yellow 21} 22 23function Fail { 24Msg " $args " 25exit 1 26} 27 28function New-TemporaryDirectory { 29$tmp = [System.IO.Path ]::GetTempPath ()# Not $env:TEMP, see https://stackoverflow.com/a/946017 30$name = (New-Guid ).ToString ("N" ) 31New-Item -ItemType Directory -Path (Join-Path $tmp $name ) 32} 33 34# Check if required programs are available 35$requiredPrograms ="cmake" ,"git" ,"ninja" 36foreach ($prog in$requiredPrograms ) { 37if (-not (Get-Command $prog -ErrorAction SilentlyContinue)) { 38Msg "This script needs $prog , but it isn't in PATH" 39$missingBin =$true 40 } 41} 42if ($missingBin ) { 43exit 1 44} 45 46# Temp directory with cleanup on exit 47$tempDir =New-TemporaryDirectory 48$cleanup = { 49if ($tempDir ) { 50Remove-Item -Recurse -Force$tempDir 51 } 52exit $lastExitCode 53} 54$null =Register-EngineEvent PowerShell.Exiting -Action$cleanup 55 56# Default values 57$repo ="https://github.com/llvm/llvm-project" 58$branch ="llvmorg-14.0.6" 59$sourceDir =$tempDir .FullName 60$installPrefix ="" 61$config ="Release" 62$extraArguments = @() 63 64# Argument parsing 65for ($i =0 ;$i -lt $args .Length ;$i ++) { 66switch ($args [$i ]) { 67 "--help" { 68Show-Help 69exit 70 } 71 "--repo" { 72$repo =$args [++$i ] 73 } 74 "--branch" { 75$branch =$args [++$i ] 76 } 77 "--source-dir" { 78$sourceDir =$args [++$i ] 79 } 80 "--config" { 81$config =$args [++$i ] 82 } 83 "--install-prefix" { 84$installPrefix =$args [++$i ] 85 } 86 "--" { 87$extraArguments =$args [$i + 1 .. $args .Length ] 88break 89 } 90 default { 91Msg "Unknown parameter passed: $( $args [ $i ])" 92Show-Help 93exit 1 94 } 95 } 96} 97 98if (-not $repo ) {Fail "please set --repo" } 99if (-not $branch ) {Fail "please set --branch" } 100if (-not $sourceDir ) {Fail "please set --source-dir" } 101if (-not $config ) {Fail "please set --config" } 102if (-not $installPrefix ) {Fail "please set --install-prefix" } 103 104# Fetch LLVM from the repo 105Msg "##########################################################" 106Msg "# Fetching LLVM from $repo at $branch " 107Msg "##########################################################" 108git clone --depth1 --branch$branch $repo $sourceDir 109 110# Configure LLVM with CMake 111Msg "##########################################################" 112Msg "# Configuring LLVM in $sourceDir " 113Msg "##########################################################" 114$msvcRuntimeLib ="MultiThreaded" 115if ($config -eq 'Debug' ) 116{ 117$msvcRuntimeLib ="MultiThreadedDebug" 118} 119$cmakeArgumentsForSlang = @( 120"-DLLVM_BUILD_LLVM_C_DYLIB=0" 121"-DLLVM_INCLUDE_BENCHMARKS=0" 122"-DLLVM_INCLUDE_DOCS=0" 123"-DLLVM_INCLUDE_EXAMPLES=0" 124"-DLLVM_INCLUDE_TESTS=0" 125"-DLLVM_ENABLE_TERMINFO=0" 126"-DCLANG_BUILD_TOOLS=0" 127"-DCLANG_ENABLE_STATIC_ANALYZER=0" 128"-DCLANG_ENABLE_ARCMT=0" 129"-DCLANG_INCLUDE_DOCS=0" 130"-DCLANG_INCLUDE_TESTS=0" 131"-DLLVM_ENABLE_PROJECTS=clang" 132"-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" 133"-DLLVM_BUILD_TOOLS=0" 134"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>" 135"-DLLVM_USE_CRT_RELEASE=MT" 136"-DLLVM_USE_CRT_DEBUG=MTd" 137) 138 139$buildDir =Join-Path $sourceDir "build" 140New-Item -Path$buildDir -ItemType Directory -Force 141$myScriptDir =Split-Path -Parent$MyInvocation .MyCommand .Path 142$toolchainFile =Join-Path $myScriptDir "WindowsToolchain\Windows.MSVC.toolchain.cmake" 143cmake -S$sourceDir \ llvm -B$buildDir $cmakeArgumentsForSlang + $extraArguments -G"Ninja" --toolchain$toolchainFile 144 145# Build LLVM 146Msg "##########################################################" 147Msg "# Building LLVM in $buildDir " 148Msg "##########################################################" 149cmake --build$buildDir -j --config$config 150 151# Install LLVM 152Msg "##########################################################" 153Msg "# Installing LLVM to $installPrefix " 154Msg "##########################################################" 155cmake --install$buildDir --prefix$installPrefix --config$config 156 157Msg "##########################################################" 158Msg "LLVM installed in $installPrefix " 159Msg "Please add $installPrefix to CMAKE_PREFIX_PATH" 160Msg "##########################################################"