1bf215546Sopenharmony_ci
2bf215546Sopenharmony_ci$MyPath = $MyInvocation.MyCommand.Path | Split-Path -Parent
3bf215546Sopenharmony_ci. "$MyPath\mesa_vs_init.ps1"
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ci# we want more secure TLS 1.2 for most things, but it breaks SourceForge
6bf215546Sopenharmony_ci# downloads so must be done after Chocolatey use
7bf215546Sopenharmony_ci[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13;
8bf215546Sopenharmony_ci
9bf215546Sopenharmony_ciRemove-Item -Recurse -Force -ErrorAction SilentlyContinue "deps" | Out-Null
10bf215546Sopenharmony_ci
11bf215546Sopenharmony_ciGet-Date
12bf215546Sopenharmony_ciWrite-Host "Cloning LLVM release/12.x"
13bf215546Sopenharmony_cigit clone -b release/12.x --depth=1 https://github.com/llvm/llvm-project deps/llvm-project
14bf215546Sopenharmony_ciif (!$?) {
15bf215546Sopenharmony_ci  Write-Host "Failed to clone LLVM repository"
16bf215546Sopenharmony_ci  Exit 1
17bf215546Sopenharmony_ci}
18bf215546Sopenharmony_ci
19bf215546Sopenharmony_ci# ideally we want to use a tag here insted of a sha,
20bf215546Sopenharmony_ci# but as of today, SPIRV-LLVM-Translator doesn't have
21bf215546Sopenharmony_ci# a tag matching LLVM 12.0.0
22bf215546Sopenharmony_ciGet-Date
23bf215546Sopenharmony_ciWrite-Host "Cloning SPIRV-LLVM-Translator"
24bf215546Sopenharmony_cigit clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator deps/llvm-project/llvm/projects/SPIRV-LLVM-Translator
25bf215546Sopenharmony_ciif (!$?) {
26bf215546Sopenharmony_ci  Write-Host "Failed to clone SPIRV-LLVM-Translator repository"
27bf215546Sopenharmony_ci  Exit 1
28bf215546Sopenharmony_ci}
29bf215546Sopenharmony_ciPush-Location deps/llvm-project/llvm/projects/SPIRV-LLVM-Translator
30bf215546Sopenharmony_cigit checkout 5b641633b3bcc3251a52260eee11db13a79d7258
31bf215546Sopenharmony_ciPop-Location
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci$depsInstallPath="C:\mesa-deps"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ciGet-Date
36bf215546Sopenharmony_ci# slightly convoluted syntax but avoids the CWD being under the PS filesystem meta-path
37bf215546Sopenharmony_ci$llvm_build = New-Item -ItemType Directory -ErrorAction SilentlyContinue -Force -Path ".\deps\llvm-project" -Name "build"
38bf215546Sopenharmony_ciPush-Location -Path $llvm_build.FullName
39bf215546Sopenharmony_ciWrite-Host "Compiling LLVM and Clang"
40bf215546Sopenharmony_cicmake ../llvm `
41bf215546Sopenharmony_ci-GNinja `
42bf215546Sopenharmony_ci-DCMAKE_BUILD_TYPE=Release `
43bf215546Sopenharmony_ci-DLLVM_USE_CRT_RELEASE=MT `
44bf215546Sopenharmony_ci-DCMAKE_PREFIX_PATH="$depsInstallPath" `
45bf215546Sopenharmony_ci-DCMAKE_INSTALL_PREFIX="$depsInstallPath" `
46bf215546Sopenharmony_ci-DLLVM_ENABLE_PROJECTS="clang" `
47bf215546Sopenharmony_ci-DLLVM_TARGETS_TO_BUILD="AMDGPU;X86" `
48bf215546Sopenharmony_ci-DLLVM_OPTIMIZED_TABLEGEN=TRUE `
49bf215546Sopenharmony_ci-DLLVM_ENABLE_ASSERTIONS=TRUE `
50bf215546Sopenharmony_ci-DLLVM_INCLUDE_UTILS=OFF `
51bf215546Sopenharmony_ci-DLLVM_INCLUDE_RUNTIMES=OFF `
52bf215546Sopenharmony_ci-DLLVM_INCLUDE_TESTS=OFF `
53bf215546Sopenharmony_ci-DLLVM_INCLUDE_EXAMPLES=OFF `
54bf215546Sopenharmony_ci-DLLVM_INCLUDE_GO_TESTS=OFF `
55bf215546Sopenharmony_ci-DLLVM_INCLUDE_BENCHMARKS=OFF `
56bf215546Sopenharmony_ci-DLLVM_BUILD_LLVM_C_DYLIB=OFF `
57bf215546Sopenharmony_ci-DLLVM_ENABLE_DIA_SDK=OFF `
58bf215546Sopenharmony_ci-DCLANG_BUILD_TOOLS=ON `
59bf215546Sopenharmony_ci-DLLVM_SPIRV_INCLUDE_TESTS=OFF `
60bf215546Sopenharmony_ci-Wno-dev && `
61bf215546Sopenharmony_cininja -j32 install
62bf215546Sopenharmony_ci$buildstatus = $?
63bf215546Sopenharmony_ciPop-Location
64bf215546Sopenharmony_ciif (!$buildstatus) {
65bf215546Sopenharmony_ci  Write-Host "Failed to compile LLVM"
66bf215546Sopenharmony_ci  Exit 1
67bf215546Sopenharmony_ci}
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ciGet-Date
70bf215546Sopenharmony_ci$libclc_build = New-Item -ItemType Directory -Path ".\deps\llvm-project" -Name "build-libclc"
71bf215546Sopenharmony_ciPush-Location -Path $libclc_build.FullName
72bf215546Sopenharmony_ciWrite-Host "Compiling libclc"
73bf215546Sopenharmony_ci# libclc can only be built with Ninja, because CMake's VS backend doesn't know how to compile new language types
74bf215546Sopenharmony_cicmake ../libclc `
75bf215546Sopenharmony_ci-GNinja `
76bf215546Sopenharmony_ci-DCMAKE_BUILD_TYPE=Release `
77bf215546Sopenharmony_ci-DCMAKE_CXX_FLAGS="-m64" `
78bf215546Sopenharmony_ci-DCMAKE_POLICY_DEFAULT_CMP0091=NEW `
79bf215546Sopenharmony_ci-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded `
80bf215546Sopenharmony_ci-DCMAKE_INSTALL_PREFIX="$depsInstallPath" `
81bf215546Sopenharmony_ci-DLIBCLC_TARGETS_TO_BUILD="spirv-mesa3d-;spirv64-mesa3d-" && `
82bf215546Sopenharmony_cininja -j32 install
83bf215546Sopenharmony_ci$buildstatus = $?
84bf215546Sopenharmony_ciPop-Location
85bf215546Sopenharmony_ciRemove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path $libclc_build
86bf215546Sopenharmony_ciif (!$buildstatus) {
87bf215546Sopenharmony_ci  Write-Host "Failed to compile libclc"
88bf215546Sopenharmony_ci  Exit 1
89bf215546Sopenharmony_ci}
90bf215546Sopenharmony_ciRemove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path $llvm_build
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ciGet-Date
93bf215546Sopenharmony_ciWrite-Host "Cloning SPIRV-Tools"
94bf215546Sopenharmony_cigit clone -b "sdk-$env:VULKAN_SDK_VERSION" --depth=1 https://github.com/KhronosGroup/SPIRV-Tools deps/SPIRV-Tools
95bf215546Sopenharmony_ciif (!$?) {
96bf215546Sopenharmony_ci  Write-Host "Failed to clone SPIRV-Tools repository"
97bf215546Sopenharmony_ci  Exit 1
98bf215546Sopenharmony_ci}
99bf215546Sopenharmony_cigit clone -b "sdk-$env:VULKAN_SDK_VERSION" --depth=1 https://github.com/KhronosGroup/SPIRV-Headers deps/SPIRV-Tools/external/SPIRV-Headers
100bf215546Sopenharmony_ciif (!$?) {
101bf215546Sopenharmony_ci  Write-Host "Failed to clone SPIRV-Headers repository"
102bf215546Sopenharmony_ci  Exit 1
103bf215546Sopenharmony_ci}
104bf215546Sopenharmony_ciWrite-Host "Building SPIRV-Tools"
105bf215546Sopenharmony_ci$spv_build = New-Item -ItemType Directory -Path ".\deps\SPIRV-Tools" -Name "build"
106bf215546Sopenharmony_ciPush-Location -Path $spv_build.FullName
107bf215546Sopenharmony_ci# SPIRV-Tools doesn't use multi-threaded MSVCRT, but we need it to
108bf215546Sopenharmony_cicmake .. `
109bf215546Sopenharmony_ci-GNinja `
110bf215546Sopenharmony_ci-DCMAKE_BUILD_TYPE=Release `
111bf215546Sopenharmony_ci-DCMAKE_POLICY_DEFAULT_CMP0091=NEW `
112bf215546Sopenharmony_ci-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded `
113bf215546Sopenharmony_ci-DCMAKE_INSTALL_PREFIX="$depsInstallPath" && `
114bf215546Sopenharmony_cininja -j32 install
115bf215546Sopenharmony_ci$buildstatus = $?
116bf215546Sopenharmony_ciPop-Location
117bf215546Sopenharmony_ciRemove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path $spv_build
118bf215546Sopenharmony_ciif (!$buildstatus) {
119bf215546Sopenharmony_ci  Write-Host "Failed to compile SPIRV-Tools"
120bf215546Sopenharmony_ci  Exit 1
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cifunction Remove-Symlinks {
124bf215546Sopenharmony_ci  Get-ChildItem -Force -ErrorAction SilentlyContinue @Args | Where-Object { if($_.Attributes -match "ReparsePoint"){$_.Delete()} }
125bf215546Sopenharmony_ci}
126bf215546Sopenharmony_ciRemove-Symlinks -Path "deps" -Recurse
127bf215546Sopenharmony_ciRemove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path "deps" | Out-Null
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ciGet-Date
130bf215546Sopenharmony_ciWrite-Host "Complete"
131