mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
feat(terminal): enable SIMD acceleration for ghostty VT parsing
- Build ghostty's C++ SIMD implementation (vt.cpp) using highway - Configure simdutf via webkit wrapper header - Add utfcpp dependency for UTF-8 error handling with replacement chars - Enable exceptions for vt.cpp only (required by utfcpp) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
5
src/deps/ghostty/simdutf.h
Normal file
5
src/deps/ghostty/simdutf.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// Wrapper header to include simdutf from webkit
|
||||
// ghostty's vt.cpp expects <simdutf.h> but Bun provides it via webkit
|
||||
#pragma once
|
||||
|
||||
#include <wtf/SIMDUTF.h>
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user