tj / gobinaries

Golang binaries compiled on-demand for your system
https://gobinaries.com/
MIT License
811 stars 31 forks source link

Windows support #2

Open tj opened 4 years ago

tj commented 4 years ago

I don't think it works right now, probably need to chuck an .exe on there at least.

msenturk commented 4 years ago

This did the trick on msys64:

Summary: Total: 2.5021 secs Slowest: 1.0606 secs Fastest: 0.3316 secs Average: 0.4985 secs Requests/sec: 3.9967 ...

tj commented 4 years ago

@msenturk interesting! thanks :D

axetroy commented 4 years ago

Maybe generating a .ps1 file and processing it by PowerShell can do this

iwr https://gobinaries.com/rakyll/hey?ps1=1 -useb | iex
axetroy commented 3 years ago

@tj

Here is an example for Windows installation.

iwr https://deno.land/x/install/install.ps1 -useb | iex

https://deno.land/x/install@v0.1.2/install.ps1

I think it can be used in Golang with a little modification

The user does not need to install other additional tools.

mniak commented 3 years ago

Here is an adaptation I made for powershell taking inspiration in the Deno installation script as in @axetroy comment. It is not complete (ie. it does not support linux or macos), but for my scenario (windows/amd64) it works.

#!/usr/bin/env pwsh

function Log-Info($message) {
    Write-Output "`e[38;5;61m  ==>`e[0;00m $message"
}
function Log-Critical($message) {
    [Console]::Error.WriteLine("")
    [Console]::Error.WriteLine("  `e[38;5;125m$message`e[0;00m")
    [Console]::Error.WriteLine("")
}
function Get-OS() {
    if ($IsWindows) {
        return "windows"
    } else {
        Log-Critical("Operating system not supported yet")
        Exit 0
    }
    return "unknown"
}
function Get-Architecture() {
    return "$env:PROCESSOR_ARCHITECTURE".ToLower()
}

$OS = Get-OS
$Arch = Get-Architecture

# API endpoint such as "http://localhost:3000"
$API = "https://gobinaries.com"

# package such as "github.com/tj/triage/cmd/triage"
$Pkg = "github.com/rakyll/hey"

# binary name such as "hello"
$Bin ="hey"

# original_version such as "master"
$OriginalVersion="master"

# version such as "master"
$Version="v0.1.4"

$GoBinariesDir = $env:GOBINARIES_DIR
$BinDir = If ($GoBinariesDir) {
  "$GoBinariesDir\bin"
} else {
  "$Home\.gobinaries\bin"
}

$TempExe = "$env:TEMP\$Bin.exe"
$TargetExe = "$BinDir\$Bin.exe" 

If ($OriginalVersion -ne $Version) {
    Log-Info("Resolved version $OriginalVersion to $Version")
}

# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Log-Info("Downloading binary for $OS $arch")
$DownloadUrl = "${API}/binary/${Pkg}?os=${OS}&arch=${Arch}&version=${Version}"
Invoke-WebRequest $DownloadUrl -OutFile $TempExe -UseBasicParsing

If (!(Test-Path $BinDir)) {
  New-Item $BinDir -ItemType Directory | Out-Null
}

Copy-Item -Path $TempExe -Destination $TargetExe

If (Test-Path $TempExe) {
    Remove-Item $TempExe
}

$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
If (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
  [Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
  $Env:Path += ";$BinDir"
}

Log-Info("Installation complete")
mniak commented 3 years ago

Since this issue seems stall, I created a demo pull request (#40) with my embrionary script (above)