Skip to content

Commit fe0ba3b

Browse files
authored
Merge pull request #77626 from hyp/eng/6/android-windows-stdlib-foundation-build
[release/6.0][android] pick fixes for building Android stdlib and swift-foundation to swift 6
2 parents f97c54b + 6482159 commit fe0ba3b

File tree

8 files changed

+115
-26
lines changed

8 files changed

+115
-26
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
3+
set(SWIFT_HOST_VARIANT_ARCH i686 CACHE STRING "")
4+
5+
# NOTE(compnerd) disable the tools, we are trying to build just the standard
6+
# library.
7+
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")
8+
9+
# NOTE(compnerd) cannot build tests since the tests require the toolchain
10+
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")
11+
12+
# NOTE(compnerd) cannot build docs since that requires perl
13+
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
14+
15+
# NOTE(compnerd) these are part of the toolchain, not the runtime.
16+
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")
17+
18+
# NOTE(compnerd) build with the compiler specified, not a just built compiler.
19+
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")
20+
21+
set(SWIFT_SDK_ANDROID_ARCHITECTURES i686 CACHE STRING "")
22+
23+
# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
24+
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
3+
set(SWIFT_HOST_VARIANT_ARCH x86_64 CACHE STRING "")
4+
5+
# NOTE(compnerd) disable the tools, we are trying to build just the standard
6+
# library.
7+
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")
8+
9+
# NOTE(compnerd) cannot build tests since the tests require the toolchain
10+
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")
11+
12+
# NOTE(compnerd) cannot build docs since that requires perl
13+
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")
14+
15+
# NOTE(compnerd) these are part of the toolchain, not the runtime.
16+
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")
17+
18+
# NOTE(compnerd) build with the compiler specified, not a just built compiler.
19+
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")
20+
21+
set(SWIFT_SDK_ANDROID_ARCHITECTURES x86_64 CACHE STRING "")
22+
23+
# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
24+
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,16 @@ function(_add_target_variant_link_flags)
553553
list(APPEND link_libraries "dl" "log")
554554
# We need to add the math library, which is linked implicitly by libc++
555555
list(APPEND result "-lm")
556-
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
557-
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
558-
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
559-
else()
560-
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
556+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
557+
# The Android resource dir is specified from build.ps1 on windows.
558+
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
559+
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
560+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
561+
else()
562+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
563+
endif()
564+
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
561565
endif()
562-
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
563566
endif()
564567

565568
# link against the custom C++ library
@@ -3233,9 +3236,14 @@ function(add_swift_target_executable name)
32333236
# it tries to build swift-backtrace it fails because *the compiler*
32343237
# refers to a libswiftCore.so that can't be found.
32353238

3239+
if(SWIFTEXE_TARGET_NOSWIFTRT)
3240+
set(NOSWIFTRT_KEYWORD "NOSWIFTRT")
3241+
else()
3242+
set(NOSWIFTRT_KEYWORD "")
3243+
endif()
32363244
_add_swift_target_executable_single(
32373245
${VARIANT_NAME}
3238-
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
3246+
${NOSWIFTRT_KEYWORD}
32393247
${SWIFTEXE_TARGET_SOURCES}
32403248
DEPENDS
32413249
${SWIFTEXE_TARGET_DEPENDS_with_suffix}
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2-
set(BUILTIN_FLOAT_SWIFT_FLAGS -Xfrontend -module-abi-name -Xfrontend Darwin)
3-
else()
4-
set(BUILTIN_FLOAT_SWIFT_FLAGS)
5-
endif()
1+
if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT)
2+
3+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
4+
set(BUILTIN_FLOAT_SWIFT_FLAGS -Xfrontend -module-abi-name -Xfrontend Darwin)
5+
else()
6+
set(BUILTIN_FLOAT_SWIFT_FLAGS)
7+
endif()
68

