-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# This script downloads the `cargo-marker` and the `marker_rustc_driver` | ||
# binaries from the GitHub release assets. It also sets up the required | ||
# Rust toolchain that the `marker_rustc_driver` depends on. | ||
# | ||
# This script must be self-contained! Nothing here should use anything from | ||
# the marker repository, because users are expected to run this script on | ||
# their machines where they don't have the marker repository cloned. | ||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
# This script isn't meant to be run from `master`, but if it is, then | ||
# it will install the latest version be it a stable version or a pre-release. | ||
# region replace-version unstable | ||
$version = "0.2.1" | ||
# endregion replace-version unstable | ||
|
||
$toolchain = "nightly-2023-08-24" | ||
|
||
function With-Log { | ||
Write-Output "> $($args -join ' ')" | ||
|
||
$cmd = $args[0] | ||
$rest = $args[1..$args.Length] | ||
|
||
& $cmd @rest | ||
} | ||
|
||
function Extract-TarGz { | ||
param ( | ||
[string]$bin, | ||
[string]$dest | ||
) | ||
$file_stem = "${bin}-${host_triple}" | ||
|
||
|
||
With-Log cd $temp_dir | ||
|
||
Check-Sha256Sum $file_stem "tar.gz" | ||
|
||
With-Log tar$exe --extract --file (Join-Path $temp_dir "$file_stem.tar.gz") --directory $dest | ||
} | ||
|
||
# There isn't mktemp on Windows, so we have to reinvent the wheel. | ||
function New-TemporaryDirectory { | ||
$parent = [System.IO.Path]::GetTempPath() | ||
[string] $name = [System.Guid]::NewGuid() | ||
New-Item -ItemType Directory -Path (Join-Path $parent $name) | ||
} | ||
|
||
# There isn't sha256sum on Windows, so we have to reinvent the wheel. | ||
function Check-Sha256Sum { | ||
param ( | ||
[string]$file_stem, | ||
[string]$extension | ||
) | ||
|
||
$file = "$file_stem.$extension" | ||
|
||
$actual = Get-FileHash -Algorithm SHA256 -Path $file | ||
$expected = Get-Content "$file_stem.sha256" | ||
|
||
foreach ($line in $expected) { | ||
$line -match '(\S+)\s*\*?(.*)' | ||
$expected_hash = $Matches[1] | ||
$expected_file = $Matches[2] | ||
|
||
if ($expected_file -ne $file) { | ||
continue | ||
} | ||
|
||
if ($actual.Hash -eq $expected_hash) { | ||
Write-Output "${file}: OK" | ||
return | ||
} | ||
|
||
throw "Checksum verification failed for $file. Expected: $expected_hash, actual: $actual" | ||
} | ||
|
||
throw "No checksum found for $file" | ||
} | ||
|
||
# Set this to `.exe` if on Windows, otherwise leave it empty. | ||
# Yes! This script can run on unix too if you have PowerShell installed there. | ||
# | ||
# Btw. this is written specically so that it can run on PowerShell 5, which is | ||
# installed by default on Windows 10 and 11. In PowerShell 7 there are automatic | ||
# variables `$IsWindows`, `$IsMacOS`, `$IsLinux`. | ||
$exe = if ([System.Environment]::OSVersion.Platform -eq "Win32NT") { | ||
".exe" | ||
} else { | ||
"" | ||
} | ||
|
||
With-Log rustup install --profile minimal --no-self-update $toolchain | ||
|
||
$host_triple = ( | ||
rustc +$toolchain --version --verbose ` | ||
| Select-String -Pattern "host: (.*)" ` | ||
| ForEach-Object { $_.Matches.Groups[1].Value } | ||
) | ||
|
||
$current_dir = (Get-Location).Path | ||
$temp_dir = New-TemporaryDirectory | ||
|
||
try { | ||
$files = "{cargo-marker,marker_rustc_driver}-$host_triple.{tar.gz,sha256}" | ||
|
||
# Curl is available by default on windows, yay! | ||
# https://curl.se/windows/microsoft.html | ||
# | ||
# Download all files using a single TCP connection with HTTP2 multiplexing | ||
With-Log curl$exe ` | ||
--location ` | ||
--silent ` | ||
--fail ` | ||
--show-error ` | ||
--retry 5 ` | ||
--retry-connrefused ` | ||
--remote-name ` | ||
--output-dir $temp_dir ` | ||
"https://github.com/rust-marker/marker/releases/download/v$version/$files" | ||
|
||
# There is a null coalescing operator in PowerShell 7, but that version | ||
# seems to be rather too cutting edge. At least on my Windows 11 laptop | ||
# the version of PowerShell is 5.1 | ||
$cargo_home = if ($env:CARGO_HOME) { | ||
$env:CARGO_HOME | ||
} else { | ||
Join-Path $HOME ".cargo" | ||
} | ||
|
||
Extract-TarGz "cargo-marker" (Join-Path $cargo_home "bin") | ||
|
||
$sysroot = (rustc +$toolchain --print sysroot) | ||
Extract-TarGz "marker_rustc_driver" (Join-Path $sysroot "bin") | ||
} finally { | ||
Write-Output "Removing the temp directory $temp_dir" | ||
|
||
# Go back to the original directory before removing the temp directory | ||
# otherwise it will fail because the temporary directory is in use. | ||
cd $current_dir | ||
|
||
Remove-Item -Force -Recurse $temp_dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ files=($(\ | |
-o -name "*.md" \ | ||
-o -name "*.toml" \ | ||
-o -name "*.sh" \ | ||
-o -name "*.ps1" \ | ||
\)\ | ||
)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters