Skip to content

Instantly share code, notes, and snippets.

@shopglobal
Forked from tgerring/geth-posh-build.ps1
Created February 5, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shopglobal/35d5fe5dd6d9d4ccca975ed2131de9a6 to your computer and use it in GitHub Desktop.
Save shopglobal/35d5fe5dd6d9d4ccca975ed2131de9a6 to your computer and use it in GitHub Desktop.
Geth build script for Windows Powershell
<#
.SYNOPSIS
Geth build script for Windows
.DESCRIPTION
A Powershell script to install dependencies for Windows and build go-ethereum binaries.
Make sure to run `Set-ExecutionPolicy RemoteSigned` in an Adminisrative Powershell window first
if you intend to run this as a script instead of in a console
.NOTES
File Name : geth-posh-install.ps1
Author : Taylor Gerring (taylor.gerring@gmail.com)
Prerequisite : PowerShell V3
Copyright 2015 - Ethereum
#>
<##############################################
Customize options here
###############################################>
$vergeth = "v1.2.2"
$vergo = "1.5.1"
$vermsys = "20150916"
<##############################################
Probably nothing needs to be modified below
###############################################>
Function InstallMsys2($vermsys)
{
# Set directories
$downloaddir = $env:TEMP
$url = "http://repo.msys2.org/distrib/$arch/msys2-$arch-$vermsys.exe"
$url2 = "https://raw.githubusercontent.com/Alexpux/MSYS2-packages/master/msys2-installer/auto-install.js"
# Determine type of system
if ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$arch = "x86_64"
$archpath = "msys64"
} else {
$arch = "i686"
$archpath = "msys32"
}
$msys2path = "C:\$archpath" # BUG This is not currently used by the install script
$url = "http://repo.msys2.org/distrib/$arch/msys2-$arch-$vermsys.exe"
$url2 = "https://raw.githubusercontent.com/Alexpux/MSYS2-packages/master/msys2-installer/auto-install.js"
# Download and install
Invoke-WebRequest $url -UseBasicParsing -OutFile "$downloaddir\msys2-setup.exe"
Invoke-WebRequest $url2 -UseBasicParsing -OutFile "$downloaddir\auto-install.js"
#$clnt = new-object System.Net.WebClient
#$clnt.DownloadFile($url,"$downloaddir\msys2-setup.exe")
#$clnt.DownloadFile($url2, "$downloaddir\auto-install.js")
cd $downloaddir
.\msys2-setup.exe --script auto-install.js -v --platform minimal # This does not wait for exit and pollutes console output
$env:PATH = "$msys2path\usr\bin;$env:PATH"
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "User")
#
# Because we cannot be sure that msys2-setup.exe is done installing, postpone dependency installation until build
#
}
Function InstallGo ($vergo)
{
# Set directories
$basedir = $env:USERPROFILE
$golangroot = "$basedir\golang"
$gosrcroot = "$basedir\go"
$downloaddir = $env:TEMP
# Determine type of system
if ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$arch = "amd64"
} else {
$arch = "386"
}
# Download and extract
$golangdl = -Join("https://storage.googleapis.com/golang/go", $vergo, ".windows-", $arch, ".zip")
Invoke-WebRequest $golangdl -UseBasicParsing -OutFile "$downloaddir\golang.zip"
#$clnt.DownloadFile($golangdl,"$downloaddir\golang.zip")
#$clnt = new-object System.Net.WebClient
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory("$downloaddir\golang.zip", $golangroot)
#unzip .\golang.zip -d $golangroot
# Set environment variables
$env:GOROOT = "$golangroot\go"
$env:GOPATH = $gosrcroot
$env:PATH = "$env:PATH;$golangroot\go\bin;$gosrcroot\bin"
[Environment]::SetEnvironmentVariable("GOROOT", $env:GOROOT, "User")
[Environment]::SetEnvironmentVariable("GOPATH", $env:GOPATH, "User")
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "User")
}
Function InstallDeps ($msys2path)
{
# Determine type of system
if ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {
$arch = "x86_64"
$archpath = "mingw64"
} else {
$arch = "i686"
$archpath = "mingw32"
}
# Install dependencies
pacman --noconfirm -S unzip git gcc gmp-devel mingw-w64-$arch-gcc
# Path order is very important. Must use gcc from mingw64 not mysys2
$env:PATH = "$msys2path\$archpath\bin;$env:PATH"
}
Function BuildGeth ($vergeth)
{
$packagepath = "github.com/ethereum/go-ethereum"
# Download source
go get github.com/tools/godep
mkdir -p $env:GOPATH\src\$packagepath
git clone https://$packagepath $env:GOPATH\src\$packagepath
# Build
cd $env:GOPATH/src/$packagepath
git checkout $vergeth
git pull
godep go install .\cmd\geth
}
# Install POSIX tools
InstallMsys2($vermsys)
# Install Go
InstallGo($vergo)
# Install late deps
InstallDeps("C:\msys64")
# Download and build
BuildGeth($vergeth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment