Skip to content

Commit 3f9cb7b

Browse files
committed
android: hardcode ICU path, add NDK to sysroot, started copying link/compile job pools from LLVM's cmake list, force -j1 and split dwarfs when compiling
1 parent a6087d9 commit 3f9cb7b

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ set(SWIFT_NATIVE_CLANG_TOOLS_PATH "" CACHE STRING
117117
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "" CACHE STRING
118118
"Path to the directory that contains Swift tools that are executable on the build machine")
119119

120+
# The following only works with the Ninja generator in CMake >= 3.0.
121+
set(SWIFT_PARALLEL_COMPILE_JOBS "" CACHE STRING
122+
"Define the maximum number of concurrent compilation jobs.")
123+
if(SWIFT_PARALLEL_COMPILE_JOBS)
124+
if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
125+
message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
126+
else()
127+
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${SWIFT_PARALLEL_COMPILE_JOBS})
128+
set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
129+
endif()
130+
endif()
131+
132+
set(SWIFT_PARALLEL_LINK_JOBS "1" CACHE STRING
133+
"Define the maximum number of concurrent link jobs.")
134+
if(SWIFT_PARALLEL_LINK_JOBS)
135+
if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
136+
message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
137+
else()
138+
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${SWIFT_PARALLEL_LINK_JOBS})
139+
set(CMAKE_JOB_POOL_LINK link_job_pool)
140+
endif()
141+
endif()
120142
#
121143
# User-configurable Darwin-specific options.
122144
#
@@ -408,6 +430,8 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
408430
is_sdk_requested(ANDROID swift_build_android)
409431
if(swift_build_android AND ${swift_can_crosscompile_stdlib})
410432
configure_sdk_unix(ANDROID "Android" "android" "android" "armv7" "armv7-none-linux-androideabi")
433+
set(SWIFT_SDK_ANDROID_PATH "/home/zhuowei/ndk/platforms/android-16/arch-arm")
434+
411435
set(SWIFT_PRIMARY_VARIANT_SDK_default "ANDROID")
412436
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
413437
endif()

cmake/modules/AddSwift.cmake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ function(_add_variant_c_compile_link_flags
4848
list(APPEND result
4949
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}")
5050

51+
if("${sdk}" STREQUAL "ANDROID")
52+
list(APPEND result
53+
"--sysroot=${SWIFT_SDK_${sdk}_PATH}")
54+
endif()
55+
56+
5157
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
5258
list(APPEND result
5359
"-arch" "${arch}"
@@ -94,6 +100,12 @@ function(_add_variant_c_compile_flags
94100
list(APPEND result "-DNDEBUG")
95101
endif()
96102

103+
if("${sdk}" STREQUAL "ANDROID")
104+
list(APPEND result
105+
"-I/home/zhuowei/ndk/sources/cxx-stl/llvm-libc++/libcxx/include"
106+
"-I/home/zhuowei/ndk/sources/android/support/include")
107+
endif()
108+
97109
set("${result_var_name}" "${result}" PARENT_SCOPE)
98110
endfunction()
99111

@@ -1051,7 +1063,7 @@ function(_add_swift_library_single target name)
10511063
# isn't the standard library. The standard library uses a
10521064
# linker script that isn't supported by the gold linker.
10531065
if(NOT SWIFTLIB_SINGLE_IS_STDLIB)
1054-
list(APPEND link_flags "-fuse-ld=gold")
1066+
list(APPEND link_flags "-fuse-ld=gold -Wl,--gdb-index")
10551067
endif()
10561068
endif()
10571069
endif()

cmake/modules/FindICU.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Find libicu's libraries
22

3+
# Android FIXME: ICU
4+
35
include(FindPackageHandleStandardArgs)
46

57
find_package(PkgConfig)
@@ -24,6 +26,9 @@ foreach(MODULE ${ICU_FIND_COMPONENTS})
2426
set(ICU_${MODULE}_LIBRARIES ${ICU_${MODULE}_LIBRARY})
2527
endif()
2628
endforeach()
29+
message("FIXME Android: ICU")
30+
set(ICU_I18N_INCLUDE_DIR "/home/zhuowei/icu/source/i18n")
31+
set(ICU_UC_INCLUDE_DIR "/home/zhuowei/icu/source/common")
2732

2833
find_package_handle_standard_args(ICU DEFAULT_MSG ${ICU_REQUIRED})
2934
mark_as_advanced(${ICU_REQUIRED})

utils/build-script-impl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ KNOWN_SETTINGS=(
175175
swift-enable-target-android "1" "Enable compiler support for targeting Android"
176176
swift-runtime-enable-dtrace "0" "Enable runtime dtrace support"
177177
swift-runtime-enable-leak-checker "0" "Enable leaks checking routines in the runtime"
178-
use-gold-linker "" "Enable using the gold linker"
178+
use-gold-linker "1" "Enable using the gold linker"
179179
darwin-toolchain-bundle-identifier "" "CFBundleIdentifier for xctoolchain info plist"
180180
darwin-toolchain-display-name "" "Display Name for xctoolcain info plist"
181181
darwin-toolchain-name "" "Directory name for xctoolchain"
@@ -1032,8 +1032,8 @@ COMMON_CMAKE_OPTIONS=(
10321032
-G "${CMAKE_GENERATOR}"
10331033
)
10341034

1035-
COMMON_C_FLAGS=""
1036-
COMMON_CXX_FLAGS=""
1035+
COMMON_C_FLAGS="-gsplit-dwarf"
1036+
COMMON_CXX_FLAGS="-gsplit-dwarf"
10371037

10381038
if [[ "${ENABLE_ASAN}" ]] ; then
10391039
COMMON_CMAKE_OPTIONS=(
@@ -1083,6 +1083,7 @@ fi
10831083
if [[ "$DISTCC" ]] ; then
10841084
BUILD_ARGS="${BUILD_ARGS} -j $(distcc -j)"
10851085
fi
1086+
BUILD_ARGS="${BUILD_ARGS} -j1"
10861087

10871088
case "${CMAKE_GENERATOR}" in
10881089
Ninja)
@@ -1474,8 +1475,8 @@ for deployment_target in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" "${CROSS_TOOLS_
14741475
# gold linker support.
14751476
cmake_options=(
14761477
"${cmake_options[@]}"
1477-
-DCMAKE_EXE_LINKER_FLAGS:STRING="-fuse-ld=gold"
1478-
-DCMAKE_SHARED_LINKER_FLAGS:STRING="-fuse-ld=gold"
1478+
-DCMAKE_EXE_LINKER_FLAGS:STRING="-fuse-ld=gold -Wl,--gdb-index"
1479+
-DCMAKE_SHARED_LINKER_FLAGS:STRING="-fuse-ld=gold -Wl,--gdb-index"
14791480
)
14801481
fi
14811482
else

0 commit comments

Comments
 (0)