Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,183 @@ jobs:
run: |
set -euo pipefail
./build/ctrace -h

build-windows:
name: Build on Windows (pinned LLVM 20.1.0)
runs-on: windows-2022

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Resolve dependency ref
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$ref = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
"DEPENDENCY_REF=$ref" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Checkout coretrace-compiler matching ref
id: checkout_compiler_ref
continue-on-error: true
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-compiler
ref: ${{ env.DEPENDENCY_REF }}
path: deps/coretrace-compiler
fetch-depth: 1

- name: Checkout coretrace-compiler main fallback
if: steps.checkout_compiler_ref.outcome == 'failure'
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-compiler
ref: main
path: deps/coretrace-compiler
fetch-depth: 1

- name: Checkout coretrace-stack-analyzer matching ref
id: checkout_stack_ref
continue-on-error: true
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-stack-analyzer
ref: ${{ env.DEPENDENCY_REF }}
path: deps/coretrace-stack-analyzer
fetch-depth: 1

- name: Checkout coretrace-stack-analyzer main fallback
if: steps.checkout_stack_ref.outcome == 'failure'
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-stack-analyzer
ref: main
path: deps/coretrace-stack-analyzer
fetch-depth: 1

- name: Checkout coretrace-log matching ref
id: checkout_logger_ref
continue-on-error: true
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-log
ref: ${{ env.DEPENDENCY_REF }}
path: deps/coretrace-log
fetch-depth: 1

- name: Checkout coretrace-log main fallback
if: steps.checkout_logger_ref.outcome == 'failure'
uses: actions/checkout@v4
with:
repository: CoreTrace/coretrace-log
ref: main
path: deps/coretrace-log
fetch-depth: 1

- name: Install LLVM 20.1.0 archive with 7-Zip
shell: pwsh
run: |
$ErrorActionPreference = "Stop"

$llvmVersion = "20.1.0"
$archiveName = "clang+llvm-$llvmVersion-x86_64-pc-windows-msvc.tar.xz"
$archiveUrl = "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvmVersion/$archiveName"
$archivePath = Join-Path $env:RUNNER_TEMP $archiveName
$extractRoot = Join-Path $env:RUNNER_TEMP "llvm-extract"
$installRoot = "C:\Program Files\LLVM-$llvmVersion"
$sevenZip = "${env:ProgramFiles}\7-Zip\7z.exe"
$tarPath = Join-Path $env:RUNNER_TEMP "clang+llvm-$llvmVersion-x86_64-pc-windows-msvc.tar"

if (-not (Test-Path $sevenZip)) {
throw "7z.exe not found at $sevenZip"
}

Write-Host "Downloading LLVM archive from $archiveUrl"
Invoke-WebRequest -Uri $archiveUrl -OutFile $archivePath
Write-Host "Download finished"
Get-Item $archivePath | Select-Object FullName, Length | Format-Table -AutoSize

if (Test-Path $extractRoot) {
Remove-Item -Recurse -Force $extractRoot
}
New-Item -ItemType Directory -Force -Path $extractRoot | Out-Null

if (Test-Path $tarPath) {
Remove-Item -Force $tarPath
}

Write-Host "Extracting .xz to .tar with 7-Zip"
& $sevenZip x $archivePath "-o$env:RUNNER_TEMP" -y
if ($LASTEXITCODE -ne 0) {
throw "7-Zip failed while extracting .xz archive"
}

if (-not (Test-Path $tarPath)) {
throw "Expected tar file not found after xz extraction: $tarPath"
}

Write-Host "Extracting .tar to $extractRoot"
& $sevenZip x $tarPath "-o$extractRoot" -y
if ($LASTEXITCODE -ne 0) {
throw "7-Zip failed while extracting .tar archive"
}

Write-Host "Listing extracted directories"
Get-ChildItem $extractRoot -Directory | Select-Object Name, FullName | Format-Table -AutoSize

$extractedDir = Get-ChildItem $extractRoot -Directory | Select-Object -First 1
if (-not $extractedDir) {
throw "Failed to find extracted LLVM directory under $extractRoot"
}

if (Test-Path $installRoot) {
Remove-Item -Recurse -Force $installRoot
}
Move-Item -Path $extractedDir.FullName -Destination $installRoot

$clangClPath = Join-Path $installRoot "bin\clang-cl.exe"
$llvmCmakeDir = Join-Path $installRoot "lib\cmake\llvm"
$clangCmakeDir = Join-Path $installRoot "lib\cmake\clang"
$llvmConfigPath = Join-Path $llvmCmakeDir "LLVMConfig.cmake"
$clangConfigPath = Join-Path $clangCmakeDir "ClangConfig.cmake"

Write-Host "Checking extracted LLVM files"
Write-Host "clang-cl path: $clangClPath"
Write-Host "LLVMConfig path: $llvmConfigPath"
Write-Host "ClangConfig path: $clangConfigPath"

if (-not (Test-Path $clangClPath)) {
throw "clang-cl.exe not found after LLVM archive extraction: $clangClPath"
}
if (-not (Test-Path $llvmConfigPath)) {
throw "LLVMConfig.cmake not found after LLVM archive extraction: $llvmConfigPath"
}
if (-not (Test-Path $clangConfigPath)) {
throw "ClangConfig.cmake not found after LLVM archive extraction: $clangConfigPath"
}

$clangVersion = (& $clangClPath --version) -join " "
if ($clangVersion -notmatch "clang version 20\.1\.0") {
throw "Unexpected clang-cl version. Got: $clangVersion"
}

"LLVM_CMAKE_DIR=$llvmCmakeDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"LLVM_DIR=$llvmCmakeDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"Clang_DIR=$clangCmakeDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Configure + Build + Install
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
powershell -ExecutionPolicy Bypass -File .\scripts\build-windows.ps1 `
-LLVMDir "${env:LLVM_CMAKE_DIR}" `
-CompilerSourceDir "${PWD}\deps\coretrace-compiler" `
-StackAnalyzerSourceDir "${PWD}\deps\coretrace-stack-analyzer" `
-LoggerSourceDir "${PWD}\deps\coretrace-log" `
-Configuration Release

- name: Smoke test
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
.\dist\windows\bin\ctrace.exe -h
Loading
Loading