Skip to content

Instantly share code, notes, and snippets.

@reiver-dev
Created May 3, 2025 22:03
Show Gist options
  • Save reiver-dev/79c998c1bc00d0c61772e15694de1c69 to your computer and use it in GitHub Desktop.
Save reiver-dev/79c998c1bc00d0c61772e15694de1c69 to your computer and use it in GitHub Desktop.
# Build neovim
Function Find-Command {
[CmdletBinding()]
Param (
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Locations
)
ForEach ($Loc In $Locations) {
$result = Get-Command -Name $Loc `
-CommandType Application `
-ErrorAction Ignore
If ($result -NE $null) {
Return $result
}
}
}
Function VisualStudioEnv {
$vswhere = Find-Command vswhere "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
$VS = (& $vswhere -format json -products "*" | ConvertFrom-Json)[0].installationPath
$cmdline = "`"$VS\Common7\Tools\VsDevCmd.bat`" -arch=amd64 -host_arch=amd64 -no_logo > NUL & set"
$result = [ordered]@{}
ForEach ($line in (& cmd /D /C $cmdline)) {
if ($line -match "^(\S*?)\s*=\s*(.*)$") {
$result[$matches[1]] = $matches[2]
}
}
Write-Output $result
}
Function Set-Env {
Param(
[string]$Key,
[string]$Value
)
Write-Information -MessageData "Set-Env: $Key = $Value" -InformationAction Continue
Set-Item -Force -Path "env:$($Key)" -Value $Value
}
(VisualStudioEnv).GetEnumerator() | ForEach-Object {
Set-Env $_.Key $_.Value
}
$cmake = Find-Command cmake "$ENV:USERPROFILE\.local\opt\cmake\bin\cmake.exe"
# Clean
Remove-Item -Recurse -Force .deps -ErrorAction Ignore
Remove-Item -Recurse -Force .build -ErrorAction Ignore
Remove-Item -Recurse -Force .dist -ErrorAction Ignore
# Dependencies
& $cmake -S cmake.deps -B .deps -G Ninja -DCMAKE_BUILD_TYPE=Release -DUSE_BUNDLED=ON
& $cmake --build '.deps' --config Release --parallel $ENV:NUMBER_OF_PROCESSORS
# App
& $cmake -S '.' -B '.build' -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$ENV:USERPROFILE\.local\opt\nvim"
& $cmake --build '.build' --config Release --target install --parallel $ENV:NUMBER_OF_PROCESSORS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment