mirror of
https://github.com/SerenityOS/serenity
synced 2026-04-25 17:15:42 +02:00
Meta: Patch up Apple SDK headers to work with C++26
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
54
Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py
Executable file
54
Meta/Lagom/Tools/patch_mac_sdk_headers_for_cxx26.py
Executable file
@@ -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()
|
||||
Reference in New Issue
Block a user