Skip to content
Merged
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
35 changes: 10 additions & 25 deletions .github/workflows/cmake-test-release-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ on:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
CACHE_VERSION: v10
CACHE_VERSION: v11
LLVM_VERSION: 22
LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/q6o011dlgw7n2ebzo176q/llvm_22_1_8_release_vs2026.zip?rlkey=s2h7c64nrmyz9bire0zr3ctzh&st=3nqb99qb&dl=1"
# The official LLVM release package plus a prebuilt MLIR archive, installed where a custom LLVM
# build would be - see scripts/install_llvm_prebuilt_release.ps1.
LLVM_FULL_VERSION: "22.1.8"
GC_VERSION: "8.2.12"
LIBATOMIC_OPS_VERSION: "7.10.0"

Expand All @@ -34,44 +36,27 @@ jobs:

- uses: actions/checkout@v4

- name: Cache Build 3rd Party
id: cache-3rd-party
uses: actions/cache@v4
with:
path: __build/llvm
key: ${{ runner.os }}-build-llvm-${{ env.LLVM_VERSION }}-${{ env.CACHE_VERSION }}

- name: Cache 3rd Party binaries
id: cache-3rd-party-binary
uses: actions/cache@v4
with:
path: 3rdParty
key: ${{ runner.os }}-3rd-party-${{ env.LLVM_VERSION }}-${{ env.CACHE_VERSION }}

- name: Cache 3rd Party binaries - LLVM ${{ env.LLVM_VERSION }} Release
id: cache-3rd-party-binary-llvm-release
uses: actions/cache@v4
with:
path: llvm_${{ env.LLVM_VERSION }}_release.zip
key: ${{ runner.os }}-3rd-party-llvm-${{ env.LLVM_VERSION }}-release-${{ env.CACHE_VERSION }}
key: ${{ runner.os }}-3rd-party-${{ env.LLVM_FULL_VERSION }}-${{ env.CACHE_VERSION }}-${{ hashFiles('scripts/install_llvm_prebuilt_release.ps1', 'scripts/llvm_prebuilt_common.ps1') }}

- name: Delete __Build TS folders
continue-on-error: true
run: if (Test-Path -Path ".\__build\tslang\msbuild\x64\release") { Remove-Item -Recurse -Force ".\__build\tslang\msbuild\x64\release" }
shell: pwsh

