@@ -403,18 +403,33 @@ def generate_linux_toolchain_file(self, platform, arch, crosscompiling=True):
403
403
toolchain_args = {}
404
404
405
405
if crosscompiling :
406
- toolchain_args ['CMAKE_SYSTEM_NAME' ] = 'Linux'
407
- toolchain_args ['CMAKE_SYSTEM_PROCESSOR' ] = arch
406
+ if platform == "linux" :
407
+ toolchain_args ['CMAKE_SYSTEM_NAME' ] = 'Linux'
408
+ toolchain_args ['CMAKE_SYSTEM_PROCESSOR' ] = arch
409
+ elif platform == "android" :
410
+ toolchain_args ['CMAKE_SYSTEM_NAME' ] = 'Android'
411
+ toolchain_args ['CMAKE_SYSTEM_VERSION' ] = self .args .android_api_level
412
+ toolchain_args ['CMAKE_SYSTEM_PROCESSOR' ] = arch if not arch == 'armv7' \
413
+ else 'armv7-a'
414
+ toolchain_args ['CMAKE_ANDROID_NDK' ] = self .args .android_ndk
415
+ toolchain_args ['CMAKE_FIND_ROOT_PATH' ] = self .args .cross_compile_deps_path
416
+ # This is a workaround for a CMake 3.30+ bug,
417
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/26154, and can
418
+ # be removed once that is fixed.
419
+ toolchain_args ['CMAKE_SHARED_LINKER_FLAGS' ] = '\" \" '
408
420
409
421
# We only set the actual sysroot if we are actually cross
410
422
# compiling. This is important since otherwise cmake seems to change the
411
423
# RUNPATH to be a relative rather than an absolute path, breaking
412
424
# certain cmark tests (and maybe others).
413
- maybe_sysroot = self .get_linux_sysroot (platform , arch )
414
- if maybe_sysroot is not None :
415
- toolchain_args ['CMAKE_SYSROOT' ] = maybe_sysroot
416
-
417
- target = self .get_linux_target (platform , arch )
425
+ if platform == "linux" :
426
+ maybe_sysroot = self .get_linux_sysroot (platform , arch )
427
+ if maybe_sysroot is not None :
428
+ toolchain_args ['CMAKE_SYSROOT' ] = maybe_sysroot
429
+
430
+ target = self .get_linux_target (platform , arch )
431
+ elif platform == "android" :
432
+ target = '%s-unknown-linux-android%s' % (arch , self .args .android_api_level )
418
433
if self .toolchain .cc .endswith ('clang' ):
419
434
toolchain_args ['CMAKE_C_COMPILER_TARGET' ] = target
420
435
if self .toolchain .cxx .endswith ('clang++' ):
@@ -460,10 +475,30 @@ def generate_toolchain_file_for_darwin_or_linux(
460
475
platform , arch ,
461
476
macos_deployment_version = override_macos_deployment_version )
462
477
self .cmake_options .define ('CMAKE_TOOLCHAIN_FILE:PATH' , toolchain_file )
463
- elif platform == "linux" :
464
- toolchain_file = self .generate_linux_toolchain_file (platform , arch )
478
+ elif platform == "linux" or platform == "android" :
479
+ # Always cross-compile for linux, but not on Android, as a native
480
+ # compile on Android does not use the NDK and its CMake config.
481
+ cross_compile = platform == "linux" or \
482
+ self .is_cross_compile_target (host_target )
483
+ toolchain_file = self .generate_linux_toolchain_file (platform , arch ,
484
+ cross_compile )
465
485
self .cmake_options .define ('CMAKE_TOOLCHAIN_FILE:PATH' , toolchain_file )
466
486
487
+ if cross_compile and platform == "android" :
488
+ resource_dir = None
489
+ # build-script-impl products build before the install and use
490
+ # the Swift stdlib from the compiler build directory instead,
491
+ # while products built even before that currently do not support
492
+ # cross-compiling Swift.
493
+ if not self .is_before_build_script_impl_product () and \
494
+ not self .is_build_script_impl_product ():
495
+ install_path = self .host_install_destdir (host_target ) + \
496
+ self .args .install_prefix
497
+ resource_dir = '%s/lib/swift' % install_path
498
+ flags = targets .StdlibDeploymentTarget .get_target_for_name (
499
+ host_target ).platform .swift_flags (self .args , resource_dir )
500
+ self .cmake_options .define ('CMAKE_Swift_FLAGS' , flags )
501
+
467
502
return toolchain_file
468
503
469
504
def get_openbsd_toolchain_file (self ):
0 commit comments