diff --git a/cmake/targets/BuildGhosttyVt.cmake b/cmake/targets/BuildGhosttyVt.cmake index 9921ef6a64..e8e774d47c 100644 --- a/cmake/targets/BuildGhosttyVt.cmake +++ b/cmake/targets/BuildGhosttyVt.cmake @@ -18,5 +18,58 @@ register_repository( v1.1.3 ) +# utfcpp - header-only UTF-8 library for error handling in SIMD code +register_repository( + NAME + utfcpp + REPOSITORY + nemtrif/utfcpp + TAG + v4.0.5 +) + # The ghostty source is cloned to ${VENDOR_PATH}/ghostty # Bun's build.zig will reference it directly as a Zig module + +# Build the SIMD acceleration library for ghostty +# This provides optimized UTF-8 decoding for terminal escape sequence parsing +set(GHOSTTY_SIMD_SRC ${VENDOR_PATH}/ghostty/src/simd/vt.cpp) + +add_library(ghostty-simd STATIC ${GHOSTTY_SIMD_SRC}) + +target_include_directories(ghostty-simd PRIVATE + # Bun's compatibility headers (simdutf.h wrapper) + ${CWD}/src/deps/ghostty + # Ghostty's own headers + ${VENDOR_PATH}/ghostty/src + # Highway SIMD library (from Bun's vendor) + ${BUILD_PATH}/highway + ${VENDOR_PATH}/highway + # simdutf from webkit + ${WEBKIT_INCLUDE_PATH} + ${WEBKIT_INCLUDE_PATH}/wtf + # utfcpp for UTF-8 error handling + ${VENDOR_PATH}/utfcpp/source +) + +target_compile_definitions(ghostty-simd PRIVATE + # Highway configuration + HWY_STATIC_DEFINE +) + +# Enable exceptions for this file only - utfcpp's replace_invalid uses them +set_source_files_properties(${GHOSTTY_SIMD_SRC} PROPERTIES + COMPILE_FLAGS "-fexceptions" +) + +# Ensure dependencies are built first +add_dependencies(ghostty-simd clone-ghostty clone-utfcpp) +if(TARGET highway) + add_dependencies(ghostty-simd highway) +endif() + +# Link ghostty-simd into bun +target_link_libraries(${bun} PRIVATE ghostty-simd) + +# Link highway library +target_link_libraries(${bun} PRIVATE ${BUILD_PATH}/highway/libhwy.a) diff --git a/src/deps/ghostty/build_options.zig b/src/deps/ghostty/build_options.zig index c2bb0dd18f..d47ea16635 100644 --- a/src/deps/ghostty/build_options.zig +++ b/src/deps/ghostty/build_options.zig @@ -2,8 +2,6 @@ //! This provides the build_options that ghostty's SIMD code expects. /// SIMD acceleration for optimized UTF-8 and escape sequence parsing. -/// Currently disabled because ghostty's SIMD uses C++ implementations (vt.cpp) -/// that would need to be built and linked separately. -/// The scalar fallback paths provide correct functionality. +/// Uses highway SIMD library with simdutf for fast UTF-8 decoding. /// Note: Keep in sync with terminal_options.simd -pub const simd = false; +pub const simd = true; diff --git a/src/deps/ghostty/simdutf.h b/src/deps/ghostty/simdutf.h new file mode 100644 index 0000000000..fa89501699 --- /dev/null +++ b/src/deps/ghostty/simdutf.h @@ -0,0 +1,5 @@ +// Wrapper header to include simdutf from webkit +// ghostty's vt.cpp expects but Bun provides it via webkit +#pragma once + +#include diff --git a/src/deps/ghostty/terminal_options.zig b/src/deps/ghostty/terminal_options.zig index f05fb9f5cf..51f7f446f2 100644 --- a/src/deps/ghostty/terminal_options.zig +++ b/src/deps/ghostty/terminal_options.zig @@ -16,10 +16,8 @@ pub const c_abi = false; pub const oniguruma = false; /// SIMD acceleration for optimized UTF-8 and escape sequence parsing. -/// Currently disabled because ghostty's SIMD uses C++ implementations (vt.cpp) -/// that would need to be built and linked separately. -/// The scalar fallback paths provide correct functionality. -pub const simd = false; +/// Uses highway SIMD library with simdutf for fast UTF-8 decoding. +pub const simd = true; /// Slow runtime safety checks - disabled in production pub const slow_runtime_safety = false;