Files
tailscale/tool/go.cmd
Aaron Klotz 02f6030dbd tool, tool/gocross: update gocross to support building natively on Windows and add a PowerShell Core wrapper script
gocross-wrapper.ps1 is a PowerShell core script that is essentially a
straight port of gocross-wrapper.sh. It requires PowerShell 7.4, which
is the latest LTS release of PSCore.

Why use PowerShell Core instead of Windows PowerShell? Essentially
because the former is much better to script with and is the edition
that is currently maintained.

Because we're using PowerShell Core, but many people will be running
scripts from a machine that only has Windows PowerShell, go.cmd has
been updated to prompt the user for PowerShell core installation if
necessary.

gocross-wrapper.sh has also been updated to utilize the PSCore script
when running under cygwin or msys.

gocross itself required a couple of updates:

We update gocross to output the PowerShell Core wrapper alongside the
bash wrapper, which will propagate the revised scripts to other repos
as necessary.

We also fix a couple of things in gocross that didn't work on Windows:
we change the toolchain resolution code to use os.UserHomeDir instead
of directly referencing the HOME environment variable, and we fix a
bug in the way arguments were being passed into exec.Command on
non-Unix systems.

Updates https://github.com/tailscale/corp/issues/29940

Signed-off-by: Aaron Klotz <aaron@tailscale.com>
2025-08-18 09:49:24 -06:00

37 lines
1.6 KiB
Batchfile

@echo off
rem Checking for PowerShell Core using PowerShell for Windows...
powershell -NoProfile -NonInteractive -Command "& {Get-Command -Name pwsh -ErrorAction Stop}" > NUL
if ERRORLEVEL 1 (
rem Ask the user whether they should install the dependencies. Note that this
rem code path never runs in CI because pwsh is always explicitly installed.
rem Time out after 5 minutes, defaulting to 'N'
choice /c yn /t 300 /d n /m "PowerShell Core is required. Install now"
if ERRORLEVEL 2 (
echo Aborting due to unmet dependencies.
exit /b 1
)
rem Check for a .NET Core runtime using PowerShell for Windows...
powershell -NoProfile -NonInteractive -Command "& {if (-not (dotnet --list-runtimes | Select-String 'Microsoft\.NETCore\.App' -Quiet)) {exit 1}}" > NUL
rem Install .NET Core if missing to provide PowerShell Core's runtime library.
if ERRORLEVEL 1 (
rem Time out after 5 minutes, defaulting to 'N'
choice /c yn /t 300 /d n /m "PowerShell Core requires .NET Core for its runtime library. Install now"
if ERRORLEVEL 2 (
echo Aborting due to unmet dependencies.
exit /b 1
)
winget install --accept-package-agreements --id Microsoft.DotNet.Runtime.8 -e --source winget
)
rem Now install PowerShell Core.
winget install --accept-package-agreements --id Microsoft.PowerShell -e --source winget
if ERRORLEVEL 0 echo Please re-run this script within a new console session to pick up PATH changes.
rem Either way we didn't build, so return 1.
exit /b 1
)
pwsh -NoProfile -ExecutionPolicy Bypass "%~dp0..\tool\gocross\gocross-wrapper.ps1" %*