diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 537edca74de8b..b1f872bf4220d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -243,20 +243,146 @@ jobs: build-type: Debug package_json_arch: "x64" label: bun-webkit-windows-amd64-debug + - runner: windows-11-arm + build-type: Release + package_json_arch: "arm64" + label: bun-webkit-windows-arm64 + - runner: windows-11-arm + build-type: Debug + package_json_arch: "arm64" + label: bun-webkit-windows-arm64-debug runs-on: ${{ matrix.runner }} timeout-minutes: 90 steps: - - name: Install Scoop + - name: Disable Windows Defender + shell: pwsh run: | - Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression - Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH - - name: Install LLVM and Ninja + # Stop Windows Defender services + Stop-Service -Name WinDefend -Force -ErrorAction SilentlyContinue + Stop-Service -Name WdNisSvc -Force -ErrorAction SilentlyContinue + + # Disable real-time protection via registry + Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender\Real-Time Protection" -Name DisableRealtimeMonitoring -Value 1 -Force -ErrorAction SilentlyContinue + Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender" -Name DisableAntiSpyware -Value 1 -Force -ErrorAction SilentlyContinue + Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender" -Name DisableAntiVirus -Value 1 -Force -ErrorAction SilentlyContinue + + # Disable via PowerShell preferences (belt and suspenders) + Set-MpPreference -DisableRealtimeMonitoring $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableBehaviorMonitoring $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableBlockAtFirstSeen $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableIOAVProtection $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisablePrivacyMode $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableScriptScanning $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableArchiveScanning $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -SignatureDisableUpdateOnStartupWithoutEngine $true -Force -ErrorAction SilentlyContinue + Set-MpPreference -DisableIntrusionPreventionSystem $true -Force -ErrorAction SilentlyContinue + + # Add exclusions for the entire system drive as a last resort + Add-MpPreference -ExclusionPath "C:\" -Force -ErrorAction SilentlyContinue + Add-MpPreference -ExclusionProcess "*" -Force -ErrorAction SilentlyContinue + + - name: Install dependencies for Windows run: | - scoop install ninja - scoop install llvm@19.1.7 - Join-Path (Resolve-Path ~).Path "scoop\apps\llvm\current\bin" >> $Env:GITHUB_PATH - - uses: cygwin/cygwin-install-action@006ad0b0946ca6d0a3ea2d4437677fa767392401 + # Detect architecture + $isARM64 = $env:PROCESSOR_ARCHITECTURE -eq "ARM64" + + # Install Scoop if not available + if (!(Get-Command scoop -ErrorAction SilentlyContinue)) { + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force + Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression + $env:PATH = "$env:USERPROFILE\scoop\shims;$env:PATH" + echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + } + + # On ARM64, manually install 7zip to avoid Scoop's extraction issues + if ($isARM64) { + $7zipUrl = "https://www.7-zip.org/a/7z2501-arm64.exe" + $7zipExe = "$env:TEMP\7z-installer.exe" + Invoke-WebRequest -Uri $7zipUrl -OutFile $7zipExe + + # Extract manually + Start-Process -FilePath $7zipExe -ArgumentList "/S", "/D=C:\Program Files\7-Zip" -Wait + echo "C:\Program Files\7-Zip" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + # Tell Scoop to use the external 7zip we just installed + scoop config use_external_7zip true + scoop config 7zip_path "C:\Program Files\7-Zip\7z.exe" + } else { + # x64 can use normal Scoop 7zip installation + scoop install 7zip + } + + # Skip aria2 on ARM64 as it may cause issues + if (-not $isARM64) { + scoop install aria2 + } + + # Install tools via Scoop one by one for better error isolation + if ($isARM64) { + # Use ARM64-specific packages + scoop install cmake + scoop install ninja + scoop install python + scoop install perl + scoop install make + + # Download and extract LLVM ARM64 directly (Scoop's pre_install fails) + Write-Host "Downloading LLVM ARM64..." + $llvmVersion = "19.1.4" + $llvmUrl = "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvmVersion/LLVM-$llvmVersion-woa64.exe" + $llvmPath = "C:\LLVM" + + # Download LLVM installer + $llvmInstaller = "$env:TEMP\llvm-arm64.exe" + Invoke-WebRequest -Uri $llvmUrl -OutFile $llvmInstaller + + # Extract with 7zip (faster than installer) + Write-Host "Extracting LLVM (this may take a few minutes)..." + $extractResult = & "C:\Program Files\7-Zip\7z.exe" x $llvmInstaller -o"$llvmPath" -y 2>&1 + Write-Host "7zip extraction completed with result: $LASTEXITCODE" + + # Verify extraction worked + if (Test-Path "$llvmPath\bin\clang.exe") { + Write-Host "LLVM extracted successfully" + # Add to PATH + echo "$llvmPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + Write-Host "LLVM ARM64 installed and added to PATH" + } else { + Write-Host "ERROR: LLVM extraction failed - clang.exe not found" + exit 1 + } + + Write-Host "ARM64 dependency installation completed, continuing..." + } else { + # Use x64 packages + scoop install cmake + scoop install ninja + scoop install python + scoop install perl + scoop install llvm + scoop install make + } + + Write-Host "Starting Ruby installation phase..." + + # Install Ruby manually on ARM64 (Scoop's Ruby fails on ARM64) + if ($isARM64) { + Write-Host "Skipping Ruby installation on ARM64 - using pre-installed Ruby" + # GitHub Actions ARM64 runners come with Ruby pre-installed + } else { + # x64 can use Scoop's Ruby + Write-Host "Installing Ruby via Scoop..." + scoop install ruby + Write-Host "Ruby installation completed" + } + + # Install vcpkg + git clone https://github.com/Microsoft/vcpkg.git C:\vcpkg + cd C:\vcpkg + .\bootstrap-vcpkg.bat + $env:VCPKG_ROOT = "C:\vcpkg" + echo "VCPKG_ROOT=C:\vcpkg" >> $env:GITHUB_ENV + - uses: actions/checkout@v4 with: sparse-checkout-cone-mode: false @@ -274,6 +400,14 @@ jobs: $env:GITHUB_SHA = "${{ github.sha }}" $env:PACKAGE_JSON_ARCH = "${{matrix.package_json_arch}}" $env:GITHUB_REPOSITORY = "${{ github.repository }}" + + # Explicitly set architecture to avoid detection issues + if ("${{matrix.package_json_arch}}" -eq "arm64") { + $env:BUILD_ARM64 = "1" + } else { + $env:BUILD_ARM64 = "0" + } + ./windows-release.ps1 - uses: actions/upload-artifact@v4 with: @@ -440,6 +574,14 @@ jobs: with: name: bun-webkit-windows-amd64-debug path: ${{runner.temp}}/bun-webkit-windows-amd64-debug + - uses: actions/download-artifact@v4 + with: + name: bun-webkit-windows-arm64 + path: ${{runner.temp}}/bun-webkit-windows-arm64 + - uses: actions/download-artifact@v4 + with: + name: bun-webkit-windows-arm64-debug + path: ${{runner.temp}}/bun-webkit-windows-arm64-debug - uses: actions/download-artifact@v4 with: name: bun-webkit-linux-amd64-musl @@ -491,6 +633,8 @@ jobs: mv ${{runner.temp}}/bun-webkit-linux-arm64-musl-lto/bun-webkit.tar.gz ./out/bun-webkit-linux-arm64-musl-lto.tar.gz mv ${{runner.temp}}/bun-webkit-windows-amd64/bun-webkit.tar.gz ./out/bun-webkit-windows-amd64.tar.gz mv ${{runner.temp}}/bun-webkit-windows-amd64-debug/bun-webkit.tar.gz ./out/bun-webkit-windows-amd64-debug.tar.gz + mv ${{runner.temp}}/bun-webkit-windows-arm64/bun-webkit.tar.gz ./out/bun-webkit-windows-arm64.tar.gz + mv ${{runner.temp}}/bun-webkit-windows-arm64-debug/bun-webkit.tar.gz ./out/bun-webkit-windows-arm64-debug.tar.gz - name: Release uses: softprops/action-gh-release@v1 with: @@ -540,3 +684,5 @@ jobs: files: | ./out/bun-webkit-windows-amd64.tar.gz ./out/bun-webkit-windows-amd64-debug.tar.gz + ./out/bun-webkit-windows-arm64.tar.gz + ./out/bun-webkit-windows-arm64-debug.tar.gz diff --git a/Source/JavaScriptCore/assembler/ARM64Assembler.h b/Source/JavaScriptCore/assembler/ARM64Assembler.h index 47eb9c9b3bddc..1418318e42cd3 100644 --- a/Source/JavaScriptCore/assembler/ARM64Assembler.h +++ b/Source/JavaScriptCore/assembler/ARM64Assembler.h @@ -465,7 +465,11 @@ class ARM64Assembler { BranchType m_branchType : 2 { BranchType_JMP }; } realTypes { }; struct CopyTypes { +#if OS(WINDOWS) + uint64_t content[5]; // Increased to match RealTypes size (40 bytes) on Windows +#else uint64_t content[3]; +#endif } copyTypes; static_assert(sizeof(RealTypes) == sizeof(CopyTypes), "LinkRecord's CopyStruct size equals to RealStruct"); } data; @@ -3780,6 +3784,9 @@ class ARM64Assembler { linuxPageFlush(current, current + page); linuxPageFlush(current, end); +#elif OS(WINDOWS) + // On Windows ARM64, use FlushInstructionCache + FlushInstructionCache(GetCurrentProcess(), code, size); #else #error "The cacheFlush support is missing on this platform." #endif diff --git a/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h b/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h index fab41dd01fc05..792a7eee16e9a 100644 --- a/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h +++ b/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h @@ -304,7 +304,7 @@ class AbstractMacroAssembler : public AbstractMacroAssemblerBase { { } -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) template explicit TrustedImmPtr(ReturnType(SYSV_ABI *value)(Arguments...)) : m_value(reinterpret_cast(value)) diff --git a/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp b/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp index 74934f85f1afa..c5a605e22278d 100644 --- a/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp +++ b/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp @@ -580,7 +580,9 @@ asm ( #else "ret" "\n" #endif +#if !OS(WINDOWS) ".previous" "\n" +#endif ); // And now, the slower version that saves the full width of FP registers: @@ -833,7 +835,9 @@ asm ( #else "ret" "\n" #endif +#if !OS(WINDOWS) ".previous" "\n" +#endif ); void MacroAssembler::probe(Probe::Function function, void* arg, SavedFPWidth savedFPWidth) diff --git a/Source/JavaScriptCore/interpreter/CallFrame.h b/Source/JavaScriptCore/interpreter/CallFrame.h index 63cf359f417c3..cbc05b23d5618 100644 --- a/Source/JavaScriptCore/interpreter/CallFrame.h +++ b/Source/JavaScriptCore/interpreter/CallFrame.h @@ -394,8 +394,8 @@ using JSInstruction = BaseInstruction; JS_EXPORT_PRIVATE bool isFromJSCode(void* returnAddress); #if USE(BUILTIN_FRAME_ADDRESS) -#if OS(WINDOWS) -// On Windows, __builtin_frame_address(1) doesn't work, it returns __builtin_frame_address(0) +#if OS(WINDOWS) && CPU(X86_64) +// On Windows x86_64, __builtin_frame_address(1) doesn't work, it returns __builtin_frame_address(0) // We can't use __builtin_frame_address(0) either, as on Windows it points at the space after // function's local variables on the stack instead of before like other platforms. // Instead we use _AddressOfReturnAddress(), and clobber rbp so it should be the first parameter @@ -411,7 +411,21 @@ JS_EXPORT_PRIVATE bool isFromJSCode(void* returnAddress); ASSERT(JSC::isFromJSCode(removeCodePtrTag(__builtin_return_address(0)))); \ std::bit_cast(*((uintptr_t**) _AddressOfReturnAddress() - 1)); \ }) -#else // !OS(WINDOWS) +#elif OS(WINDOWS) && CPU(ARM64) +// On Windows ARM64, __builtin_frame_address(1) also has issues similar to x86_64 +// Use _AddressOfReturnAddress() and clobber x29 (frame pointer) for ARM64 +#define DECLARE_CALL_FRAME(vm) \ + ({ \ + asm volatile( \ + "" \ + : /* no outputs */ \ + : /* no inputs */ \ + : "x29" /* clobber frame pointer */ \ + ); \ + ASSERT(JSC::isFromJSCode(removeCodePtrTag(__builtin_return_address(0)))); \ + std::bit_cast(*((uintptr_t**) _AddressOfReturnAddress() - 1)); \ + }) +#else // !OS(WINDOWS) || (!CPU(X86_64) && !CPU(ARM64)) // FIXME (see rdar://72897291): Work around a Clang bug where __builtin_return_address() // sometimes gives us a signed pointer, and sometimes does not. #define DECLARE_CALL_FRAME(vm) \ @@ -419,7 +433,7 @@ JS_EXPORT_PRIVATE bool isFromJSCode(void* returnAddress); ASSERT(JSC::isFromJSCode(removeCodePtrTag(__builtin_return_address(0)))); \ std::bit_cast(__builtin_frame_address(1)); \ }) -#endif // !OS(WINDOWS) +#endif // !(OS(WINDOWS) && (CPU(X86_64) || CPU(ARM64))) #else #define DECLARE_CALL_FRAME(vm) ((vm).topCallFrame) #endif diff --git a/Source/JavaScriptCore/jit/ThunkGenerators.cpp b/Source/JavaScriptCore/jit/ThunkGenerators.cpp index 26e99a881b21b..180447739fc4b 100644 --- a/Source/JavaScriptCore/jit/ThunkGenerators.cpp +++ b/Source/JavaScriptCore/jit/ThunkGenerators.cpp @@ -902,7 +902,7 @@ typedef MathThunkCallingConvention(*MathThunk)(MathThunkCallingConvention); } \ static MathThunk UnaryDoubleOpWrapper(function) = &function##Thunk; -#elif CPU(ARM64) +#elif CPU(ARM64) && !OS(WINDOWS) #define defineUnaryDoubleOpWrapper(function) \ asm( \ diff --git a/Source/JavaScriptCore/offlineasm/arm64.rb b/Source/JavaScriptCore/offlineasm/arm64.rb index aa6451bc7b93f..58263d0dbfdc7 100644 --- a/Source/JavaScriptCore/offlineasm/arm64.rb +++ b/Source/JavaScriptCore/offlineasm/arm64.rb @@ -1399,6 +1399,17 @@ def lowerARM64 $asm.puts "ldr #{operands[1].arm64Operand(:quad)}, [#{operands[1].arm64Operand(:quad)}, :got_lo12:#{operands[0].asmLabel}]" $asm.putStr("#endif") + # On Windows, use COFF-style addressing + $asm.putStr("#elif OS(WINDOWS)") + + # Windows ARM64 uses PC-relative addressing similar to Linux + $asm.puts "adrp #{operands[1].arm64Operand(:quad)}, #{operands[0].asmLabel}" + $asm.putStr("#if CPU(ADDRESS32)") + $asm.puts "add #{operands[1].arm64Operand(:word)}, #{operands[1].arm64Operand(:word)}, :lo12:#{operands[0].asmLabel}" + $asm.putStr("#else") + $asm.puts "add #{operands[1].arm64Operand(:quad)}, #{operands[1].arm64Operand(:quad)}, :lo12:#{operands[0].asmLabel}" + $asm.putStr("#endif") + # Throw a compiler error everywhere else. $asm.putStr("#else") $asm.putStr("#error Missing globaladdr implementation") diff --git a/Source/JavaScriptCore/runtime/MachineContext.h b/Source/JavaScriptCore/runtime/MachineContext.h index 0232941cb6327..08a93122fb47e 100644 --- a/Source/JavaScriptCore/runtime/MachineContext.h +++ b/Source/JavaScriptCore/runtime/MachineContext.h @@ -107,6 +107,8 @@ static inline void*& stackPointerImpl(PlatformRegisters& regs) return reinterpret_cast((uintptr_t&) regs.Esp); #elif CPU(X86_64) return reinterpret_cast((uintptr_t&) regs.Rsp); +#elif CPU(ARM64) + return reinterpret_cast((uintptr_t&) regs.Sp); #else #error Unknown Architecture #endif @@ -233,6 +235,8 @@ static inline void*& framePointerImpl(PlatformRegisters& regs) return reinterpret_cast((uintptr_t&) regs.Ebp); #elif CPU(X86_64) return reinterpret_cast((uintptr_t&) regs.Rbp); +#elif CPU(ARM64) + return reinterpret_cast((uintptr_t&) regs.Fp); #else #error Unknown Architecture #endif @@ -361,6 +365,8 @@ static inline void*& instructionPointerImpl(PlatformRegisters& regs) return reinterpret_cast((uintptr_t&) regs.Eip); #elif CPU(X86_64) return reinterpret_cast((uintptr_t&) regs.Rip); +#elif CPU(ARM64) + return reinterpret_cast((uintptr_t&) regs.Pc); #else #error Unknown Architecture #endif @@ -542,6 +548,8 @@ inline void*& argumentPointer<1>(PlatformRegisters& regs) return reinterpret_cast((uintptr_t&) regs.Edx); #elif CPU(X86_64) return reinterpret_cast((uintptr_t&) regs.Rdx); +#elif CPU(ARM64) + return reinterpret_cast((uintptr_t&) regs.X1); #else #error Unknown Architecture #endif @@ -571,6 +579,8 @@ inline void* wasmInstancePointer(const PlatformRegisters& regs) return reinterpret_cast((uintptr_t) regs.Ebx); #elif CPU(X86_64) return reinterpret_cast((uintptr_t) regs.Rbx); +#elif CPU(ARM64) + return reinterpret_cast((uintptr_t) regs.X19); #else #error Unknown Architecture #endif @@ -740,6 +750,9 @@ inline void*& llintInstructionPointer(PlatformRegisters& regs) #if CPU(ARM) static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC."); return reinterpret_cast((uintptr_t&) regs.R8); +#elif CPU(ARM64) + static_assert(LLInt::LLIntPC == ARM64Registers::x4, "Wrong LLInt PC."); + return reinterpret_cast((uintptr_t&) regs.X4); #elif CPU(X86) static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC."); return reinterpret_cast((uintptr_t&) regs.Esi); diff --git a/Source/WTF/wtf/CodePtr.h b/Source/WTF/wtf/CodePtr.h index f271642ddb5ae..7d72312c7b870 100644 --- a/Source/WTF/wtf/CodePtr.h +++ b/Source/WTF/wtf/CodePtr.h @@ -93,7 +93,7 @@ class CodePtr : public CodePtrBase { : m_value(encodeFunc(ptr)) { } -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) template constexpr CodePtr(Out(SYSV_ABI *ptr)(In...)) : m_value(encodeFunc(ptr)) diff --git a/Source/WTF/wtf/FunctionPtr.h b/Source/WTF/wtf/FunctionPtr.h index e6dc79afa57d6..31e1af7d2426d 100644 --- a/Source/WTF/wtf/FunctionPtr.h +++ b/Source/WTF/wtf/FunctionPtr.h @@ -88,7 +88,7 @@ class FunctionPtr : public FunctionPtrBase { : m_ptr(encode(ptr)) { } -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) constexpr FunctionPtr(Out(SYSV_ABI *ptr)(In...)) : m_ptr(encode(ptr)) { } diff --git a/Source/WTF/wtf/FunctionTraits.h b/Source/WTF/wtf/FunctionTraits.h index 02d701d21bb2b..141e0afe7efb1 100644 --- a/Source/WTF/wtf/FunctionTraits.h +++ b/Source/WTF/wtf/FunctionTraits.h @@ -77,7 +77,7 @@ struct FunctionTraits { }; -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) template struct FunctionTraits : public FunctionTraits { }; @@ -87,7 +87,7 @@ template struct FunctionTraits : public FunctionTraits { }; -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) template struct FunctionTraits : public FunctionTraits { }; diff --git a/Source/WTF/wtf/PlatformCPU.h b/Source/WTF/wtf/PlatformCPU.h index 8aac10247bb56..fabd6cba39f16 100644 --- a/Source/WTF/wtf/PlatformCPU.h +++ b/Source/WTF/wtf/PlatformCPU.h @@ -119,7 +119,7 @@ #endif /* CPU(ARM64) */ -#if defined(__arm64__) || defined(__aarch64__) +#if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) #define WTF_CPU_ARM64 1 #define WTF_CPU_KNOWN 1 diff --git a/Source/WTF/wtf/PlatformCallingConventions.h b/Source/WTF/wtf/PlatformCallingConventions.h index e39e583ca4d24..680e981fbffe6 100644 --- a/Source/WTF/wtf/PlatformCallingConventions.h +++ b/Source/WTF/wtf/PlatformCallingConventions.h @@ -33,7 +33,7 @@ /* Macros for specifing specific calling conventions. */ -#if OS(WINDOWS) +#if OS(WINDOWS) && CPU(X86_64) #define SYSV_ABI __attribute__((sysv_abi)) #else #define SYSV_ABI diff --git a/Source/WTF/wtf/PlatformUse.h b/Source/WTF/wtf/PlatformUse.h index e1b5763446baf..016489bc33917 100644 --- a/Source/WTF/wtf/PlatformUse.h +++ b/Source/WTF/wtf/PlatformUse.h @@ -145,7 +145,7 @@ /* FIXME: This name should be more specific if it is only for use with CallFrame* */ /* Use __builtin_frame_address(1) to get CallFrame* */ -#if CPU(ARM64) || CPU(X86_64) +#if (CPU(ARM64) || CPU(X86_64)) && !(OS(WINDOWS) && CPU(ARM64)) #define USE_BUILTIN_FRAME_ADDRESS 1 #endif diff --git a/Source/WTF/wtf/StackPointer.cpp b/Source/WTF/wtf/StackPointer.cpp index 70b18cfdcceac..529e52b015e25 100644 --- a/Source/WTF/wtf/StackPointer.cpp +++ b/Source/WTF/wtf/StackPointer.cpp @@ -96,6 +96,17 @@ asm ( ".previous" "\n" ); +#elif CPU(ARM64) && OS(WINDOWS) +asm ( + ".text" "\n" + ".balign 16" "\n" + ".globl " SYMBOL_STRING(currentStackPointer) "\n" + SYMBOL_STRING(currentStackPointer) ":" "\n" + + "mov x0, sp" "\n" + "ret" "\n" +); + #elif CPU(ARM64) asm ( ".text" "\n" diff --git a/Source/bmalloc/bmalloc/BPlatform.h b/Source/bmalloc/bmalloc/BPlatform.h index bd82d96566462..06132c9097153 100644 --- a/Source/bmalloc/bmalloc/BPlatform.h +++ b/Source/bmalloc/bmalloc/BPlatform.h @@ -149,7 +149,7 @@ #endif /* BCPU(ARM64) */ -#if defined(__arm64__) || defined(__aarch64__) +#if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) #define BCPU_ARM64 1 #if defined(__arm64e__) #define BCPU_ARM64E 1 diff --git a/Source/cmake/OptionsMSVC.cmake b/Source/cmake/OptionsMSVC.cmake index 53ca9e7941acc..cd5c5165464fa 100644 --- a/Source/cmake/OptionsMSVC.cmake +++ b/Source/cmake/OptionsMSVC.cmake @@ -65,7 +65,17 @@ add_link_options(/INCREMENTAL:NO) string(REGEX MATCH "^[0-9]+" CLANG_CL_MAJOR_VERSION ${CMAKE_CXX_COMPILER_VERSION}) cmake_path(REMOVE_FILENAME CMAKE_CXX_COMPILER OUTPUT_VARIABLE CLANG_CL_DIR) cmake_path(APPEND CLANG_CL_DIR "../lib/clang" ${CLANG_CL_MAJOR_VERSION} "lib/windows") -find_library(CLANG_BUILTINS_LIBRARY clang_rt.builtins-x86_64 PATHS ${CLANG_CL_DIR} REQUIRED NO_DEFAULT_PATH) + +# Detect the correct architecture for clang runtime library +if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64") + set(CLANG_RT_ARCH "aarch64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64") + set(CLANG_RT_ARCH "x86_64") +else() + set(CLANG_RT_ARCH "x86_64") # Default fallback +endif() + +find_library(CLANG_BUILTINS_LIBRARY clang_rt.builtins-${CLANG_RT_ARCH} PATHS ${CLANG_CL_DIR} REQUIRED NO_DEFAULT_PATH) link_libraries(${CLANG_BUILTINS_LIBRARY}) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608") diff --git a/arm64-windows-static.cmake b/arm64-windows-static.cmake new file mode 100644 index 0000000000000..bee374ce8ff9d --- /dev/null +++ b/arm64-windows-static.cmake @@ -0,0 +1,10 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Windows) + +# Use static runtime library +set(VCPKG_CXX_FLAGS "/MT") +set(VCPKG_C_FLAGS "/MT") +set(VCPKG_CXX_FLAGS_DEBUG "/MTd") +set(VCPKG_C_FLAGS_DEBUG "/MTd") \ No newline at end of file diff --git a/jit_crash_test.js b/jit_crash_test.js new file mode 100644 index 0000000000000..1551daaeed417 --- /dev/null +++ b/jit_crash_test.js @@ -0,0 +1,18 @@ +// Test to trigger JIT compilation and potential crash +function hotFunction(x) { + let result = 0; + for (let i = 0; i < 1000; i++) { + result += x * i + Math.sin(i) + Math.cos(x); + } + return result; +} + +// Call it many times to trigger JIT compilation +print("Starting JIT crash test..."); +for (let i = 0; i < 10000; i++) { + if (i % 1000 === 0) { + print("Iteration " + i); + } + hotFunction(i); +} +print("Test completed successfully"); \ No newline at end of file diff --git a/minimal_jit_crash.js b/minimal_jit_crash.js new file mode 100644 index 0000000000000..104c3669eba3d --- /dev/null +++ b/minimal_jit_crash.js @@ -0,0 +1,15 @@ +// Minimal test to trigger JIT compilation crash +function hotFunction(n) { + var sum = 0; + for (var i = 0; i < n; i++) { + sum += i * 2; + } + return sum; +} + +// Trigger JIT by calling many times with different values +for (var j = 0; j < 15000; j++) { + hotFunction(100); +} + +print("Finished without crash"); \ No newline at end of file diff --git a/windows-release.ps1 b/windows-release.ps1 index 3d01dcd095574..335ec70cf20fe 100644 --- a/windows-release.ps1 +++ b/windows-release.ps1 @@ -7,18 +7,52 @@ param( ) $ErrorActionPreference = "Stop" + # Set up MSVC environment variables. This is taken from Bun's 'scripts\env.ps1' +# Check for ARM64 environment +$processor = Get-WmiObject Win32_Processor +$isARM64 = ($processor.Architecture -eq 12 -or $env:BUILD_ARM64 -eq "1") + +if ($isARM64) { + Write-Host "Building for ARM64 architecture" +} + +# Try to load VS environment if available if ($env:VSINSTALLDIR -eq $null) { Write-Host "Loading Visual Studio environment, this may take a second..." - $vsDir = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\2022" -Directory - if ($vsDir -eq $null) { - throw "Visual Studio directory not found." - } - Push-Location $vsDir - try { - . (Join-Path -Path $vsDir.FullName -ChildPath "Common7\Tools\Launch-VsDevShell.ps1") -Arch amd64 -HostArch amd64 + # Check both Program Files locations for VS 2022 + $vsDir = $null + if (Test-Path "C:\Program Files\Microsoft Visual Studio\2022") { + $vsDir = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\2022" -Directory | Select-Object -First 1 + } elseif (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2022") { + $vsDir = Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio\2022" -Directory | Select-Object -First 1 + } + + if ($vsDir -ne $null -and (Test-Path (Join-Path -Path $vsDir.FullName -ChildPath "Common7\Tools\Launch-VsDevShell.ps1"))) { + Push-Location $vsDir.FullName + try { + # Detect the target architecture + $targetArch = if ($isARM64) { "arm64" } else { "amd64" } + + Write-Host "Target Architecture: $targetArch" + . (Join-Path -Path $vsDir.FullName -ChildPath "Common7\Tools\Launch-VsDevShell.ps1") -Arch $targetArch + + # Verify and force the environment for native ARM64 + Write-Host "After VS setup:" + Write-Host " VSCMD_ARG_TGT_ARCH: $env:VSCMD_ARG_TGT_ARCH" + Write-Host " PROCESSOR_ARCHITECTURE: $env:PROCESSOR_ARCHITECTURE" + + if ($isARM64) { + # Force native ARM64 environment + $env:PROCESSOR_ARCHITECTURE = "ARM64" + $env:VSCMD_ARG_TGT_ARCH = "arm64" + Write-Host "Forced ARM64 environment variables" + } + } + finally { Pop-Location } + } else { + Write-Host "Visual Studio developer shell not found, using clang-cl directly" } - finally { Pop-Location } } if ($Env:VSCMD_ARG_TGT_ARCH -eq "x86") { @@ -26,16 +60,21 @@ if ($Env:VSCMD_ARG_TGT_ARCH -eq "x86") { throw "Visual Studio environment is targetting 32 bit. This configuration is definetly a mistake." } -# Fix up $PATH -Write-Host $env:PATH +# Set COMSPEC to ensure we use Windows command processor +$env:COMSPEC = "$env:SystemRoot\system32\cmd.exe" + +Write-Host "Using original PATH without cleaning" -$MakeExe = (Get-Command make).Path +# Get make executable (should be available from dependency installation) +$MakeExe = if (Get-Command make -ErrorAction SilentlyContinue) { + (Get-Command make).Path +} else { + Write-Host "Warning: make command not found in PATH" + $null +} -$SplitPath = $env:PATH -split ";"; -$MSVCPaths = $SplitPath | Where-Object { $_ -like "Microsoft Visual Studio" } -$SplitPath = $MSVCPaths + ($SplitPath | Where-Object { $_ -notlike "Microsoft Visual Studio" } | Where-Object { $_ -notlike "*mingw*" }) -$PathWithPerl = $SplitPath -join ";" -$env:PATH = ($SplitPath | Where-Object { $_ -notlike "*strawberry*" }) -join ';' +# Keep a copy of PATH with Perl for later use (some WebKit scripts need it) +$PathWithPerl = $env:PATH if($ExtraEffortPathManagement) { $SedPath = $(& cygwin.exe -c 'where sed') @@ -47,9 +86,14 @@ if($ExtraEffortPathManagement) { $env:PATH = "$LinkDir;$SedDir;$PathWithPerl" } -Write-Host $env:PATH +# Show clang-cl version but don't fail if link isn't found (we'll use lld-link) +try { + $linkPath = (Get-Command link -ErrorAction SilentlyContinue).Path + if ($linkPath) { + Write-Host "Found link at: $linkPath" + } +} catch { } -(Get-Command link).Path clang-cl.exe --version $env:CC = "clang-cl" @@ -60,110 +104,121 @@ $WebKitBuild = if ($env:WEBKIT_BUILD_DIR) { $env:WEBKIT_BUILD_DIR } else { "WebK $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) } -# WebKit/JavaScriptCore requires being linked against the dynamic ICU library, -# but we do not want Bun to ship with DLLs, so we build ICU statically and -# link against that. This means we need both the static and dynamic build of -# ICU, once to link webkit, and second to link bun. -# -# I spent a few hours trying to find a way to get it to work with just the -# static library, did not get any meaningful results. -# -# Note that Bun works fine when you use this dual library technique. -# TODO: update to 75.1. It seems that additional CFLAGS need to be passed here. -$ICU_SOURCE_URL = "https://github.com/unicode-org/icu/releases/download/release-73-2/icu4c-73_2-src.tgz" - -$ICU_STATIC_ROOT = Join-Path $WebKitBuild "icu" -$ICU_STATIC_LIBRARY = Join-Path $ICU_STATIC_ROOT "lib" -$ICU_STATIC_INCLUDE_DIR = Join-Path $ICU_STATIC_ROOT "include" +# Use vcpkg for ICU - packages are installed in project directory +$UseVcpkg = $true +$VcpkgRoot = if ($env:VCPKG_ROOT) { $env:VCPKG_ROOT } else { "C:\vcpkg" } -$null = mkdir $WebKitBuild -ErrorAction SilentlyContinue +# vcpkg installs packages in the project directory when using manifest mode +$triplet = if ($isARM64) { "arm64-windows-static" } else { "x64-windows-static" } +$VcpkgInstalled = Join-Path (Get-Location) "vcpkg_installed\$triplet" -if (!(Test-Path -Path $ICU_STATIC_ROOT)) { - $ICU_STATIC_TAR = Join-Path $WebKitBuild "icu4c-src.tgz" +# Set up ICU paths based on whether we're using vcpkg or building from source +if ($UseVcpkg) { + Write-Host ":: Using vcpkg for ICU" - if (!(Test-Path $ICU_STATIC_TAR)) { - Write-Host ":: Downloading ICU" - Invoke-WebRequest -Uri $ICU_SOURCE_URL -OutFile $ICU_STATIC_TAR + # Ensure vcpkg dependencies are installed with static CRT + if (-not (Test-Path "$VcpkgInstalled\include\unicode")) { + Write-Host ":: Installing ICU via vcpkg with static CRT" + + # Create custom triplet for static linking + $TripletName = if ($isARM64) { "arm64-windows-static" } else { "x64-windows-static" } + $TripletFile = Join-Path $VcpkgRoot "triplets\community\$TripletName.cmake" + + # Create community triplets directory if it doesn't exist + $TripletsDir = Join-Path $VcpkgRoot "triplets\community" + if (-not (Test-Path $TripletsDir)) { + New-Item -ItemType Directory -Path $TripletsDir -Force | Out-Null + } + + if (-not (Test-Path $TripletFile)) { + $vcpkgArch = if ($isARM64) { "arm64" } else { "x64" } + # Base the custom triplet on the standard Windows triplet + $TripletContent = @" +set(VCPKG_TARGET_ARCHITECTURE $vcpkgArch) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) + +# Use the default Windows settings for everything else +if(PORT MATCHES "icu") + # Force ICU to build as static libraries + set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DBUILD_SHARED_LIBS=OFF) +endif() +"@ + Set-Content -Path $TripletFile -Value $TripletContent + Write-Host "Created custom triplet: $TripletFile" + } + + # Ensure vcpkg can find the compiler + $env:CC = "cl" + $env:CXX = "cl" + & vcpkg install --triplet $TripletName + # Reset to clang-cl for WebKit build + $env:CC = "clang-cl" + $env:CXX = "clang-cl" + if ($LASTEXITCODE -ne 0) { throw "vcpkg install failed with exit code $LASTEXITCODE" } } - Write-Host ":: Extracting ICU" - tar.exe -xzf $ICU_STATIC_TAR -C $WebKitBuild - if ($LASTEXITCODE -ne 0) { throw "tar failed with exit code $LASTEXITCODE" } - - # two patches needed to build statically with clang-cl - # 1. fix build script to align with bun's compiler requirements - # a. replace references to `cl` with `clang-cl` from configure - # b. use -MT instead of -MD to statically link the C runtime - # c. enable debug build for Debug configuration - $ConfigureFile = Get-Content "$ICU_STATIC_ROOT/source/runConfigureICU" -Raw - $ConfigureFile = $ConfigureFile -replace "=cl", "=clang-cl" - if ($CMAKE_BUILD_TYPE -eq "Debug") { - $ConfigureFile = $ConfigureFile -replace "debug=0", "debug=1" - $ConfigureFile = $ConfigureFile -replace "release=1", "release=0" - $ConfigureFile = $ConfigureFile -replace "-MDd", "-MTd /DU_STATIC_IMPLEMENTATION" - } else { - $ConfigureFile = $ConfigureFile -replace "-MD'", "-MT /DU_STATIC_IMPLEMENTATION'" - } - - Set-Content "$ICU_STATIC_ROOT/source/runConfigureICU" $ConfigureFile -NoNewline -Encoding UTF8 + $ICU_STATIC_ROOT = $VcpkgInstalled + $ICU_STATIC_LIBRARY = Join-Path $ICU_STATIC_ROOT "lib" + $ICU_STATIC_INCLUDE_DIR = Join-Path $ICU_STATIC_ROOT "include" - Push-Location $ICU_STATIC_ROOT/source - try { - Write-Host ":: Configuring ICU Build" - - if ($CMAKE_BUILD_TYPE -eq "Release") { - bash.exe ./runConfigureICU Cygwin/MSVC ` - --enable-static ` - --disable-shared ` - --with-data-packaging=static ` - --disable-samples ` - --disable-tests ` - --disable-debug ` - --enable-release - } elseif ($CMAKE_BUILD_TYPE -eq "Debug") { - bash.exe ./runConfigureICU Cygwin/MSVC ` - --enable-static ` - --disable-shared ` - --with-data-packaging=static ` - --disable-samples ` - --disable-tests ` - --enable-debug ` - --disable-release + # Find and configure ICU static libraries + Write-Host "ICU library files found:" + if (Test-Path $ICU_STATIC_LIBRARY) { + # Get ALL ICU libraries, not just specific ones + $allIcuLibs = Get-ChildItem "$ICU_STATIC_LIBRARY\*icu*.lib" | Sort-Object Name + + Write-Host " All ICU libraries in directory:" + $allIcuLibs | ForEach-Object { Write-Host " $($_.Name)" } + + # Create library list for CMake - include ALL ICU libraries + $ICU_LIBRARY_LIST = @() + + # Add all ICU libraries to the list, prioritizing static versions (s prefix) + foreach ($lib in $allIcuLibs) { + # Skip debug libraries (d suffix before version number) + if ($lib.Name -notmatch "icud\d+\.lib" -and $lib.Name -notmatch "sicud\d+\.lib") { + $ICU_LIBRARY_LIST += $lib.FullName + } } - - if ($LASTEXITCODE -ne 0) { - Get-Content "config.log" - throw "runConfigureICU failed with exit code $LASTEXITCODE" + + # Also look for specific required libraries to ensure they're present + $requiredLibs = @{ + "UC" = "s?icuuc" + "I18N" = "s?icui.*n|s?icuin" + "Data" = "s?icudt|s?icudata" + "IO" = "s?icuio" + "TU" = "s?icutu" # ICU Tool Util + "Test" = "s?icutest" # ICU Test } - - Write-Host ":: Building ICU" - & $MakeExe "-j$((Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors)" - if ($LASTEXITCODE -ne 0) { throw "make failed with exit code $LASTEXITCODE" } - } - finally { Pop-Location } - - $null = mkdir -Force $ICU_STATIC_INCLUDE_DIR/unicode - Copy-Item -r $ICU_STATIC_ROOT/source/common/unicode/* $ICU_STATIC_INCLUDE_DIR/unicode - Copy-Item -r $ICU_STATIC_ROOT/source/i18n/unicode/* $ICU_STATIC_INCLUDE_DIR/unicode - $null = mkdir -Force $ICU_STATIC_LIBRARY - Copy-Item -r $ICU_STATIC_ROOT/source/lib/* $ICU_STATIC_LIBRARY/ - - # JSC expects the static library to be named icudt.lib - if ($CMAKE_BUILD_TYPE -eq "Release") { - Move-Item $ICU_STATIC_LIBRARY/sicudt.lib $ICU_STATIC_LIBRARY/icudt.lib - Move-Item $ICU_STATIC_LIBRARY/sicutu.lib $ICU_STATIC_LIBRARY/icutu.lib - Move-Item $ICU_STATIC_LIBRARY/sicuio.lib $ICU_STATIC_LIBRARY/icuio.lib - Move-Item $ICU_STATIC_LIBRARY/sicuin.lib $ICU_STATIC_LIBRARY/icuin.lib - Move-Item $ICU_STATIC_LIBRARY/sicuuc.lib $ICU_STATIC_LIBRARY/icuuc.lib - } elseif ($CMAKE_BUILD_TYPE -eq "Debug") { - Move-Item $ICU_STATIC_LIBRARY/sicudtd.lib $ICU_STATIC_LIBRARY/icudt.lib - Move-Item $ICU_STATIC_LIBRARY/sicutud.lib $ICU_STATIC_LIBRARY/icutu.lib - Move-Item $ICU_STATIC_LIBRARY/sicuiod.lib $ICU_STATIC_LIBRARY/icuio.lib - Move-Item $ICU_STATIC_LIBRARY/sicuind.lib $ICU_STATIC_LIBRARY/icuin.lib - Move-Item $ICU_STATIC_LIBRARY/sicuucd.lib $ICU_STATIC_LIBRARY/icuuc.lib + + foreach ($libType in $requiredLibs.Keys) { + $pattern = $requiredLibs[$libType] + $found = $allIcuLibs | Where-Object { $_.Name -match $pattern } + if ($found) { + Write-Host " Found $libType lib: $($found[0].Name)" + } else { + Write-Host " WARNING: ICU $libType library not found (pattern: $pattern)" + } + } + + Write-Host "ICU Libraries configured for linking ($($ICU_LIBRARY_LIST.Count) libraries):" + $ICU_LIBRARY_LIST | ForEach-Object { Write-Host " $($_ | Split-Path -Leaf)" } + + # Set ICU library paths for CMake + $ICU_LIBRARIES_FOR_CMAKE = $ICU_LIBRARY_LIST -join ";" + } else { + Write-Host " ICU library directory not found: $ICU_STATIC_LIBRARY" + $ICU_LIBRARIES_FOR_CMAKE = "" } +} else { + Write-Host ":: Building ICU from source" + # Original ICU build code would go here, but we'll skip it for now + throw "Manual ICU build not implemented - please install vcpkg" } +$null = mkdir $WebKitBuild -ErrorAction SilentlyContinue + Write-Host ":: Configuring WebKit" $env:PATH = $PathWithPerl @@ -171,6 +226,10 @@ $env:PATH = $PathWithPerl $env:CFLAGS = "/Zi" $env:CXXFLAGS = "/Zi" +# Set CC and CXX for the inspector preprocessor script +$env:CC = "clang-cl" +$env:CXX = "clang-cl" + $CmakeMsvcRuntimeLibrary = "MultiThreaded" if ($CMAKE_BUILD_TYPE -eq "Debug") { $CmakeMsvcRuntimeLibrary = "MultiThreadedDebug" @@ -179,8 +238,96 @@ if ($CMAKE_BUILD_TYPE -eq "Debug") { $NoWebassembly = if ($env:NO_WEBASSEMBLY) { $env:NO_WEBASSEMBLY } else { $false } $WebAssemblyState = if ($NoWebassembly) { "OFF" } else { "ON" } +# Set architecture for CMake +$CmakeArch = if ($isARM64) { "ARM64" } else { "X64" } + +# Set vcpkg toolchain file if using vcpkg +$VcpkgToolchain = if ($UseVcpkg) { + "-DCMAKE_TOOLCHAIN_FILE=$VcpkgRoot/scripts/buildsystems/vcpkg.cmake", + "-DVCPKG_TARGET_TRIPLET=$triplet", + "-DVCPKG_OVERLAY_TRIPLETS=$VcpkgRoot/triplets/community", + "-DVCPKG_MANIFEST_MODE=OFF" # We already installed packages manually +} else { @() } + +# Detect Ruby installation (WinGet or Scoop) +$RubyPath = $null +$GemPath = $null + +# Try WinGet installation first +if (Test-Path "C:\Program Files\Ruby\bin\ruby.exe") { + $RubyPath = "C:\Program Files\Ruby\bin\ruby.exe" + $GemPath = "C:\Program Files\Ruby\bin\gem.cmd" +} elseif (Test-Path "C:\Users\$env:USERNAME\scoop\apps\ruby\current\bin\ruby.exe") { + # Fall back to Scoop installation + $RubyPath = "C:\Users\$env:USERNAME\scoop\apps\ruby\current\bin\ruby.exe" + $GemPath = "C:\Users\$env:USERNAME\scoop\apps\ruby\current\bin\gem.cmd" +} else { + # Try to find Ruby in PATH + $RubyCmd = Get-Command ruby -ErrorAction SilentlyContinue + if ($RubyCmd) { + $RubyPath = $RubyCmd.Source + $GemCmd = Get-Command gem -ErrorAction SilentlyContinue + $GemPath = if ($GemCmd) { $GemCmd.Source } else { $null } + } +} + +# Install required Ruby gems for WebKit build +Write-Host ":: Checking Ruby dependencies" +$RequiredGems = @("getoptlong") +foreach ($gem in $RequiredGems) { + Write-Host " Checking for gem: $gem" + $gemCheck = & gem list $gem 2>&1 + if ($gemCheck -notlike "*$gem*") { + Write-Host " Installing missing gem: $gem" + & gem install $gem --no-document + if ($LASTEXITCODE -ne 0) { + Write-Host " Warning: Failed to install $gem, build may fail" + } + } +} + +# Check for ccache +$CcacheLauncher = @() +$CcachePath = Get-Command ccache -ErrorAction SilentlyContinue +if ($CcachePath) { + Write-Host ":: Found ccache at $($CcachePath.Source), enabling compiler cache" + $CcacheLauncher = @( + "-DCMAKE_C_COMPILER_LAUNCHER=ccache", + "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" + ) +} else { + Write-Host ":: ccache not found, building without compiler cache" +} + +# Build CMake ICU configuration +$ICUCmakeArgs = @() +if ($UseVcpkg) { + # When using vcpkg toolchain, let it handle ICU discovery + # But we still need to ensure all ICU components are linked + if ($ICU_LIBRARIES_FOR_CMAKE) { + # Pass all ICU libraries explicitly to ensure they're all linked + $ICUCmakeArgs += "-DICU_LIBRARIES=$ICU_LIBRARIES_FOR_CMAKE" + Write-Host "Passing ICU libraries to CMake: $ICU_LIBRARIES_FOR_CMAKE" + } + + # Also pass the root paths for ICU + $ICUCmakeArgs += "-DICU_ROOT=${ICU_STATIC_ROOT}" + $ICUCmakeArgs += "-DICU_INCLUDE_DIR=${ICU_STATIC_INCLUDE_DIR}" + + # Ensure ICU is enabled + $ICUCmakeArgs += "-DUSE_ICU=ON" + + Write-Host "CMake ICU configuration:" + $ICUCmakeArgs | ForEach-Object { Write-Host " $_" } +} + +# ARM64 needs to disable asynchronous unwind tables to avoid SEH crashes +$UnwindTablesFlag = if ($isARM64) { "/clang:-fno-asynchronous-unwind-tables " } else { "" } + cmake -S . -B $WebKitBuild ` -DPORT="JSCOnly" ` + "-DCMAKE_SYSTEM_PROCESSOR=${CmakeArch}" ` + @CcacheLauncher ` -DENABLE_STATIC_JSC=ON ` -DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON ` "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" ` @@ -196,17 +343,17 @@ cmake -S . -B $WebKitBuild ` -DUSE_BUN_EVENT_LOOP=ON ` -DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON ` -DUSE_SYSTEM_MALLOC=ON ` - "-DICU_ROOT=${ICU_STATIC_ROOT}" ` - "-DICU_LIBRARY=${ICU_STATIC_LIBRARY}" ` - "-DICU_INCLUDE_DIR=${ICU_STATIC_INCLUDE_DIR}" ` + @ICUCmakeArgs ` + "-DRuby_EXECUTABLE=${RubyPath}" ` "-DCMAKE_C_COMPILER=clang-cl" ` "-DCMAKE_CXX_COMPILER=clang-cl" ` - "-DCMAKE_C_FLAGS_RELEASE=/Zi /O2 /Ob2 /DNDEBUG " ` - "-DCMAKE_CXX_FLAGS_RELEASE=/Zi /O2 /Ob2 /DNDEBUG -Xclang -fno-c++-static-destructors " ` - "-DCMAKE_C_FLAGS_DEBUG=/Zi /FS /O0 /Ob0 " ` - "-DCMAKE_CXX_FLAGS_DEBUG=/Zi /FS /O0 /Ob0 -Xclang -fno-c++-static-destructors " ` + "-DCMAKE_C_FLAGS_RELEASE=/Zi /O2 /Ob2 /DNDEBUG ${UnwindTablesFlag}" ` + "-DCMAKE_CXX_FLAGS_RELEASE=/Zi /O2 /Ob2 /DNDEBUG ${UnwindTablesFlag}" ` + "-DCMAKE_C_FLAGS_DEBUG=/Zi /FS /O0 /Ob0 ${UnwindTablesFlag}" ` + "-DCMAKE_CXX_FLAGS_DEBUG=/Zi /FS /O0 /Ob0 ${UnwindTablesFlag}" ` -DENABLE_REMOTE_INSPECTOR=ON ` "-DCMAKE_MSVC_RUNTIME_LIBRARY=${CmakeMsvcRuntimeLibrary}" ` + @VcpkgToolchain ` -G Ninja # TODO: "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" ` if ($LASTEXITCODE -ne 0) { throw "cmake failed with exit code $LASTEXITCODE" } @@ -248,19 +395,6 @@ if (Test-Path -Path $WebKitBuild/lib64) { Copy-Item $WebKitBuild/cmakeconfig.h $output/include/cmakeconfig.h -if ($CMAKE_BUILD_TYPE -eq "Release") { - Move-Item $ICU_STATIC_LIBRARY/icudt.lib $ICU_STATIC_LIBRARY/sicudt.lib - Move-Item $ICU_STATIC_LIBRARY/icutu.lib $ICU_STATIC_LIBRARY/sicutu.lib - Move-Item $ICU_STATIC_LIBRARY/icuio.lib $ICU_STATIC_LIBRARY/sicuio.lib - Move-Item $ICU_STATIC_LIBRARY/icuin.lib $ICU_STATIC_LIBRARY/sicuin.lib - Move-Item $ICU_STATIC_LIBRARY/icuuc.lib $ICU_STATIC_LIBRARY/sicuuc.lib -} elseif ($CMAKE_BUILD_TYPE -eq "Debug") { - Move-Item $ICU_STATIC_LIBRARY/icudt.lib $ICU_STATIC_LIBRARY/sicudtd.lib - Move-Item $ICU_STATIC_LIBRARY/icutu.lib $ICU_STATIC_LIBRARY/sicutud.lib - Move-Item $ICU_STATIC_LIBRARY/icuio.lib $ICU_STATIC_LIBRARY/sicuiod.lib - Move-Item $ICU_STATIC_LIBRARY/icuin.lib $ICU_STATIC_LIBRARY/sicuind.lib - Move-Item $ICU_STATIC_LIBRARY/icuuc.lib $ICU_STATIC_LIBRARY/sicuucd.lib -} Add-Content -Path $output/include/cmakeconfig.h -Value "`#define BUN_WEBKIT_VERSION `"$BUN_WEBKIT_VERSION`""