- name: Create __Build Folders
run: if (!(Test-Path -Path ".\__build\tslang\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\tslang\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\llvm\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\llvm\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\gc\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\gc\msbuild\x64\release" };
shell: pwsh

- name: Download 3rd party - LLVM
continue-on-error: true
run: if (!(Test-Path -Path ".\__build\tslang\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\tslang\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\gc\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\gc\msbuild\x64\release" };
shell: pwsh
run: if (!(Test-Path -Path "llvm_${{ env.LLVM_VERSION }}_release.zip")) { Invoke-WebRequest -SkipCertificateCheck -Uri "${{ env.LLVM_ZIPFILE }}" -OutFile "llvm_${{ env.LLVM_VERSION }}_release.zip" }

- name: UnZip 3rd party - LLVM
# Downloads and unpacks the official LLVM package and the prebuilt MLIR archive - nothing is
# compiled. Skips itself when the cached 3rdParty already has them.
- name: Install 3rd party - LLVM ${{ env.LLVM_FULL_VERSION }} + MLIR
continue-on-error: false
run: if (Test-Path -Path "llvm_${{ env.LLVM_VERSION }}_release.zip") { Expand-Archive -Path "llvm_${{ env.LLVM_VERSION }}_release.zip" -DestinationPath "3rdParty\llvm\x64" -Force }
run: ./scripts/install_llvm_prebuilt_release.ps1 -Version ${{ env.LLVM_FULL_VERSION }}
shell: pwsh

- name: Download 3rd party source - GC
Expand Down
40 changes: 13 additions & 27 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ env:
ASSET_NAME: tslang-${{ github.ref_name }}
CACHE_VERSION: v10
LLVM_VERSION: 22
LLVM_ZIPFILE: "https://www.dropbox.com/scl/fi/q6o011dlgw7n2ebzo176q/llvm_22_1_8_release_vs2026.zip?rlkey=s2h7c64nrmyz9bire0zr3ctzh&st=3nqb99qb&dl=1"
# Windows: the official LLVM release package plus a prebuilt MLIR archive, installed where a
# custom LLVM build would be - see scripts/install_llvm_prebuilt_release.ps1.
LLVM_FULL_VERSION: "22.1.8"
LLVM_TARGZFILE: "https://www.dropbox.com/scl/fi/ym6xvv8ib6yyewgf47ene/llvm_22_1_8_release.tgz?rlkey=jwkrrp82lql46qd1oysg9p736&st=p828hd39&dl=1"
GC_VERSION: "8.2.12"
LIBATOMIC_OPS_VERSION: "7.10.0"
Expand All @@ -30,26 +32,12 @@ jobs:
- name: Build project # This would actually build your project, using zip for an example artifact
run: echo 'SELECTED_COLOR=green Build project (Windows)' >> "$GITHUB_OUTPUT"

- name: Cache Build 3rd Party
id: cache-3rd-party
uses: actions/cache@v4
with:
path: __build/llvm
key: ${{ runner.os }}-build-llvm-${{ env.LLVM_VERSION }}-${{ env.CACHE_VERSION }}

- name: Cache 3rd Party binaries
id: cache-3rd-party-binary
uses: actions/cache@v4
with:
path: 3rdParty
key: ${{ runner.os }}-3rd-party-${{ env.LLVM_VERSION }}-${{ env.CACHE_VERSION }}

- name: Cache 3rd Party binaries - LLVM ${{ env.LLVM_VERSION }} Release
id: cache-3rd-party-binary-llvm-release
uses: actions/cache@v4
with:
path: llvm_${{ env.LLVM_VERSION }}_release.zip
key: ${{ runner.os }}-3rd-party-llvm-${{ env.LLVM_VERSION }}-release-${{ env.CACHE_VERSION }}
key: ${{ runner.os }}-3rd-party-${{ env.LLVM_FULL_VERSION }}-${{ env.CACHE_VERSION }}-${{ hashFiles('scripts/install_llvm_prebuilt_release.ps1', 'scripts/llvm_prebuilt_common.ps1') }}

- name: Retrieve version
run: echo "TAG_NAME=$(git describe --abbrev=0 --tags)" >> "$GITHUB_OUTPUT"
Expand All @@ -63,17 +51,14 @@ jobs:
shell: pwsh

- name: Create __Build Folders
run: if (!(Test-Path -Path ".\__build\tslang\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\tslang\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\llvm\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\llvm\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\gc\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\gc\msbuild\x64\release" };
run: if (!(Test-Path -Path ".\__build\tslang\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\tslang\msbuild\x64\release" }; if (!(Test-Path -Path ".\__build\gc\msbuild\x64\release")) { New-Item -ItemType Directory -Force -Path ".\__build\gc\msbuild\x64\release" };
shell: pwsh

- name: Download 3rd party - LLVM
continue-on-error: true
shell: pwsh
run: if (!(Test-Path -Path "llvm_${{ env.LLVM_VERSION }}_release.zip")) { Invoke-WebRequest -SkipCertificateCheck -Uri "${{ env.LLVM_ZIPFILE }}" -OutFile "llvm_${{ env.LLVM_VERSION }}_release.zip" }

- name: UnZip 3rd party - LLVM
# Downloads and unpacks the official LLVM package and the prebuilt MLIR archive - nothing is
# compiled. Skips itself when the cached 3rdParty already has them.
- name: Install 3rd party - LLVM ${{ env.LLVM_FULL_VERSION }} + MLIR
continue-on-error: false
run: if (Test-Path -Path "llvm_${{ env.LLVM_VERSION }}_release.zip") { Expand-Archive -Path "llvm_${{ env.LLVM_VERSION }}_release.zip" -DestinationPath "3rdParty\llvm\x64" -Force }
run: ./scripts/install_llvm_prebuilt_release.ps1 -Version ${{ env.LLVM_FULL_VERSION }}
shell: pwsh

- name: Download 3rd party source - GC
Expand Down Expand Up @@ -228,12 +213,13 @@ jobs:
# plus the shared collector in its own folder, because its import library is also named
# gc.lib: gcdll/gc.lib + gcdll/gc.dll, for programs that load a tslang shared library.
# tsbindgen looks for clang's resource directory next to itself as lib/clang/<major>
# (findResourceDir's "release package" candidate), so stage that layout too.
# (findResourceDir's "release package" candidate), so stage that layout too - its headers
# only: the official LLVM package also puts compiler-rt's libraries under
# lib/clang/<major>/lib, which neither tsbindgen nor tslang uses.
run: |
New-Item -ItemType Directory -Force -Path .\gcdll_stage\gcdll | Out-Null
Copy-Item -Path ..\3rdParty\gcdll\x64\release\lib\gc.lib, ..\3rdParty\gcdll\x64\release\bin\gc.dll -Destination .\gcdll_stage\gcdll -ErrorAction Stop
New-Item -ItemType Directory -Force -Path .\resourcedir_stage\lib | Out-Null
Copy-Item -Path ..\3rdParty\llvm\x64\release\lib\clang -Destination .\resourcedir_stage\lib -Recurse -ErrorAction Stop
Get-ChildItem -Path ..\3rdParty\llvm\x64\release\lib\clang -Directory | ForEach-Object { $dest = ".\resourcedir_stage\lib\clang\$($_.Name)"; New-Item -ItemType Directory -Force -Path $dest | Out-Null; Copy-Item -Path (Join-Path $_.FullName "include") -Destination $dest -Recurse -ErrorAction Stop }
Get-ChildItem -Path .\tslang\msbuild\x64\release\bin\tslang.exe, .\tslang\msbuild\x64\release\bin\tsbindgen.exe, .\tslang\msbuild\x64\release\bin\TypeScriptRuntime.dll, .\tslang\msbuild\x64\release\bin\gc.dll, .\gc\msbuild\x64\release\${{ env.BUILD_TYPE }}\gc.lib, .\tslang\msbuild\x64\release\lib\TypeScriptAsyncRuntime.lib, ..\3rdParty\llvm\x64\release\bin\wasm-ld.exe, ..\TypeScriptCompilerDefaultLib\__build, .\gcdll_stage, .\resourcedir_stage | Compress-Archive -DestinationPath ..\${{ env.ASSET_NAME }}-windows-x64.zip
shell: pwsh

Expand Down
68 changes: 68 additions & 0 deletions scripts/build_mlir_prebuilt_release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Builds the prebuilt MLIR archive that install_llvm_prebuilt_release.ps1 installs - run once per
# LLVM version, by hand, then upload the archive as the asset of the release named in
# Get-MlirArchiveUrl (llvm_prebuilt_common.ps1). Background there.
#
# MLIR is built standalone (mlir/ and cmake/ from the matching llvm-project source release) against
# the official LLVM package, Release, static CRT, and installed into an empty prefix. That install
# is the archive: its CMake package finds LLVM relative to itself, so unpacked over the official
# package it needs no absolute paths. About 10 minutes at -j20; far longer on a 4-core CI runner,
# which is why CI downloads the result instead.
param(
[string]$Version = "22.1.8",
[string]$WorkDir = "",
[string]$Out = "",
[string]$Generator = "Visual Studio 18 2026",
[int]$Jobs = [Environment]::ProcessorCount
)

. (Join-Path $PSScriptRoot "llvm_prebuilt_common.ps1")

$repoRoot = Split-Path -Parent $PSScriptRoot
# Short by default: MSBuild's file tracker fails on paths past MAX_PATH, and MLIR's build tree is deep.
if ($WorkDir -eq "") { $WorkDir = Join-Path $repoRoot "__build\llvm-prebuilt" }
$WorkDir = [IO.Path]::GetFullPath($WorkDir)
if ($Out -eq "") { $Out = Join-Path $WorkDir (Get-MlirArchiveName $Version) }
$Out = [IO.Path]::GetFullPath($Out)
New-Item -ItemType Directory -Force -Path $WorkDir | Out-Null

# 1. The official package to build against.
$llvmPrefix = Join-Path $WorkDir "llvm"
Install-OfficialLlvm $Version $llvmPrefix $WorkDir

# 2. MLIR sources: mlir/ plus the shared cmake/ modules it includes.
$srcRoot = Join-Path $WorkDir "llvm-project-$Version.src"
if (-not (Test-Path (Join-Path $srcRoot "mlir\CMakeLists.txt"))) {
$sources = Get-LlvmAsset $Version "llvm-project-$Version.src.tar.xz" $WorkDir
Write-Host "Unpacking mlir/ and cmake/ from $sources"
Invoke-Checked "Unpacking the MLIR sources" {
& $script:tar -xf $sources -C $WorkDir "llvm-project-$Version.src/mlir" "llvm-project-$Version.src/cmake"
}
}

# 3. MLIR into an empty prefix. LLVM_BUILD_UTILS is off in the package's LLVMConfig, and without
# it mlir-tblgen is built but not installed.
$buildDir = Join-Path $WorkDir "mlir-build"
$mlirPrefix = Join-Path $WorkDir "mlir-install"
if (Test-Path $mlirPrefix) { Remove-Item -Recurse -Force $mlirPrefix }
Invoke-Checked "Configuring MLIR" {
cmake -S (Join-Path $srcRoot "mlir") -B $buildDir -G $Generator -A x64 -Thost=x64 -Wno-dev `
"-DLLVM_DIR=$(($llvmPrefix -replace '\\', '/'))/lib/cmake/llvm" `
"-DCMAKE_INSTALL_PREFIX=$(($mlirPrefix -replace '\\', '/'))" `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded `
-DLLVM_BUILD_UTILS=ON `
-DLLVM_INCLUDE_TESTS=OFF `
-DMLIR_INCLUDE_TESTS=OFF `
-DMLIR_INCLUDE_INTEGRATION_TESTS=OFF `
-DMLIR_ENABLE_BINDINGS_PYTHON=OFF
}
Invoke-Checked "Building MLIR" { cmake --build $buildDir --config Release --target install -j $Jobs }
foreach ($required in @("lib\cmake\mlir\MLIRConfig.cmake", "bin\mlir-tblgen.exe")) {
if (-not (Test-Path (Join-Path $mlirPrefix $required))) { throw "MLIR install is missing $required" }
}

# 4. The archive.
if (Test-Path $Out) { Remove-Item -Force $Out }
Invoke-Checked "Packing MLIR" { & $script:tar -cJf $Out -C $mlirPrefix . }
Write-Host "Wrote $Out ($([math]::Round((Get-Item $Out).Length / 1MB)) MB)"
Write-Host "Upload it as $(Get-MlirArchiveUrl $Version)"
39 changes: 39 additions & 0 deletions scripts/install_llvm_prebuilt_release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Installs a Release LLVM/Clang/LLD/MLIR prefix from prebuilt archives only - nothing is compiled:
# the official LLVM Windows package, then the MLIR archive made by build_mlir_prebuilt_release.ps1,
# unpacked into the same prefix. Background in llvm_prebuilt_common.ps1.
#
# Skips everything when the prefix already has MLIR, so it never overwrites a custom build.
param(
[string]$Version = "22.1.8",
[string]$Prefix = "",
[string]$WorkDir = "",
# A URL or a local file; defaults to the release asset named in llvm_prebuilt_common.ps1.
[string]$MlirArchive = ""
)

. (Join-Path $PSScriptRoot "llvm_prebuilt_common.ps1")

$repoRoot = Split-Path -Parent $PSScriptRoot
if ($Prefix -eq "") { $Prefix = Join-Path $repoRoot "3rdParty\llvm\x64\release" }
if ($WorkDir -eq "") { $WorkDir = Join-Path $repoRoot "__build\llvm-prebuilt" }
if ($MlirArchive -eq "") { $MlirArchive = Get-MlirArchiveUrl $Version }
$Prefix = [IO.Path]::GetFullPath($Prefix)
$WorkDir = [IO.Path]::GetFullPath($WorkDir)

$mlirConfig = Join-Path $Prefix "lib\cmake\mlir\MLIRConfig.cmake"
if (Test-Path $mlirConfig) {
Write-Host "MLIR is already installed in $Prefix, nothing to do"
exit 0
}
New-Item -ItemType Directory -Force -Path $WorkDir, $Prefix | Out-Null

Install-OfficialLlvm $Version $Prefix $WorkDir

if ($MlirArchive -match '^https?://') { $MlirArchive = Get-Download $MlirArchive $WorkDir }
Write-Host "Unpacking $MlirArchive into $Prefix"
Invoke-Checked "Unpacking the MLIR archive" { & $script:tar -xf $MlirArchive -C $Prefix }

foreach ($required in @($mlirConfig, (Join-Path $Prefix "bin\mlir-tblgen.exe"))) {
if (-not (Test-Path $required)) { throw "MLIR install is missing $required" }
}
Write-Host "LLVM $Version with MLIR installed in $Prefix"
79 changes: 79 additions & 0 deletions scripts/llvm_prebuilt_common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Shared by build_mlir_prebuilt_release.ps1 and install_llvm_prebuilt_release.ps1 (dot-sourced).
#
# The official LLVM Windows package (clang+llvm-<ver>-x86_64-pc-windows-msvc.tar.xz, a GitHub
# release asset of llvm/llvm-project) carries the LLVM, Clang and LLD libraries with their CMake
# packages, lld/wasm-ld, clang and clang's resource directory, built with the static CRT (/MT) the
# project needs. It has no MLIR at all. build_mlir_prebuilt_release.ps1 builds MLIR standalone
# against it once and packs the MLIR install; install_llvm_prebuilt_release.ps1 unpacks both into
# one prefix, which then has the layout of a prefix made by config_llvm_release_vs.bat +
# build_llvm_release_vs.bat. Nothing is compiled on the machine that installs.
#
# Differences from the custom build: RTTI and EH are off in the LLVM libraries (the project's MSVC
# flags force /GR /EHsc for its own code, which is fine), LLVMSupport brings rpmalloc as the
# process malloc (-INCLUDE:malloc on its CMake target), and there is no Debug variant - Debug still
# needs the custom build.

$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

# Windows' own bsdtar reads and writes .tar.xz; a Git for Windows tar earlier on PATH would need xz
# beside it.
$script:tar = Join-Path $env:SystemRoot "System32\tar.exe"

function Invoke-Checked([string]$what, [scriptblock]$block) {
& $block
if ($LASTEXITCODE -ne 0) { throw "$what failed (exit code $LASTEXITCODE)" }
}

# Downloads $url into $dir unless it is already there; returns the file.
function Get-Download([string]$url, [string]$dir) {
$file = Join-Path $dir ([IO.Path]::GetFileName(([Uri]$url).AbsolutePath))
if (-not (Test-Path $file)) {
Write-Host "Downloading $url"
Invoke-WebRequest -Uri $url -OutFile "$file.part"
Move-Item "$file.part" $file
}
return $file
}

function Get-LlvmAsset([string]$version, [string]$name, [string]$dir) {
return Get-Download "https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/$name" $dir
}

# Unpacks the official package into $prefix (unless it is there) and checks its version.
function Install-OfficialLlvm([string]$version, [string]$prefix, [string]$workDir) {
$llvmConfig = Join-Path $prefix "lib\cmake\llvm\LLVMConfig.cmake"
if (-not (Test-Path $llvmConfig)) {
$package = Get-LlvmAsset $version "clang+llvm-$version-x86_64-pc-windows-msvc.tar.xz" $workDir
New-Item -ItemType Directory -Force -Path $prefix | Out-Null
Write-Host "Unpacking $package into $prefix"
Invoke-Checked "Unpacking the LLVM package" { & $script:tar -xf $package -C $prefix --strip-components=1 }
}
if (-not (Select-String -Path $llvmConfig -SimpleMatch "set(LLVM_PACKAGE_VERSION $version)" -Quiet)) {
throw "$prefix holds an LLVM other than $version (see $llvmConfig)"
}
Repair-DiaSdkPath $prefix
}

# LLVMDebugInfoPDB's exported link line names the DIA SDK at the path it had on the machine that
# built the package (llvm/llvm-project#86250), so every link that pulls it in fails with LNK1181.
# Point it at this machine's Visual Studio.
function Repair-DiaSdkPath([string]$prefix) {
$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe"
$vsPath = & $vswhere -latest -products * -property installationPath
$diaGuids = Join-Path $vsPath "DIA SDK\lib\amd64\diaguids.lib"
if (-not (Test-Path $diaGuids)) { throw "DIA SDK not found at $diaGuids" }
$exports = Join-Path $prefix "lib\cmake\llvm\LLVMExports.cmake"
$text = [IO.File]::ReadAllText($exports)
$fixed = [regex]::Replace($text, '[^";]*/DIA SDK/lib/amd64/diaguids\.lib', ($diaGuids -replace '\\', '/'))
if ($fixed -ne $text) {
[IO.File]::WriteAllText($exports, $fixed)
Write-Host "LLVMExports.cmake: DIA SDK -> $diaGuids"
}
}

# The MLIR archive's name, and where install_llvm_prebuilt_release.ps1 looks for it by default.
function Get-MlirArchiveName([string]$version) { return "mlir-$version-x86_64-pc-windows-msvc-mt.tar.xz" }
function Get-MlirArchiveUrl([string]$version) {
return "https://github.com/ASDAlexander77/TypeScriptCompiler/releases/download/llvm-$version-mlir/$(Get-MlirArchiveName $version)"
}
Loading
Loading