Files
termux-packages/packages/swift/swift-cmake.patch
2025-11-17 15:39:54 +00:00

314 lines
15 KiB
Diff

diff --git a/llvm-project/clang/runtime/CMakeLists.txt b/llvm-project/clang/runtime/CMakeLists.txt
index 61b1c60bf590..5b0d10a67699 100644
--- a/llvm-project/clang/runtime/CMakeLists.txt
+++ b/llvm-project/clang/runtime/CMakeLists.txt
@@ -75,6 +75,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
@@ -84,6 +85,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
+ -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
diff --git a/llvm-project/clang/tools/IndexStore/CMakeLists.txt b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
index 1bcfc0734785..ddb77c91b22d 100644
--- a/llvm-project/clang/tools/IndexStore/CMakeLists.txt
+++ b/llvm-project/clang/tools/IndexStore/CMakeLists.txt
@@ -65,7 +65,7 @@ if (LLVM_INSTALL_TOOLCHAIN_ONLY)
endif()
endif()
-set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "local/include")
+set(INDEXSTORE_HEADERS_INSTALL_DESTINATION "include")
install(DIRECTORY ../../include/indexstore
COMPONENT IndexStore
diff --git a/llvm-project/cmake/Modules/HandleCompilerRT.cmake b/llvm-project/cmake/Modules/HandleCompilerRT.cmake
index ac9e0871489d..b495cbfb5c2e 100644
--- a/llvm-project/cmake/Modules/HandleCompilerRT.cmake
+++ b/llvm-project/cmake/Modules/HandleCompilerRT.cmake
@@ -77,7 +77,7 @@
set(cmd_prefix "/clang:")
endif()
execute_process(
- COMMAND ${clang_command} "${cmd_prefix}--rtlib=compiler-rt" "${cmd_prefix}-print-libgcc-file-name"
+ COMMAND ${clang_command} "${cmd_prefix}--rtlib=compiler-rt" "${cmd_prefix}-print-libgcc-file-name" "-resource-dir=$ENV{PREFIX}/lib/clang/latest/"
RESULT_VARIABLE had_error
OUTPUT_VARIABLE library_file
)
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index b7503ecdd6..c643c2c9a5 100644
--- a/swift/CMakeLists.txt
+++ b/swift/CMakeLists.txt
@@ -463,7 +463,7 @@ set(SWIFT_BUILD_HOST_DISPATCH FALSE)
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Only build libdispatch for the host if the host tools are being built and
# specifically if these two libraries that depend on it are built.
- if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SOURCEKIT)
+ if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Android AND SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SOURCEKIT)
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
endif()
@@ -966,7 +966,7 @@ if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined")
set(BOOTSTRAPPING_MODE "OFF")
endif()
- elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
+ elseif(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS")
# If cross-compiling, we don't have to bootstrap. We can just use the previously
# built native swiftc to build the swift compiler modules.
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
@@ -976,7 +976,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
else()
- set(BOOTSTRAPPING_MODE "HOSTTOOLS")
+ set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
endif()
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
# We are building using a pre-installed host toolchain but not bootstrapping
@@ -1279,7 +1280,8 @@ if (LLVM_ENABLE_DOXYGEN)
message(STATUS "Doxygen: enabled")
endif()
-if(SWIFT_ENABLE_DISPATCH)
+# Use the Termux libdispatch when cross-compiling instead.
+if(SWIFT_ENABLE_DISPATCH AND ${CMAKE_HOST_SYSTEM_NAME} STREQUAL Android)
include(Libdispatch)
endif()
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index ed28ab1891d..b7aa589f909 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -374,6 +374,8 @@ function(_add_host_variant_link_flags target)
# We need to add the math library, which is linked implicitly by libc++
m)
+ target_link_options(${target} PRIVATE "SHELL:-Xlinker -z -Xlinker max-page-size=16384")
+
# link against the custom C++ library
swift_android_cxx_libraries_for_arch(${SWIFT_HOST_VARIANT_ARCH}
cxx_link_libraries)
diff --git a/swift/cmake/modules/SwiftCompilerCapability.cmake b/swift/cmake/modules/SwiftCompilerCapability.cmake
index d7d4381a1a7..d8c05dc6a75 100644
--- a/swift/cmake/modules/SwiftCompilerCapability.cmake
+++ b/swift/cmake/modules/SwiftCompilerCapability.cmake
@@ -39,7 +39,6 @@ function(swift_get_package_cmo_support out_var)
# > 6.0 : Fixed feature.
swift_supports_compiler_arguments(result
-package-name my-package
- -enable-library-evolution
-Xfrontend -package-cmo
-Xfrontend -allow-non-resilient-access
)
diff --git a/swift/lib/CompilerSwiftSyntax/CMakeLists.txt b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt
index 849cf90fee0..f2a08df0e57 100644
--- a/swift/lib/CompilerSwiftSyntax/CMakeLists.txt
+++ b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt
@@ -49,6 +49,9 @@ set(compiler_swiftsyntax_libs
foreach(lib ${compiler_swiftsyntax_libs})
target_compile_options(${lib} PRIVATE "SHELL:-module-link-name ${lib}")
+ if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
+ add_dependencies(${lib} swift-stdlib-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
+ endif()
endforeach()
swift_install_in_component(TARGETS ${compiler_swiftsyntax_libs}
diff --git a/swift/SwiftCompilerSources/CMakeLists.txt b/swift/SwiftCompilerSources/CMakeLists.txt
--- a/swift/SwiftCompilerSources/CMakeLists.txt
+++ b/swift/SwiftCompilerSources/CMakeLists.txt
@@ -162,6 +162,7 @@ function(add_swift_compiler_modules_library name)
list(APPEND sdk_option "-resource-dir" "${swift_exec_bin_dir}/../bootstrapping0/lib/swift")
endif()
elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
+ set(deployment_version ${SWIFT_ANDROID_API_LEVEL})
# NOTE: prepending allows SWIFT_COMPILER_SOURCES_SDK_FLAGS to override the
# resource directory if needed.
list(PREPEND sdk_option "-resource-dir" "${SWIFTLIB_DIR}")
@@ -196,6 +196,8 @@
# Workaround for https://github.com/swiftlang/llvm-project/issues/7172
list(APPEND swift_compile_options "-Xcc" "-Xclang" "-Xcc" "-fmodule-format=raw")
+ elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
+ list(APPEND sdk_option "-I" "${SWIFTLIB_DIR}/../")
else()
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
endif()
diff --git a/swift/lib/SwiftSyntax/CMakeLists.txt b/swift/lib/SwiftSyntax/CMakeLists.txt
index 5c7bd65fead..36f3bbc1b91 100644
--- a/swift/lib/SwiftSyntax/CMakeLists.txt
+++ b/swift/lib/SwiftSyntax/CMakeLists.txt
@@ -80,6 +80,9 @@ endif()
# Install Swift module interface files.
foreach(module ${SWIFT_SYNTAX_MODULES})
+ if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
+ add_dependencies(${module} swift-stdlib-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
+ endif()
set(module_dir "${module}.swiftmodule")
set(module_file "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${SWIFT_HOST_MODULE_TRIPLE}")
swift_install_in_component(FILES "${module_file}.swiftinterface" "${module_file}.private.swiftinterface"
diff --git a/swift/localization/CMakeLists.txt b/swift/localization/CMakeLists.txt
index 07a3585a66c..461a98b6856 100644
--- a/swift/localization/CMakeLists.txt
+++ b/swift/localization/CMakeLists.txt
@@ -1,3 +1,4 @@
+if(NOT SWIFT_PREBUILT_SWIFT)
set(diagnostic_witness "${CMAKE_BINARY_DIR}/share/swift/diagnostics/generated")
add_custom_command(
@@ -32,3 +33,4 @@ swift_install_in_component(
PATTERN "*.yaml"
PATTERN "*.strings"
)
+endif()
diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
index 5021409ba06..bb5bc1a6fd4 100644
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -2508,6 +2508,10 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384")
endif()
+ if(sdk STREQUAL "ANDROID" AND name STREQUAL "swiftCxxStdlib")
+ list(APPEND swiftlib_swift_compile_flags_all "-target" "${SWIFT_SDK_ANDROID_ARCH_${arch}_TRIPLE}${SWIFT_ANDROID_API_LEVEL}")
+ endif()
+
if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY)
set(back_deployment_library_option BACK_DEPLOYMENT_LIBRARY ${SWIFTLIB_BACK_DEPLOYMENT_LIBRARY})
else()
diff --git a/swift/stdlib/public/Concurrency/CMakeLists.txt b/swift/stdlib/public/Concurrency/CMakeLists.txt
index 3313f56c8a6..59804ff6228 100644
--- a/swift/stdlib/public/Concurrency/CMakeLists.txt
+++ b/swift/stdlib/public/Concurrency/CMakeLists.txt
@@ -24,8 +24,8 @@ if(SWIFT_CONCURRENCY_USES_DISPATCH)
# FIXME: we can't rely on libdispatch having been built for the
# target at this point in the process. Currently, we're relying
# on soft-linking.
- list(APPEND swift_concurrency_link_libraries
- dispatch)
+ #list(APPEND swift_concurrency_link_libraries
+ # dispatch)
endif()
elseif("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "singlethreaded" OR
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "hooked" OR
@@ -120,6 +120,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY
${swift_concurrency_incorporate_object_libraries_so}
LINK_LIBRARIES ${swift_concurrency_link_libraries}
+ LINK_FLAGS "-ldispatch"
C_COMPILE_FLAGS
-Dswift_Concurrency_EXPORTS ${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS}
diff --git a/swift/stdlib/public/Platform/CMakeLists.txt b/swift/stdlib/public/Platform/CMakeLists.txt
index f958d4ce899..ac6d7248606 100644
--- a/swift/stdlib/public/Platform/CMakeLists.txt
+++ b/swift/stdlib/public/Platform/CMakeLists.txt
@@ -300,7 +300,7 @@
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
${swift_platform_compile_flags}
- LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
+ LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS};-landroid-posix-semaphore"
TARGET_SDKS "ANDROID"
INSTALL_IN_COMPONENT sdk-overlay
DEPENDS android_modulemap)
diff --git a/swift/stdlib/public/core/CMakeLists.txt b/swift/stdlib/public/core/CMakeLists.txt
index 27a4b2bbc6e..5469b3457a6 100644
--- a/swift/stdlib/public/core/CMakeLists.txt
+++ b/swift/stdlib/public/core/CMakeLists.txt
@@ -404,7 +404,7 @@ if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
endif()
set(tooling_stdlib_deps)
-if(TARGET libSwiftScan)
+if(NOT BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE" AND TARGET libSwiftScan)
list(APPEND tooling_stdlib_deps libSwiftScan)
endif()
diff --git a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
index 7a77e125f95..7eddfea2054 100644
--- a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
+++ b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
@@ -79,6 +79,9 @@ function(add_sourcekit_default_compiler_flags target)
endif()
target_compile_options(${target} PRIVATE
-fblocks)
+ # Look in Termux sysroot for dispatch/dispatch.h from libdispatch
+ target_include_directories("${target}" SYSTEM PRIVATE
+ ${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include)
endfunction()
function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
diff --git a/swift/tools/swift-compatibility-symbols/CMakeLists.txt b/swift/tools/swift-compatibility-symbols/CMakeLists.txt
index 11cda641cc2..bd2cb152725 100644
--- a/swift/tools/swift-compatibility-symbols/CMakeLists.txt
+++ b/swift/tools/swift-compatibility-symbols/CMakeLists.txt
@@ -1,3 +1,4 @@
+if(NOT SWIFT_PREBUILT_SWIFT)
add_swift_host_tool(swift-compatibility-symbols
swift-compatibility-symbols.cpp
LLVM_LINK_COMPONENTS support
@@ -26,3 +27,4 @@ swift_install_in_component(
compiler
)
endif()
+endif()
diff --git a/swift-corelibs-xctest/CMakeLists.txt b/swift-corelibs-xctest/CMakeLists.txt
index 531e7c0..589930f 100644
--- a/swift-corelibs-xctest/CMakeLists.txt
+++ b/swift-corelibs-xctest/CMakeLists.txt
@@ -58,6 +58,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
Foundation)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
target_link_options(XCTest PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ set_target_properties(XCTest PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
endif()
set_target_properties(XCTest PROPERTIES
diff --git a/swift-testing/CMakeLists.txt b/swift-testing/CMakeLists.txt
index 1be9a4b..bd7b1bd 100644
--- a/swift-testing/CMakeLists.txt
+++ b/swift-testing/CMakeLists.txt
@@ -28,6 +28,7 @@ list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake/modules
${PROJECT_SOURCE_DIR}/cmake/modules/shared)
+set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -39,7 +39,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_INSTALL_RPATH "$<IF:$<PLATFORM_ID:Darwin>,@loader_path/..,$ORIGIN>")
+set(CMAKE_INSTALL_RPATH "$<IF:$<PLATFORM_ID:Darwin>,@loader_path/..,@TERMUX_PREFIX@/lib:$ORIGIN>")
set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH YES)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
diff --git a/swift-testing/Sources/Testing/CMakeLists.txt b/swift-testing/Sources/Testing/CMakeLists.txt
index e40cb1b..ff2f920 100644
--- a/swift-testing/Sources/Testing/CMakeLists.txt
+++ b/swift-testing/Sources/Testing/CMakeLists.txt
@@ -110,7 +110,8 @@ target_link_libraries(Testing PRIVATE
if(NOT APPLE)
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
target_link_libraries(Testing PUBLIC
- dispatch)
+ dispatch android-execinfo)
+ target_link_directories(Testing PUBLIC ${CMAKE_FIND_ROOT_PATH}/usr/lib)
endif()
target_link_libraries(Testing PUBLIC
Foundation)