diff --git a/Ladybird/AppKit/CMakeLists.txt b/Ladybird/AppKit/CMakeLists.txt index a7ed57105ba..7bdd3f47928 100644 --- a/Ladybird/AppKit/CMakeLists.txt +++ b/Ladybird/AppKit/CMakeLists.txt @@ -19,6 +19,11 @@ add_executable(ladybird MACOSX_BUNDLE Utilities/Conversions.mm ) target_include_directories(ladybird PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + +# FIXME: Remove this once https://openradar.appspot.com/21478051 is fixed. +add_dependencies(ladybird patched_mac_headers) +target_include_directories(ladybird PRIVATE "${CMAKE_BINARY_DIR}/patched_mac_headers") + target_link_libraries(ladybird PRIVATE "-framework Cocoa -framework UniformTypeIdentifiers" LibUnicode) target_compile_options(ladybird PRIVATE -fobjc-arc diff --git a/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt index e5e3009d3c3..1eb2ae328c1 100644 --- a/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt +++ b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt @@ -30,6 +30,10 @@ target_link_libraries(MacPDF PRIVATE "-framework UniformTypeIdentifiers" ) +# FIXME: Remove this once https://openradar.appspot.com/21478051 is fixed. +add_dependencies(MacPDF patched_mac_headers) +target_include_directories(MacPDF PRIVATE "${CMAKE_BINARY_DIR}/patched_mac_headers") + set_target_properties(MacPDF PROPERTIES MACOSX_BUNDLE TRUE diff --git a/Meta/Lagom/Tools/CMakeLists.txt b/Meta/Lagom/Tools/CMakeLists.txt index c5d58d9a699..2cdd2dfd249 100644 --- a/Meta/Lagom/Tools/CMakeLists.txt +++ b/Meta/Lagom/Tools/CMakeLists.txt @@ -17,3 +17,16 @@ add_subdirectory(PrekernelPEImageGenerator) add_subdirectory(IPCMagicLinter) include(jakt) + +if (APPLE) + # FIXME: Remove this once https://openradar.appspot.com/21478051 is fixed. + find_package(Python3 REQUIRED COMPONENTS Interpreter) + add_custom_command( + OUTPUT "${CMAKE_BINARY_DIR}/patched_mac_headers/stamp" + COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py" -o "${CMAKE_BINARY_DIR}/patched_mac_headers" --sdk-path "${CMAKE_OSX_SYSROOT}" + COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_BINARY_DIR}/patched_mac_headers/stamp" + VERBATIM + DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py" + ) + add_custom_target(patched_mac_headers DEPENDS "${CMAKE_BINARY_DIR}/patched_mac_headers/stamp") +endif() diff --git a/Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py b/Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py new file mode 100755 index 00000000000..2e7010384ef --- /dev/null +++ b/Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +# In Xcode 26.2, Cocoa.h doesn't compile with -std=c++26, +# https://openradar.appspot.com/21478051 +# +# This patches up bad headers in the meantime. +# +# Use like this, and add `foobar` to your include search path: +# Meta/Lagom/patch_mac_sdk_headers_for_cxx26.py -o foobar --sdk_path $(xcrun --show-sdk-path) + + +import argparse +import os +import subprocess + + +patches = { + "CoreGraphics/CGImage.h": [ + ( + 'return alpha | component | byteOrder | pixelFormat;', + 'return (CGBitmapInfo)((CGBitmapInfo)alpha | (CGBitmapInfo)component | (CGBitmapInfo)byteOrder | (CGBitmapInfo)pixelFormat);' # noqa: E501 + ), + ], +} + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--sdk-path', help='Path to Mac SDK', required=True) + parser.add_argument('-o', '--output-dir', help='Output path for the patched header files', required=True) + args = parser.parse_args() + + sdk_path = args.sdk_path + if not sdk_path: + sdk_path = subprocess.check_output(['xcrun', '--show-sdk-path']).decode().strip() + + for relative_path, replacements in patches.items(): + framework_name, header_name = relative_path.split("/") + sdk_file_path = f'{sdk_path}/System/Library/Frameworks/{framework_name}.framework/Headers/{header_name}' + with open(sdk_file_path, "r") as f: + content = f.read() + + for old, new in replacements: + content = content.replace(old, new) + + output_path = f'{args.output_dir}/{relative_path}' + os.makedirs(os.path.dirname(output_path), exist_ok=True) + + with open(output_path, "w") as f: + f.write(content) + + +if __name__ == '__main__': + main()