From 616c5eafee3f9ddabe1d9c59248a0a6fdbe7796f Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Fri, 20 Sep 2024 16:58:56 -0700 Subject: [PATCH] CI: win arm adjustments (#6898) --- .github/workflows/release.yaml | 2 ++ scripts/build_windows.ps1 | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8fbe475f4..82d4a28a2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -291,6 +291,7 @@ jobs: iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) choco install -y --no-progress git gzip echo "C:\Program Files\Git\cmd" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\ProgramData\chocolatey\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Install Visual Studio 2022 run: | $components = @( @@ -389,6 +390,7 @@ jobs: $env:CMAKE_SYSTEM_VERSION="10.0.22621.0" $env:PATH="$gopath;$gccpath;$env:PATH;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin" echo $env:PATH + $env:ARCH="arm64" .\scripts\build_windows.ps1 buildOllama buildApp gatherDependencies distZip name: 'Windows Build' - uses: actions/upload-artifact@v4 diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1 index ff74a5003..b9508341e 100644 --- a/scripts/build_windows.ps1 +++ b/scripts/build_windows.ps1 @@ -7,7 +7,17 @@ $ErrorActionPreference = "Stop" function checkEnv() { - $script:ARCH = (([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture).ToString().ToLower()).Replace("x64", "amd64") + if ($null -ne $env:ARCH ) { + $script:ARCH = $env:ARCH + } else { + $arch=([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) + if ($null -ne $arch) { + $script:ARCH = ($arch.ToString().ToLower()).Replace("x64", "amd64") + } else { + write-host "WARNING: old powershell detected, assuming amd64 architecture - set `$env:ARCH to override" + $script:ARCH="amd64" + } + } $script:TARGET_ARCH=$script:ARCH Write-host "Building for ${script:TARGET_ARCH}" write-host "Locating required tools and paths" @@ -70,7 +80,6 @@ function checkEnv() { function buildOllama() { - write-host "Building ollama CLI" if ($null -eq ${env:OLLAMA_SKIP_GENERATE}) { Remove-Item -ea 0 -recurse -force -path "${script:SRC_DIR}\dist\windows-${script:ARCH}" @@ -78,15 +87,16 @@ function buildOllama() { # which targets to build # Start by skipping CUDA to build everything else - pwsh -Command { $env:OLLAMA_SKIP_CUDA_GENERATE="1"; & go generate ./... } + write-host "Building ollama runners" + powershell -Command { $env:OLLAMA_SKIP_CUDA_GENERATE="1"; & go generate ./... } if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} # Then skip everyhting else and build all the CUDA variants foreach ($env:CUDA_LIB_DIR in $script:CUDA_DIRS) { - write-host "Building CUDA ${env:CUDA_LIB_DIR}" + write-host "Building CUDA ${env:CUDA_LIB_DIR} runner" if ($env:CUDA_LIB_DIR.Contains("v12")) { - pwsh -Command { + powershell -Command { $env:OLLAMA_SKIP_CUDA_GENERATE="" $env:OLLAMA_SKIP_STATIC_GENERATE="1" $env:OLLAMA_SKIP_CPU_GENERATE="1" @@ -99,7 +109,7 @@ function buildOllama() { & go generate ./... } } else { - pwsh -Command { + powershell -Command { $env:OLLAMA_SKIP_CUDA_GENERATE="" $env:OLLAMA_SKIP_STATIC_GENERATE="1" $env:OLLAMA_SKIP_CPU_GENERATE="1" @@ -118,6 +128,7 @@ function buildOllama() { } else { write-host "Skipping generate step with OLLAMA_SKIP_GENERATE set" } + write-host "Building ollama CLI" & go build -trimpath -ldflags "-s -w -X=github.com/ollama/ollama/version.Version=$script:VERSION -X=github.com/ollama/ollama/server.mode=release" . if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} if ("${env:KEY_CONTAINER}") { @@ -137,7 +148,7 @@ function buildApp() { if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} if ("${env:KEY_CONTAINER}") { & "${script:SignTool}" sign /v /fd sha256 /t http://timestamp.digicert.com /f "${script:OLLAMA_CERT}" ` - /csp "Google Cloud KMS Provider" /kc ${env:KEY_CONTAINER} app.exe + /csp "Google Cloud KMS Provider" /kc ${env:KEY_CONTAINER} "${script:SRC_DIR}\dist\windows-${script:TARGET_ARCH}-app.exe" if ($LASTEXITCODE -ne 0) { exit($LASTEXITCODE)} } }