Skip to content

Commit c8b5344

Browse files
authored
Merge pull request #72014 from compnerd/android
utils: support building android SDKs on Windows
2 parents e6f680d + 6381a77 commit c8b5344

File tree

8 files changed

+431
-91
lines changed

8 files changed

+431
-91
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
@@ -554,13 +554,16 @@ function(_add_target_variant_link_flags)
554554
list(APPEND link_libraries "dl" "log")
555555
# We need to add the math library, which is linked implicitly by libc++
556556
list(APPEND result "-lm")
557-
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
558-
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
559-
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
560-
else()
561-
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
557+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
558+
# The Android resource dir is specified from build.ps1 on windows.
559+
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
560+
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
561+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
562+
else()
563+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
564+
endif()
565+
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
562566
endif()
563-
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
564567
endif()
565568

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

3238+
if(SWIFTEXE_TARGET_NOSWIFTRT)
3239+
set(NOSWIFTRT_KEYWORD "NOSWIFTRT")
3240+
else()
3241+
set(NOSWIFTRT_KEYWORD "")
3242+
endif()
32353243
_add_swift_target_executable_single(
32363244
${VARIANT_NAME}
3237-
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
3245+
${NOSWIFTRT_KEYWORD}
32383246
${SWIFTEXE_TARGET_SOURCES}
32393247
DEPENDS
32403248
${SWIFTEXE_TARGET_DEPENDS_with_suffix}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
add_swift_target_library(swift_Builtin_float
2-
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
3-
IS_SDK_OVERLAY
1+
if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT)
2+
add_swift_target_library(swift_Builtin_float
3+
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
4+
IS_SDK_OVERLAY
45

5-
GYB_SOURCES
6-
float.swift.gyb
6+
GYB_SOURCES
7+
float.swift.gyb
78

8-
SWIFT_COMPILE_FLAGS
9-
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
10-
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
11-
-Xfrontend -previous-module-installname-map-file -Xfrontend "${SWIFT_SOURCE_DIR}/stdlib/linker-support/previous-module-installname.json"
9+
SWIFT_COMPILE_FLAGS
10+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
11+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
12+
-Xfrontend -previous-module-installname-map-file -Xfrontend "${SWIFT_SOURCE_DIR}/stdlib/linker-support/previous-module-installname.json"
1213

13-
LINK_FLAGS
14-
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
14+
LINK_FLAGS
15+
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
1516

16-
INSTALL_IN_COMPONENT stdlib
17-
MACCATALYST_BUILD_FLAVOR zippered)
17+
INSTALL_IN_COMPONENT stdlib
18+
MACCATALYST_BUILD_FLAVOR zippered)
19+
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/core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
262262
list(APPEND SWIFTLIB_EMBEDDED_GYB_SOURCES SIMDConcreteOperations.swift.gyb SIMDVectorTypes.swift.gyb)
263263
endif()
264264

265-
# Freestanding and Linux builds both have failures to resolve.
266-
if(NOT BOOTSTRAPPING_MODE STREQUAL "OFF" AND NOT SWIFT_FREESTANDING_FLAVOR AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX")
265+
# Freestanding and Linux/Android builds both have failures to resolve.
266+
if(NOT BOOTSTRAPPING_MODE STREQUAL "OFF" AND NOT SWIFT_FREESTANDING_FLAVOR AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
267267
list(APPEND SWIFTLIB_SOURCES ObjectIdentifier+DebugDescription.swift)
268268
endif()
269269

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)