forked from devashishdxt/ring
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall-build-tools.ps1
67 lines (63 loc) · 2.33 KB
/
install-build-tools.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function Verify-Or-Delete-File {
param (
[Parameter(Mandatory)]
[string]$File,
[Parameter(Mandatory)]
[string]$ExpectedDigest
)
$ActualDigest = ( Get-FileHash -Algorithm SHA256 $File ).Hash
if ( $ActualDigest -eq $ExpectedDigest )
{
return
}
rm $File
echo "Digest verification failed for $Url; actual $ActualDigest, expected $ExpectedDigest"
exit 1
}
function Download-Zip-and-Extract-File {
param (
[Parameter(Mandatory)]
[string]$Uri,
[Parameter(Mandatory)]
[string]$ZipExpectedDigest,
[Parameter(Mandatory)]
[string]$PathWithinZip,
[Parameter(Mandatory)]
[string]$FileExpectedDigest,
[Parameter(Mandatory)]
[string]$OutFile
)
$TmpZip = New-TemporaryFile
Invoke-WebRequest -Uri $Uri -OutFile $TmpZip.FullName
echo $TmpZip
Verify-Or-Delete-File -File $TmpZip.FullName -ExpectedDigest $ZipExpectedDigest
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::OpenRead($TmpZip)
$zip.Entries |
Where-Object { $_.FullName -eq $PathWithinZip } |
ForEach-Object {
$TmpFile = New-TemporaryFile
# extract the selected items from the ZIP archive
# and copy them to the out folder
$FileName = $_.Name
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$TmpFile", $true)
Verify-Or-Delete-File -File $TmpFile -ExpectedDigest $FileExpectedDigest
Move-Item -Force $TmpFile $OutFile
}
$zip.Dispose()
}
$tools_dir = "target/tools"
mkdir -Force $tools_dir
# This is the file BoringSSL refers to in
# https://boringssl.googlesource.com/boringssl/+/26f8297177ad8033cc39de84afe9c2000430a66d.
$nasm_version = "nasm-2.13.03"
$nasm_zip = "$nasm_version-win64.zip"
$nasm_zip_sha256 = "B3A1F896B53D07854884C2E0D6BE7DEFBA7EBD09B864BBB9E6D69ADA1C3E989F"
$nasm_exe = "nasm.exe"
$nasm_exe_sha256 = "D8A933BF5CC3597C56193135CB78B225AB225E1F611D2FDB51EF6E3F555B21E3"
Download-Zip-and-Extract-File `
-Uri "https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/$nasm_zip" `
-ZipExpectedDigest "$nasm_zip_sha256" `
-PathWithinZip "$nasm_version/$nasm_exe" `
-FileExpectedDigest "$nasm_exe_sha256" `
-OutFile "$tools_dir/$nasm_exe"