7-
add_swift_target_library(swift_Builtin_float
8-
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
9-
IS_SDK_OVERLAY
9+
add_swift_target_library(swift_Builtin_float
10+
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
11+
IS_SDK_OVERLAY
1012

11-
linker-support/magic-symbols-for-install-name.c
13+
linker-support/magic-symbols-for-install-name.c
1214

13-
GYB_SOURCES
14-
float.swift.gyb
15+
GYB_SOURCES
16+
float.swift.gyb
1517

16-
SWIFT_COMPILE_FLAGS
17-
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
18-
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
19-
${BUILTIN_FLOAT_SWIFT_FLAGS}
18+
SWIFT_COMPILE_FLAGS
19+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
20+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
21+
${BUILTIN_FLOAT_SWIFT_FLAGS}
2022

21-
LINK_FLAGS
22-
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
23+
LINK_FLAGS
24+
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
2325

24-
INSTALL_IN_COMPONENT stdlib
25-
MACCATALYST_BUILD_FLAVOR zippered)
26+
INSTALL_IN_COMPONENT stdlib
27+
MACCATALYST_BUILD_FLAVOR zippered)
28+
endif()

stdlib/public/Concurrency/DispatchGlobalExecutor.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ struct MinimalDispatchObjectHeader {
4747
int Opaque1;
4848
void *Linkage;
4949
};
50+
51+
#pragma clang diagnostic push
52+
#pragma clang diagnostic ignored "-Wgnu-offsetof-extensions"
5053
static_assert(
5154
offsetof(Job, metadata) == offsetof(MinimalDispatchObjectHeader, VTable),
5255
"Job Metadata field must match location of Dispatch VTable field.");
5356
static_assert(offsetof(Job, SchedulerPrivate[Job::DispatchLinkageIndex]) ==
5457
offsetof(MinimalDispatchObjectHeader, Linkage),
5558
"Dispatch Linkage field must match Job "
5659
"SchedulerPrivate[DispatchLinkageIndex].");
60+
#pragma clang diagnostic pop
5761

5862
/// The function passed to dispatch_async_f to execute a job.
5963
static void __swift_run_job(void *_job) {

stdlib/public/Platform/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,24 @@ if("ANDROID" IN_LIST SWIFT_SDKS)
472472
COMPONENT sdk-overlay)
473473
endif()
474474
endforeach()
475+
476+
set(android_posix_filesystem_apinotes_source "posix_filesystem.apinotes")
477+
set(apinotes_subdir "${SWIFTLIB_DIR}/apinotes")
478+
add_custom_command_target(
479+
copy_android_posix_filesystem_apinotes_resource
480+
COMMAND
481+
"${CMAKE_COMMAND}" "-E" "make_directory" ${apinotes_subdir}
482+
COMMAND
483+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
484+
"${CMAKE_CURRENT_SOURCE_DIR}/${android_posix_filesystem_apinotes_source}" ${apinotes_subdir}
485+
OUTPUT ${apinotes_subdir}/${android_posix_filesystem_apinotes_source}
486+
COMMENT "Copying Android posix_filesystem API notes to resource directories")
487+
add_dependencies(sdk-overlay ${copy_android_posix_filesystem_apinotes_resource})
488+
list(APPEND android_modulemap_target_list ${copy_android_posix_filesystem_apinotes_resource})
489+
swift_install_in_component(FILES
490+
"${android_posix_filesystem_apinotes_source}"
491+
DESTINATION "lib/swift/apinotes"
492+
COMPONENT sdk-overlay)
475493
endif()
476494
add_custom_target(android_modulemap DEPENDS ${android_modulemap_target_list})
477495
set_property(TARGET android_modulemap PROPERTY FOLDER "Miscellaneous")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
Name: bionic
3+
Functions:
4+
- Name: fts_open
5+
Parameters:
6+
- Position: 0
7+
Type: "char * const _Nullable * _Nonnull"

stdlib/tools/swift-reflection-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_swift_target_executable(swift-reflection-test BUILD_WITH_STDLIB
2+
NOSWIFTRT
23
swift-reflection-test.c
34
overrides.c
45
LINK_LIBRARIES

0 commit comments

Comments
 (0)