1 <# 2 .Description 3 The script installs binaries needed to build and run crosvm, including rust toolchain and protoc, 4 in User's temp directory and sets up system environment variables. 5 .PARAMETER BASE_DIR 6 Determines where the binaries will be installed. This defaults to user's temp directory. 7 #> 8 param ( 9 [Parameter( 10 Position = 0 11 )] 12 [string]$BASE_DIR = $Env:TEMP ## 13 ) 14 15 $BASE_DIR = $BASE_DIR + "\" 16 $PROTOC_VERSION = '21.12' 17 $PROTOC_SHA256 = "71852A30CF62975358EDFCBBFF93086E8857A079C8E4D6904881AA968D65C7F9" 18 $PROTOC_URL = "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-win64.zip" 19 $PROTOC_ZIP = $BASE_DIR + 'protoc.zip' 20 $PROTOC_DIR = $BASE_DIR + 'protoc\' 21 22 23 $RUSTUP_INIT_VERSION = '1.25.1' 24 $RUSTUP_INIT_SHA256 = "2220DDB49FEA0E0945B1B5913E33D66BD223A67F19FD1C116BE0318DE7ED9D9C" 25 $RUSTUP_INIT_URL = "https://static.rust-lang.org/rustup/archive/$RUSTUP_INIT_VERSION/x86_64-pc-windows-msvc/rustup-init.exe" 26 $RUSTUP_INIT = $BASE_DIR + 'rustup-init.exe' 27 28 $CARGO_BINSTALL_VERSION = 'v0.19.3' 29 $CARGO_BINSTALL_URL = "https://github.com/cargo-bins/cargo-binstall/releases/download/$CARGO_BINSTALL_VERSION/cargo-binstall-x86_64-pc-windows-msvc.zip" 30 31 Write-Host "Installing in $BASE_DIR" 32 33 if (!(Test-Path $BASE_DIR -PathType Container)) { 34 New-Item -ItemType Directory -Force -Path $BASE_DIR 35 } 36 37 Set-Location $BASE_DIR 38 39 # Install protobuf compiler 40 Invoke-WebRequest $PROTOC_URL -Out $PROTOC_ZIP 41 Write-Host "Verifying protoc integrity" 42 if ((Get-FileHash $PROTOC_ZIP -Algorithm SHA256).Hash -ne $PROTOC_SHA256) 43 { 44 Write-Host "$PROTOC_ZIP sha did not match" 45 Break 46 } 47 Expand-Archive -Path $PROTOC_ZIP -DestinationPath $PROTOC_DIR 48 $Env:PATH = $Env:PATH + ";" + $PROTOC_DIR + "bin\" 49 50 # Update PATH to contain protobuf and depot_tools directory 51 [Environment]::SetEnvironmentVariable("Path", $Env:PATH, [System.EnvironmentVariableTarget]::User) 52 53 # Download rustup-init that helps setting up rustup and rust toolchain. 54 # Install protobuf compiler 55 Invoke-WebRequest $RUSTUP_INIT_URL -Out $RUSTUP_INIT 56 Write-Host "Verifying rustup_init integrity" 57 if ((Get-FileHash $RUSTUP_INIT -Algorithm SHA256).Hash -ne $RUSTUP_INIT_SHA256) 58 { 59 Write-Host "$RUSTUP_INIT sha did not match" 60 Break 61 } 62 63 # Install rustup and rust toolchain 64 & $RUSTUP_INIT 65 66 # Update PATH to to contain cargo home directory. 67 [Environment]::SetEnvironmentVariable("Path", $Env:PATH, [System.EnvironmentVariableTarget]::User) 68 69 # Cargo extension to install binary packages from github 70 $BINSTALL_ZIP = New-TemporaryFile 71 Invoke-WebRequest $CARGO_BINSTALL_URL -Out $BINSTALL_ZIP 72 $BINSTALL_DEST=((Get-Command cargo) | Get-Item).DirectoryName 73 Expand-Archive -Path $BINSTALL_ZIP -DestinationPath $BINSTALL_DEST 74 75 # Nextest is an improved test runner for cargo 76 cargo binstall --no-confirm cargo-nextest --version "0.9.49" 77 78