Skip to content

Commit

Permalink
Bun: Build WebKit for Windows in CI (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
paperclover authored Oct 27, 2023
1 parent 67c9ba9 commit 4668973
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 35 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ jobs:
name: ${{matrix.label}}
path: ${{runner.temp}}/bun-webkit.tar.gz

windows:
strategy:
matrix:
include:
- runner: windows-latest
build-type: Release
arch: amd64
runs-on: windows-latest
timeout-minutes: 90
steps:
- uses: ilammy/msvc-dev-cmd@7315a94840631165970262a99c72cfb48a65d25d
with:
arch: ${{ matrix.arch }}
- uses: KyleMayes/install-llvm-action@1a3da29f56261a1e1f937ec88f0856a9b8321d7e
with:
version: 16.0.6
- run: choco install -y ninja
- uses: actions/checkout@v4
- name: Build WebKit
run: |
$env:Path = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\;" + $env:Path
$env:WEBKIT_OUTPUT_DIR = "bun-webkit"
$env:BUN_WEBKIT_VERSION = "${{ github.sha }}"
$env:CMAKE_BUILD_TYPE = "${{matrix.build-type}}"
./windows-release.ps1
- uses: actions/upload-artifact@v3
with:
name: bun-webkit-windows-${{ matrix.arch }}
path: bun-webkit.tar.gz

release:
name: release
permissions:
Expand All @@ -160,6 +190,7 @@ jobs:
needs:
- linux
- macos
- windows
steps:
- uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -209,6 +240,10 @@ jobs:
with:
name: bun-webkit-linux-arm64-lto
path: ${{runner.temp}}/bun-webkit-linux-arm64-lto
- uses: actions/download-artifact@v3
with:
name: bun-webkit-windows-amd64
path: ${{runner.temp}}/bun-webkit-windows-amd64

- name: Rename files
run: |
Expand All @@ -224,6 +259,7 @@ jobs:
mv ${{runner.temp}}/bun-webkit-macos-amd64-lto/bun-webkit.tar.gz ${{runner.temp}}/bun-webkit-macos-amd64-lto.tar.gz
mv ${{runner.temp}}/bun-webkit-linux-arm64-lto/bun-webkit.tar.gz ${{runner.temp}}/bun-webkit-linux-arm64-lto.tar.gz
mv ${{runner.temp}}/bun-webkit-linux-amd64-lto/bun-webkit.tar.gz ${{runner.temp}}/bun-webkit-linux-amd64-lto.tar.gz
mv ${{runner.temp}}/bun-webkit-windows-amd64/bun-webkit.tar.gz ${{runner.temp}}/bun-webkit-windows-amd64.tar.gz
- name: Release
uses: softprops/action-gh-release@v1
id: release
Expand All @@ -244,6 +280,7 @@ jobs:
${{runner.temp}}/bun-webkit-linux-arm64-lto.tar.gz
${{runner.temp}}/bun-webkit-macos-arm64-lto.tar.gz
${{runner.temp}}/bun-webkit-macos-amd64-lto.tar.gz
${{runner.temp}}/bun-webkit-windows-amd64.tar.gz
- name: Canary
uses: softprops/action-gh-release@v1
with:
Expand All @@ -263,6 +300,7 @@ jobs:
${{runner.temp}}/bun-webkit-linux-arm64-lto.tar.gz
${{runner.temp}}/bun-webkit-macos-arm64-lto.tar.gz
${{runner.temp}}/bun-webkit-macos-amd64-lto.tar.gz
${{runner.temp}}/bun-webkit-windows-amd64.tar.gz
- uses: actions/setup-node@v3
with:
node-version: "16.x"
Expand Down
118 changes: 83 additions & 35 deletions windows-release.ps1
Original file line number Diff line number Diff line change
@@ -1,56 +1,104 @@
# Set default OUT_DIR to WebKitBuild
if (!$env:WEBKIT_BUILD_DIR) {
$env:WEBKIT_BUILD_DIR = "WebKitBuild"
$ErrorActionPreference = "Stop"

$output = if ($env:WEBKIT_OUTPUT_DIR) { $env:WEBKIT_OUTPUT_DIR } else { "bun-webkit" }
$WebKitBuild = if ($env:WEBKIT_BUILD_DIR) { $env:WEBKIT_BUILD_DIR } else { "WebKitBuild" }
$CMAKE_BUILD_TYPE = if ($env:CMAKE_BUILD_TYPE) { $env:CMAKE_BUILD_TYPE } else { "Release" }
$BUN_WEBKIT_VERSION = if ($env:BUN_WEBKIT_VERSION) { $env:BUN_WEBKIT_VERSION } else { $(git rev-parse HEAD) }

$ICU_URL = "https://github.com/unicode-org/icu/releases/download/release-73-1/icu4c-73_1-Win64-MSVC2019.zip"
$ICU_ROOT = Join-Path $WebKitBuild "libicu"
$ICU_LIBRARY = Join-Path $ICU_ROOT "lib64"
$ICU_INCLUDE_DIR = Join-Path $ICU_ROOT "include"

$null = mkdir $WebKitBuild -ErrorAction SilentlyContinue

if (!(Test-Path -Path $ICU_ROOT)) {
# Download and extract URL
Write-Host "Downloading ICU from ${ICU_URL}"
$icuZipPath = Join-Path $WebKitBuild "icu.zip"
if (!(Test-Path -Path $icuZipPath)) {
Invoke-WebRequest -Uri $ICU_URL -OutFile $icuZipPath
}
$null = New-Item -ItemType Directory -Path $ICU_ROOT
$null = Expand-Archive $icuZipPath $ICU_ROOT
Remove-Item -Path $icuZipPath
}

# ICU_LIBRARY is expected to exist: C:\Users\windo\Build\libicu\lib64
# ICU_INCLUDE_DIR is expected to exist: C:\Users\windo\Build\libicu\include
# ICU_ROOT is expected to exist: C:\Users\windo\Build\libicu
cmake `
$env:CC = "clang-cl"
$env:CXX = "clang-cl"
# for some reason we don't get pdb files by default
# if we used MSVC we would, so it's something with clang-cl??
# these flags don't actually work, but docs say they should...
$env:CFLAGS = "/Zi /Z7"
$env:CXXFLAGS = "/Zi /Z7"

cmake -S . -B $WebKitBuild `
-DPORT="JSCOnly" `
-DENABLE_STATIC_JSC=ON `
-DENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE=ON `
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON `
-DCMAKE_BUILD_TYPE=Release `
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" `
-DUSE_THIN_ARCHIVES=OFF `
-DENABLE_DFG_JIT=ON `
-DENABLE_FTL_JIT=OFF `
-DENABLE_WEBASSEMBLY=OFF `
-DUSE_BUN_JSC_ADDITIONS=ON `
-S . `
-B ${env:WEBKIT_BUILD_DIR} `
-DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON `
-DUSE_SYSTEM_MALLOC=ON `
-DSTATICALLY_LINKED_WITH_WTF=ON

cmake --build WebKitBuild --config Release --target jsc
"-DICU_ROOT=${ICU_ROOT}" `
"-DICU_LIBRARY=${ICU_LIBRARY}" `
"-DICU_INCLUDE_DIR=${ICU_INCLUDE_DIR}" `
"-DCMAKE_C_COMPILER=clang-cl" `
"-DCMAKE_CXX_COMPILER=clang-cl" `
-DENABLE_REMOTE_INSPECTOR=ON `
-G Ninja

$output = "bun-webkit-x64"
if ($env:WEBKIT_OUTPUT_DIR) {
$output = $env:WEBKIT_OUTPUT_DIR
# Workaround for what is probably a CMake bug
$batFiles = Get-ChildItem -Path $WebKitBuild -Filter "*.bat" -File -Recurse
foreach ($file in $batFiles) {
$content = Get-Content $file.FullName -Raw
$newContent = $content -replace "(\|\| \(set FAIL_LINE=\d+& goto :ABORT\))", ""
if ($content -ne $newContent) {
Set-Content -Path $file.FullName -Value $newContent
Write-Host "Patched: $($file.FullName)"
}
}

rm -r -Force $output
mkdir -Force $output
mkdir -Force $output/lib
mkdir -Force $output/include
mkdir -Force $output/scripts
mkdir -Force $output/include/JavaScriptCore
mkdir -Force $output/include/wtf
cmake --build $WebKitBuild --config Release --target jsc

Remove-Item -Recurse -ErrorAction SilentlyContinue $output
$null = mkdir -ErrorAction SilentlyContinue $output
$null = mkdir -ErrorAction SilentlyContinue $output/lib
$null = mkdir -ErrorAction SilentlyContinue $output/include
$null = mkdir -ErrorAction SilentlyContinue $output/include/JavaScriptCore
$null = mkdir -ErrorAction SilentlyContinue $output/include/wtf

Copy-Item $WebKitBuild/cmakeconfig.h $output/include/cmakeconfig.h

# the pdb is commented because of above
Copy-Item $WebKitBuild/lib64/JavaScriptCore.lib $output/lib/
# Copy-Item $WebKitBuild/lib64/JavaScriptCore.pdb $output/lib/
Copy-Item $WebKitBuild/lib64/WTF.lib $output/lib/
# Copy-Item $WebKitBuild/lib64/WTF.pdb $output/lib/

Add-Content -Path $output/include/cmakeconfig.h -Value "`#define BUN_WEBKIT_VERSION `"$BUN_WEBKIT_VERSION`""

Copy-Item -r -Force $WebKitBuild/JavaScriptCore/DerivedSources/* $output/include/JavaScriptCore
Copy-Item -r -Force $WebKitBuild/JavaScriptCore/Headers/JavaScriptCore/* $output/include/JavaScriptCore/
Copy-Item -r -Force $WebKitBuild/JavaScriptCore/PrivateHeaders/JavaScriptCore/* $output/include/JavaScriptCore/

cp WebKitBuild/cmakeconfig.h $output/include/cmakeconfig.h
cp WebKitBuild/lib64/*.lib $output/lib/
cp WebKitBuild/lib64/*.pdb $output/lib/
Copy-Item -r $WebKitBuild/WTF/DerivedSources/* $output/include/wtf/
Copy-Item -r $WebKitBuild/WTF/Headers/wtf/* $output/include/wtf/

$BUN_WEBKIT_VERSION = $(git rev-parse HEAD)
(Get-Content -Path $output/include/JavaScriptCore/JSValueInternal.h) `
-replace "#import <JavaScriptCore/JSValuePrivate.h>", "#include <JavaScriptCore/JSValuePrivate.h>" `
| Set-Content -Path $output/include/JavaScriptCore/JSValueInternal.h

# Append #define BUN_WEBKIT_VERSION "${BUN_WEBKIT_VERSION}" to $output/include/cmakeconfig.h
Add-Content -Path $output/include/cmakeconfig.h -Value "`#define BUN_WEBKIT_VERSION `"`"$BUN_WEBKIT_VERSION`"`""
Copy-Item $WebKitBuild/libicu/include/* $output/include/
Copy-Item $WebKitBuild/libicu/lib64/* $output/lib/

cp -r -Force WebKitBuild/JavaScriptCore/DerivedSources/* $output/include/JavaScriptCore
cp -r -Force WebKitBuild/JavaScriptCore/Headers/JavaScriptCore/* $output/include/JavaScriptCore/
cp -r -Force WebKitBuild/JavaScriptCore/PrivateHeaders/JavaScriptCore/* $output/include/JavaScriptCore/
Remove-Item $output/lib/testplug.pdb

cp -r WebKitBuild/WTF/DerivedSources/* $output/include/wtf/
cp -r WebKitBuild/WTF/Headers/wtf/* $output/include/wtf/
tar -cz -f "${output}.tar.gz" "${output}"

cp WebKitBuild/JavaScriptCore/Scripts/*.py $output/scripts/
Write-Host "-> ${output}.tar.gz"

0 comments on commit 4668973

Please sign in to comment.