Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: support building android SDKs on Windows #72014

Merged
merged 12 commits into from
Jun 7, 2024
Merged
24 changes: 24 additions & 0 deletions cmake/caches/Runtime-Android-i686.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
set(SWIFT_HOST_VARIANT_ARCH i686 CACHE STRING "")

# NOTE(compnerd) disable the tools, we are trying to build just the standard
# library.
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")

# NOTE(compnerd) cannot build tests since the tests require the toolchain
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")

# NOTE(compnerd) cannot build docs since that requires perl
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")

# NOTE(compnerd) these are part of the toolchain, not the runtime.
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")

# NOTE(compnerd) build with the compiler specified, not a just built compiler.
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")

set(SWIFT_SDK_ANDROID_ARCHITECTURES i686 CACHE STRING "")

# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")
24 changes: 24 additions & 0 deletions cmake/caches/Runtime-Android-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

set(SWIFT_HOST_VARIANT_SDK ANDROID CACHE STRING "")
set(SWIFT_HOST_VARIANT_ARCH x86_64 CACHE STRING "")

# NOTE(compnerd) disable the tools, we are trying to build just the standard
# library.
set(SWIFT_INCLUDE_TOOLS NO CACHE BOOL "")

# NOTE(compnerd) cannot build tests since the tests require the toolchain
set(SWIFT_INCLUDE_TESTS NO CACHE BOOL "")

# NOTE(compnerd) cannot build docs since that requires perl
set(SWIFT_INCLUDE_DOCS NO CACHE BOOL "")

# NOTE(compnerd) these are part of the toolchain, not the runtime.
set(SWIFT_BUILD_SOURCEKIT NO CACHE BOOL "")

# NOTE(compnerd) build with the compiler specified, not a just built compiler.
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")

set(SWIFT_SDK_ANDROID_ARCHITECTURES x86_64 CACHE STRING "")

# NOTE(compnerd) this is lollipop, which seems to still have decent usage.
set(SWIFT_ANDROID_API_LEVEL 21 CACHE STRING "")
22 changes: 15 additions & 7 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,16 @@ function(_add_target_variant_link_flags)
list(APPEND link_libraries "dl" "log")
# We need to add the math library, which is linked implicitly by libc++
list(APPEND result "-lm")
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
else()
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
# The Android resource dir is specified from build.ps1 on windows.
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
else()
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
endif()
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
endif()
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
endif()

# link against the custom C++ library
Expand Down Expand Up @@ -3062,9 +3065,14 @@ function(add_swift_target_executable name)
# it tries to build swift-backtrace it fails because *the compiler*
# refers to a libswiftCore.so that can't be found.

if(SWIFTEXE_TARGET_NOSWIFTRT)
set(NOSWIFTRT_KEYWORD "NOSWIFTRT")
else()
set(NOSWIFTRT_KEYWORD "")
endif()
_add_swift_target_executable_single(
${VARIANT_NAME}
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
${NOSWIFTRT_KEYWORD}
${SWIFTEXE_TARGET_SOURCES}
DEPENDS
${SWIFTEXE_TARGET_DEPENDS_with_suffix}
Expand Down
28 changes: 15 additions & 13 deletions stdlib/public/ClangOverlays/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
add_swift_target_library(swift_Builtin_float
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
IS_SDK_OVERLAY
if(NOT DEFINED SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT OR NOT SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT)
add_swift_target_library(swift_Builtin_float
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
IS_SDK_OVERLAY

GYB_SOURCES
float.swift.gyb
GYB_SOURCES
float.swift.gyb

SWIFT_COMPILE_FLAGS
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -previous-module-installname-map-file -Xfrontend "${SWIFT_SOURCE_DIR}/stdlib/linker-support/previous-module-installname.json"
SWIFT_COMPILE_FLAGS
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -previous-module-installname-map-file -Xfrontend "${SWIFT_SOURCE_DIR}/stdlib/linker-support/previous-module-installname.json"

LINK_FLAGS
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
LINK_FLAGS
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}

INSTALL_IN_COMPONENT stdlib
MACCATALYST_BUILD_FLAVOR zippered)
INSTALL_IN_COMPONENT stdlib
MACCATALYST_BUILD_FLAVOR zippered)
endif()
4 changes: 4 additions & 0 deletions stdlib/public/Concurrency/DispatchGlobalExecutor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ struct MinimalDispatchObjectHeader {
int Opaque1;
void *Linkage;
};

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-offsetof-extensions"
static_assert(
offsetof(Job, metadata) == offsetof(MinimalDispatchObjectHeader, VTable),
"Job Metadata field must match location of Dispatch VTable field.");
static_assert(offsetof(Job, SchedulerPrivate[Job::DispatchLinkageIndex]) ==
offsetof(MinimalDispatchObjectHeader, Linkage),
"Dispatch Linkage field must match Job "
"SchedulerPrivate[DispatchLinkageIndex].");
#pragma clang diagnostic pop

/// The function passed to dispatch_async_f to execute a job.
static void __swift_run_job(void *_job) {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
list(APPEND SWIFTLIB_EMBEDDED_GYB_SOURCES SIMDConcreteOperations.swift.gyb SIMDVectorTypes.swift.gyb)
endif()

# Freestanding and Linux builds both have failures to resolve.
if(NOT BOOTSTRAPPING_MODE STREQUAL "OFF" AND NOT SWIFT_FREESTANDING_FLAVOR AND NOT SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX")
# Freestanding and Linux/Android builds both have failures to resolve.
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")
list(APPEND SWIFTLIB_SOURCES ObjectIdentifier+DebugDescription.swift)
endif()

Expand Down
1 change: 1 addition & 0 deletions stdlib/tools/swift-reflection-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_swift_target_executable(swift-reflection-test BUILD_WITH_STDLIB
NOSWIFTRT
swift-reflection-test.c
overrides.c
LINK_LIBRARIES
Expand Down
Loading