-
Notifications
You must be signed in to change notification settings - Fork 240
/
Build.ps1
78 lines (61 loc) · 2.41 KB
/
Build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
param (
[string]$Version = "luajit",
[string]$BuildFromSource = "false"
)
$Build = [System.Convert]::ToBoolean($BuildFromSource)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$BuildDir = "build"
function Build-FromSource($feature) {
if (-not (Test-Path $BuildDir)) {
New-Item -ItemType Directory -Path $BuildDir | Out-Null
}
cargo build --release --features=$feature
$targetTokenizerFile = "avante_tokenizers.dll"
$targetTemplatesFile = "avante_templates.dll"
Copy-Item (Join-Path "target\release\avante_tokenizers.dll") (Join-Path $BuildDir $targetTokenizerFile)
Copy-Item (Join-Path "target\release\avante_templates.dll") (Join-Path $BuildDir $targetTemplatesFile)
Remove-Item -Recurse -Force "target"
}
function Download-Prebuilt($feature) {
$REPO_OWNER = "yetone"
$REPO_NAME = "avante.nvim"
$SCRIPT_DIR = $PSScriptRoot
# Set the target directory to clone the artifact
$TARGET_DIR = Join-Path $SCRIPT_DIR "build"
# Set the platform to Windows
$PLATFORM = "windows"
$ARCH = "x86_64"
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
$ARCH = "aarch64"
}
# Set the Lua version (lua51 or luajit)
$LUA_VERSION = if ($feature) { $feature } else { "luajit" }
# Set the artifact name pattern
$ARTIFACT_NAME_PATTERN = "avante_lib-$PLATFORM-$ARCH-$LUA_VERSION"
# Get the artifact download URL
$LATEST_RELEASE = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest"
$ARTIFACT_URL = $LATEST_RELEASE.assets | Where-Object { $_.name -like "*$ARTIFACT_NAME_PATTERN*" } | Select-Object -ExpandProperty browser_download_url
# Create target directory if it doesn't exist
if (-not (Test-Path $TARGET_DIR)) {
New-Item -ItemType Directory -Path $TARGET_DIR | Out-Null
}
# Download and extract the artifact
$TempFile = New-TemporaryFile | Rename-Item -NewName { $_.Name + ".zip" } -PassThru
Invoke-WebRequest -Uri $ARTIFACT_URL -OutFile $TempFile
Expand-Archive -Path $TempFile -DestinationPath $TARGET_DIR -Force
Remove-Item $TempFile
}
function Main {
Set-Location $PSScriptRoot
if ($Build) {
Write-Host "Building for $Version..."
Build-FromSource $Version
} else {
Write-Host "Downloading for $Version..."
Download-Prebuilt $Version
}
Write-Host "Completed!"
}
# Run the main function
Main