Skip to content

Commit

Permalink
checkpoint: into main from release/2.0.0 @ d7539b1 (Chia-Network#15878)
Browse files Browse the repository at this point in the history
Source hash: d7539b1
Remaining commits: 9
  • Loading branch information
wallentx authored Jul 27, 2023
2 parents 23058e6 + bd246a8 commit 13843bf
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 137 deletions.
174 changes: 112 additions & 62 deletions Install-plotter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,44 @@ param(

$ErrorActionPreference = "Stop"

$DEFAULT_BLADEBIT_VERSION = "v2.0.1"
$DEFAULT_MADMAX_VERSION = "0.0.2"
$VERSION = $v
$OS = "windows"
$ARCH = "x86-64"

if (("$plotter" -ne "bladebit") -And ("$plotter" -ne "madmax"))
{
Write-Output "Plotter must be 'bladebit' or 'madmax'"
Exit 1
}

function get_bladebit_filename()
# Check for necessary tools
if (!(Get-Command Invoke-WebRequest -errorAction SilentlyContinue)) {
Write-Output "ERROR: Invoke-WebRequest could not be found. Please ensure PowerShell is updated and try again."
Exit 1
}

if (!(Get-Command Expand-Archive -errorAction SilentlyContinue)) {
Write-Output "ERROR: Expand-Archive could not be found. Please ensure PowerShell is updated and try again."
Exit 1
}

if ($null -eq (Get-ChildItem env:VIRTUAL_ENV -ErrorAction SilentlyContinue))
{
Write-Output "This script requires that the Chia Python virtual environment is activated."
Write-Output "Execute '.\venv\Scripts\Activate.ps1' before running."
Exit 1
}

$venv_bin = "${env:VIRTUAL_ENV}\Scripts"
if (-not (Test-Path -Path "$venv_bin" -PathType Container))
{
Write-Output "ERROR: venv folder does not exists: '${venv_bin}'"
Exit 1
}

function Get-BladebitFilename()
{
param(
[string]$ver,
Expand All @@ -33,7 +64,33 @@ function get_bladebit_filename()
"bladebit-${ver}-${os}-${arch}.zip"
}

function get_bladebit_url()
function Get-BladebitCudaFilename()
{
param(
[string]$ver,
[string]$os,
[string]$arch
)

"bladebit-cuda-${ver}-${os}-${arch}.zip"
}


function Get-BladebitUrl()
{
param(
[string]$ver,
[string]$os,
[string]$arch
)

$GITHUB_BASE_URL = "https://github.com/Chia-Network/bladebit/releases/download"
$filename = Get-BladebitFilename -ver $ver -os $os -arch $arch

"${GITHUB_BASE_URL}/${ver}/${filename}"
}

function Get-BladebitCudaUrl()
{
param(
[string]$ver,
Expand All @@ -42,12 +99,12 @@ function get_bladebit_url()
)

$GITHUB_BASE_URL = "https://github.com/Chia-Network/bladebit/releases/download"
$filename = get_bladebit_filename -ver $ver -os $os -arch $arch
$filename = Get-BladebitCudaFilename -ver $ver -os $os -arch $arch

"${GITHUB_BASE_URL}/${ver}/${filename}"
}

function get_madmax_filename()
function Get-MadmaxFilename()
{
param(
[string]$ksize,
Expand Down Expand Up @@ -78,7 +135,7 @@ function get_madmax_filename()
"${chia_plot}-${ver}${suffix}"
}

function get_madmax_url()
function Get-MadmaxUrl()
{
param(
[string]$ksize,
Expand All @@ -88,30 +145,51 @@ function get_madmax_url()
)

$GITHUB_BASE_URL = "https://github.com/Chia-Network/chia-plotter-madmax/releases/download"
$madmax_filename = get_madmax_filename -ksize $ksize -ver $ver -os $os -arch $arch
$madmax_filename = Get-MadmaxFilename -ksize $ksize -ver $ver -os $os -arch $arch

"${GITHUB_BASE_URL}/${ver}/${madmax_filename}"
}

$DEFAULT_BLADEBIT_VERSION = "v2.0.0"
$DEFAULT_MADMAX_VERSION = "0.0.2"
$VERSION = $v
$OS = "windows"
$ARCH = "x86-64"
# Function to download, extract, set permissions, and clean up
function Get-Binary()
{
param(
[string]$url,
[string]$dest_dir,
[string]$new_filename
)

$filename = [System.IO.Path]::GetFileName($url)
$download_path = Join-Path -Path $PWD -ChildPath $filename
try {
Invoke-WebRequest -Uri $url -OutFile $download_path
} catch {
Write-Warning "Failed to download from ${url}. Maybe specified version of the binary does not exist."
return
}

if ($null -eq (Get-ChildItem env:VIRTUAL_ENV -ErrorAction SilentlyContinue))
{
Write-Output "This script requires that the Chia Python virtual environment is activated."
Write-Output "Execute '.\venv\Scripts\Activate.ps1' before running."
Exit 1
}
$extension = [System.IO.Path]::GetExtension($download_path)
if ($extension -eq '.zip') {
Expand-Archive -Path $download_path -DestinationPath $dest_dir -Force
Remove-Item -Path $download_path
} else {
Move-Item -Path $download_path -Destination (Join-Path -Path $dest_dir -ChildPath $filename) -Force
}

$venv_bin = "${env:VIRTUAL_ENV}\Scripts"
if (-not (Test-Path -Path "$venv_bin" -PathType Container))
{
Write-Output "ERROR: venv folder does not exists: '${venv_bin}'"
Exit 1
# Check if new_filename parameter is provided
if ($new_filename) {
# Construct the full paths to the old and new files
$old_file_path = Join-Path -Path $dest_dir -ChildPath $filename
$new_file_path = Join-Path -Path $dest_dir -ChildPath $new_filename
# If the new file already exists, delete it
if (Test-Path $new_file_path) {
Remove-Item -Path $new_file_path
}
# Rename the old file to the new filename
Rename-Item -Path $old_file_path -NewName $new_file_path
}

Write-Output "Successfully installed $filename to $dest_dir"
}

Push-Location
Expand All @@ -128,23 +206,13 @@ try {

Write-Output "Installing bladebit ${VERSION}"

$URL = get_bladebit_url -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -OutFile ".\bladebit.zip"
Write-Output "Successfully downloaded: $URL"
}
catch {
Write-Output "ERROR: Download failed. Maybe specified version of the binary does not exist."
Pop-Location
Exit 1
}
$url = Get-BladebitUrl -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir

Expand-Archive -Path ".\bladebit.zip" -DestinationPath ".\bladebit"
Move-Item .\bladebit\bladebit.exe .\ -Force
Remove-Item bladebit -Force
Remove-Item bladebit.zip -Force
Write-Output "Successfully installed bladebit to $(Get-Location)\bladebit.exe"
$url = Get-BladebitCudaUrl -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir
}
elseif("${plotter}" -eq "madmax")
{
Expand All @@ -155,31 +223,13 @@ try {

Write-Output "Installing madmax ${VERSION}"

$madmax_filename = get_madmax_filename -ksize k32 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
$URL = get_madmax_url -ksize k32 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -Outfile "chia_plot.exe"
Write-Output "Successfully downloaded: $URL"
Write-Output "Successfully installed madmax to $(Get-Location)\chia_plot.exe"
}
catch {
Write-Output "ERROR: Download failed. Maybe specified version of the binary does not exist."
Pop-Location
Exit 1
}
$url = Get-MadmaxUrl -ksize "k32" -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir -new_filename "chia_plot_k32.exe"

$madmax_filename = get_madmax_filename -ksize k34 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
$URL = get_madmax_url -ksize k34 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -Outfile "chia_plot_k34.exe"
Write-Output "Successfully downloaded: $URL"
Write-Output "Successfully installed madmax for k34 to $(Get-Location)\chia_plot_k34.exe"
}
catch {
Write-Output "madmax for k34 is not found"
}
$url = Get-MadmaxUrl -ksize "k34" -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir -new_filename "chia_plot_k34.exe"
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions chia/pyinstaller.spec
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ if os.path.exists(f"{ROOT}/bladebit/bladebit"):
)
])

if os.path.exists(f"{ROOT}/bladebit/bladebit_cuda"):
binaries.extend([
(
f"{ROOT}/bladebit/bladebit_cuda",
"bladebit"
)
])

if THIS_IS_WINDOWS:
chia_mod = importlib.import_module("chia")
dll_paths = pathlib.Path(sysconfig.get_path("platlib")) / "*.dll"
Expand Down Expand Up @@ -131,6 +139,10 @@ if THIS_IS_WINDOWS:
f"{ROOT}\\bladebit\\bladebit.exe",
"bladebit"
),
(
f"{ROOT}\\bladebit\\bladebit_cuda.exe",
"bladebit"
),
]


Expand Down
Loading

0 comments on commit 13843bf

Please sign in to comment.