Skip to content

Commit a499c41

Browse files
committed
Support AARCH64 for Fuchsia
This change adds support for compiling Fuchsia for ARM64. It also changes the arguments passed to build-script to remove hardcoded file paths to sysroots and include directories in a Fuchsia build tree. Some changes were made to be able to support building more than one architecture for a non-Darwin platform as the Unix sdk targets only support one at a time.
1 parent 6128a51 commit a499c41

File tree

10 files changed

+230
-60
lines changed

10 files changed

+230
-60
lines changed

CMakeLists.txt

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,35 @@ set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
181181
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
182182

183183
#
184-
# User-configurable ICU specific options for Android, FreeBSD, Linux and Haiku.
184+
# User-configurable Fuchsia specific options
185185
#
186186

187-
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;FUCHSIA;HAIKU)
187+
set(SWIFT_FUCHSIA_AARCH64_SYSROOT "" CACHE STRING
188+
"Path to a Fuchsia zircon aarch64 sysroot directory")
189+
190+
set(SWIFT_FUCHSIA_X86_64_SYSROOT "" CACHE STRING
191+
"Path to a Fuchsia zircon x86_64 sysroot directory")
192+
193+
set(SWIFT_FUCHSIA_AARCH64_LIBS "" CACHE STRING
194+
"Path to a Fuchsia aarch64 shared libs directory")
195+
196+
set(SWIFT_FUCHSIA_X86_64_LIBS "" CACHE STRING
197+
"Path to a Fuchsia x86_64 shared libs directory")
198+
199+
set(SWIFT_FUCHSIA_ICU_UC_INCLUDE "" CACHE STRING
200+
"Path to a directory containing Fuchsia's ICU common headers")
201+
202+
set(SWIFT_FUCHSIA_ICU_I18N_INCLUDE "" CACHE STRING
203+
"Path to a directory containing Fuchsia's ICU i18n headers")
204+
205+
set(SWIFT_FUCHSIA_TOOLCHAIN_PATH "" CACHE STRING
206+
"Path to a directory containing a Fuchsia clang toolchain")
207+
208+
#
209+
# User-configurable ICU specific options for non-Darwin SDKs.
210+
#
211+
212+
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
188213
set(SWIFT_${sdk}_ICU_UC "" CACHE STRING
189214
"Path to a directory containing the icuuc library for ${sdk}")
190215
set(SWIFT_${sdk}_ICU_UC_INCLUDE "" CACHE STRING
@@ -755,15 +780,22 @@ endif()
755780

756781
# Should we cross-compile the standard library for Fuchsia
757782
is_sdk_requested(FUCHSIA swift_build_fuchsia)
758-
if(swift_build_fuchsia AND NOT "${SWIFT_FUCHSIA_BUILD_PATH}" STREQUAL "")
759-
# HACK: support arm64 fuchsia builds
760-
set(SWIFT_FUCHSIA_SYSROOT
761-
"${SWIFT_FUCHSIA_BUILD_PATH}/out/build-zircon/build-zircon-pc-x86-64/sysroot")
783+
if(swift_build_fuchsia)
784+
set(fuchsia_archs)
785+
786+
if (NOT SWIFT_FUCHSIA_AARCH64_SYSROOT STREQUAL "")
787+
set(SWIFT_SDK_FUCHSIA_ARCH_aarch64_PATH "${SWIFT_FUCHSIA_AARCH64_SYSROOT}")
788+
list(APPEND fuchsia_archs "aarch64")
789+
endif()
790+
if (NOT SWIFT_FUCHSIA_X86_64_SYSROOT STREQUAL "")
791+
set(SWIFT_SDK_FUCHSIA_ARCH_x86_64_PATH "${SWIFT_FUCHSIA_X86_64_SYSROOT}")
792+
list(APPEND fuchsia_archs "x86_64")
793+
endif()
762794

763-
set(SWIFT_SDK_FUCHSIA_ARCH_x86_64_LINKER
764-
"${SWIFT_FUCHSIA_BUILD_PATH}/buildtools/linux-x64/clang/bin/ld.lld")
795+
set(SWIFT_FUCHSIA_ICU_UC "-licuuc")
796+
set(SWIFT_FUCHSIA_ICU_I18N "-licui18n")
765797

766-
configure_sdk_unix(FUCHSIA "Fuchsia" "fuchsia" "fuchsia" "x86_64" "x86_64-unknown-fuchsia" "${SWIFT_FUCHSIA_SYSROOT}")
798+
configure_sdk_fuchsia(FUCHSIA "Fuchsia" "fuchsia" "fuchsia" "${fuchsia_archs}")
767799

768800
if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
769801
message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Fuchsia")

cmake/modules/AddSwift.cmake

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function(_add_variant_c_compile_link_flags)
107107

108108
is_darwin_based_sdk("${CFLAGS_SDK}" IS_DARWIN)
109109
if(IS_DARWIN)
110-
list(APPEND result "-isysroot" "${SWIFT_SDK_${CFLAGS_SDK}_PATH}")
111-
elseif(NOT SWIFT_COMPILER_IS_MSVC_LIKE AND NOT "${SWIFT_SDK_${CFLAGS_SDK}_PATH}" STREQUAL "/")
112-
list(APPEND result "--sysroot=${SWIFT_SDK_${CFLAGS_SDK}_PATH}")
110+
list(APPEND result "-isysroot" "${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_PATH}")
111+
elseif(NOT SWIFT_COMPILER_IS_MSVC_LIKE AND NOT "${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_PATH}" STREQUAL "/")
112+
list(APPEND result "--sysroot=${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_PATH}")
113113
endif()
114114

115115
if("${CFLAGS_SDK}" STREQUAL "ANDROID")
@@ -121,8 +121,7 @@ function(_add_variant_c_compile_link_flags)
121121

122122
if("${CFLAGS_SDK}" STREQUAL "FUCHSIA")
123123
list(APPEND result
124-
"-I${SWIFT_FUCHSIA_BUILD_PATH}/buildtools/linux-x64/clang/lib/x86_64-fuchsia/include/c++/v1/"
125-
"-L${SWIFT_FUCHSIA_BUILD_PATH}/buildtools/linux-x64/clang/lib/x86_64-fuchsia/lib")
124+
"-I${SWIFT_FUCHSIA_TOOLCHAIN_PATH}/lib/${CFLAGS_ARCH}-fuchsia/include/c++/v1/")
126125
endif()
127126

128127
if(IS_DARWIN)
@@ -277,10 +276,15 @@ function(_add_variant_c_compile_flags)
277276
endif()
278277

279278
if("${CFLAGS_SDK}" STREQUAL "FUCHSIA")
279+
if ("${CFLAGS_ARCH}" STREQUAL "x86_64")
280+
# LLVM may assume that CMPXCHG16B instruction doesn't exist on some x64 cpus
281+
# and will attempt to replace it with a libcall to a libgcc function that
282+
# doesn't exist in compiler-rt
283+
list(APPEND result "-mcx16")
284+
endif()
280285
list(APPEND result
281-
"-mcx16"
282-
"-I${SWIFT_FUCHSIA_BUILD_PATH}/third_party/icu/source/common/"
283-
"-I${SWIFT_FUCHSIA_BUILD_PATH}/third_party/icu/source/i18n/")
286+
"-I${SWIFT_FUCHSIA_ICU_CU_INCLUDE}"
287+
"-I${SWIFT_FUCHSIA_ICU_I18N_INCLUDE}")
284288
endif()
285289

286290
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
@@ -290,9 +294,9 @@ function(_add_variant_swift_compile_flags
290294
sdk arch build_type enable_assertions result_var_name)
291295
set(result ${${result_var_name}})
292296

293-
# On Windows, we don't set SWIFT_SDK_WINDOWS_PATH, so don't include it.
297+
# On Windows, we don't set SWIFT_SDK_WINDOWS_ARCH_{ARCH}_PATH, so don't include it.
294298
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
295-
list(APPEND result "-sdk" "${SWIFT_SDK_${sdk}_PATH}")
299+
list(APPEND result "-sdk" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}")
296300
endif()
297301

298302
if(BUILD_STANDALONE)
@@ -307,7 +311,7 @@ function(_add_variant_swift_compile_flags
307311
is_darwin_based_sdk("${sdk}" IS_DARWIN)
308312
if(IS_DARWIN)
309313
list(APPEND result
310-
"-F" "${SWIFT_SDK_${sdk}_PATH}/../../../Developer/Library/Frameworks")
314+
"-F" "${SWIFT_SDK_${sdk}_ARCH_{arch}_PATH}/../../../Developer/Library/Frameworks")
311315
endif()
312316

313317
is_build_type_optimized("${build_type}" optimized)
@@ -340,7 +344,7 @@ function(_add_variant_link_flags)
340344
${ARGN})
341345

342346
precondition(LFLAGS_SDK MESSAGE "Should specify an SDK")
343-
precondition(LFLAGS_SDK MESSAGE "Should specify an architecture")
347+
precondition(LFLAGS_ARCH MESSAGE "Should specify an architecture")
344348

345349
set(result ${${LFLAGS_RESULT_VAR_NAME}})
346350
set(library_search_directories ${${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}})
@@ -383,7 +387,12 @@ function(_add_variant_link_flags)
383387
"${SWIFT_ANDROID_PREBUILT_PATH}/arm-linux-androideabi/lib/armv7-a"
384388
"${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x")
385389
elseif("${LFLAGS_SDK}" STREQUAL "FUCHSIA")
386-
list(APPEND result "-lc" "-ldl")
390+
list(APPEND result "-lc" "-ldl" "-lzircon" "-lfdio")
391+
if (LFLAGS_ARCH STREQUAL "aarch64")
392+
list(APPEND library_search_directories "${SWIFT_FUCHSIA_AARCH64_LIBS}")
393+
elseif (LFLAGS_ARCH STREQUAL "x86_64")
394+
list(APPEND library_search_directories "${SWIFT_FUCHSIA_X86_64_LIBS}")
395+
endif()
387396
else()
388397
# If lto is enabled, we need to add the object path flag so that the LTO code
389398
# generator leaves the intermediate object file in a place where it will not
@@ -1617,7 +1626,7 @@ function(add_swift_library name)
16171626
# Add PrivateFrameworks, rdar://28466433
16181627
set(swiftlib_link_flags_all ${SWIFTLIB_LINK_FLAGS})
16191628
if(SWIFTLIB_IS_SDK_OVERLAY)
1620-
list(APPEND swiftlib_swift_compile_flags_all "-Fsystem" "${SWIFT_SDK_${sdk}_PATH}/System/Library/PrivateFrameworks/")
1629+
list(APPEND swiftlib_swift_compile_flags_all "-Fsystem" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/System/Library/PrivateFrameworks/")
16211630
endif()
16221631

16231632
if("${sdk}" STREQUAL "IOS_SIMULATOR")

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function(_report_sdk prefix)
2222
message(STATUS " ${arch} LIB: ${${arch}_LIB}")
2323
endforeach()
2424
else()
25-
message(STATUS " Path: ${SWIFT_SDK_${prefix}_PATH}")
25+
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
26+
message(STATUS " ${arch} Path: ${SWIFT_SDK_${prefix}_ARCH_${ARCH}_PATH}")
27+
endforeach()
2628
endif()
2729
message(STATUS " Version: ${SWIFT_SDK_${prefix}_VERSION}")
2830
message(STATUS " Build number: ${SWIFT_SDK_${prefix}_BUILD_NUMBER}")
@@ -122,6 +124,9 @@ macro(configure_sdk_darwin
122124
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "MACHO")
123125

124126
foreach(arch ${architectures})
127+
# On Darwin, all archs share the same SDK path.
128+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_PATH "${SWIFT_SDK_${prefix}_PATH}")
129+
125130
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE
126131
"${arch}-apple-${SWIFT_SDK_${prefix}_TRIPLE_NAME}${SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION}")
127132
endforeach()
@@ -137,8 +142,10 @@ macro(configure_sdk_unix
137142
# Note: this has to be implemented as a macro because it sets global
138143
# variables.
139144

145+
# Todo: this only supports building an SDK for one target arch only.
146+
140147
set(SWIFT_SDK_${prefix}_NAME "${name}")
141-
set(SWIFT_SDK_${prefix}_PATH "${sdkpath}")
148+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_PATH "${sdkpath}")
142149
set(SWIFT_SDK_${prefix}_VERSION "don't use")
143150
set(SWIFT_SDK_${prefix}_BUILD_NUMBER "don't use")
144151
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "don't use")
@@ -160,6 +167,37 @@ macro(configure_sdk_unix
160167
_report_sdk("${prefix}")
161168
endmacro()
162169

170+
macro(configure_sdk_fuchsia
171+
prefix name lib_subdir triple_name architectures)
172+
# Note: this has to be implemented as a macro because it sets global
173+
# variables.
174+
175+
set(SWIFT_SDK_${prefix}_NAME "${name}")
176+
# SDK PATHs are configured by caller
177+
set(SWIFT_SDK_${prefix}_VERSION "don't use")
178+
set(SWIFT_SDK_${prefix}_BUILD_NUMBER "don't use")
179+
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "don't use")
180+
set(SWIFT_SDK_${prefix}_LIB_SUBDIR "${lib_subdir}")
181+
set(SWIFT_SDK_${prefix}_VERSION_MIN_NAME "")
182+
set(SWIFT_SDK_${prefix}_TRIPLE_NAME "${triple_name}")
183+
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
184+
if("${prefix}" STREQUAL "CYGWIN")
185+
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
186+
else()
187+
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
188+
endif()
189+
190+
foreach(arch ${architectures})
191+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE "${arch}-unknown-fuchsia")
192+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER "${SWIFT_FUCHSIA_TOOLCHAIN_PATH}/bin/ld.lld")
193+
endforeach()
194+
195+
# Add this to the list of known SDKs.
196+
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
197+
198+
_report_sdk("${prefix}")
199+
endmacro()
200+
163201
macro(configure_sdk_windows prefix sdk_name environment architectures)
164202
# Note: this has to be implemented as a macro because it sets global
165203
# variables.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
823823

824824
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
825825
Opts.DisableAvailabilityChecking = true;
826-
826+
827827
if (auto A = Args.getLastArg(OPT_enable_access_control,
828828
OPT_disable_access_control)) {
829829
Opts.EnableAccessControl
@@ -854,7 +854,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
854854
Opts.EnableTargetOSChecking
855855
= A->getOption().matches(OPT_enable_target_os_checking);
856856
}
857-
857+
858858
Opts.EnableASTScopeLookup |= Args.hasArg(OPT_enable_astscope_lookup);
859859
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
860860
Opts.EnableConstraintPropagation |= Args.hasArg(OPT_propagate_constraints);
@@ -892,7 +892,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
892892

893893
Opts.DebugConstraintSolverAttempt = attempt;
894894
}
895-
895+
896896
if (const Arg *A = Args.getLastArg(OPT_debug_forbid_typecheck_prefix)) {
897897
Opts.DebugForbidTypecheckPrefix = A->getValue();
898898
}
@@ -904,7 +904,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
904904
A->getAsString(Args), A->getValue());
905905
return true;
906906
}
907-
907+
908908
Opts.SolverMemoryThreshold = threshold;
909909
}
910910

@@ -929,7 +929,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
929929

930930
Opts.MaxCircularityDepth = threshold;
931931
}
932-
932+
933933
for (const Arg *A : Args.filtered(OPT_D)) {
934934
Opts.addCustomConditionalCompilationFlag(A->getValue());
935935
}
@@ -1102,9 +1102,9 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
11021102
// Opts.RuntimeIncludePath is set by calls to
11031103
// setRuntimeIncludePath() or setMainExecutablePath().
11041104
// Opts.RuntimeImportPath is set by calls to
1105-
// setRuntimeIncludePath() or setMainExecutablePath() and
1105+
// setRuntimeIncludePath() or setMainExecutablePath() and
11061106
// updated by calls to setTargetTriple() or parseArgs().
1107-
// Assumes exactly one of setMainExecutablePath() or setRuntimeIncludePath()
1107+
// Assumes exactly one of setMainExecutablePath() or setRuntimeIncludePath()
11081108
// is called before setTargetTriple() and parseArgs().
11091109
// TODO: improve the handling of RuntimeIncludePath.
11101110

@@ -1222,7 +1222,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
12221222
return true;
12231223
}
12241224
}
1225-
1225+
12261226
if (const Arg *A = Args.getLastArg(OPT_disable_sil_linking,
12271227
OPT_sil_link_all)) {
12281228
if (A->getOption().matches(OPT_disable_sil_linking))
@@ -1486,7 +1486,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
14861486

14871487
if (Args.hasArg(OPT_use_jit))
14881488
Opts.UseJIT = true;
1489-
1489+
14901490
for (const Arg *A : Args.filtered(OPT_verify_type_layout)) {
14911491
Opts.VerifyTypeLayoutNames.push_back(A->getValue());
14921492
}

stdlib/public/Platform/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ foreach(sdk ${SWIFT_SDKS})
7171
endif()
7272

7373
if(NOT "${sdk}" STREQUAL "HAIKU")
74-
set(GLIBC_INCLUDE_PATH "${SWIFT_SDK_${sdk}_PATH}/${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH}")
75-
set(GLIBC_ARCH_INCLUDE_PATH "${SWIFT_SDK_${sdk}_PATH}/${GLIBC_SYSROOT_RELATIVE_ARCH_INCLUDE_PATH}")
74+
set(GLIBC_INCLUDE_PATH "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH}")
75+
set(GLIBC_ARCH_INCLUDE_PATH "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/${GLIBC_SYSROOT_RELATIVE_ARCH_INCLUDE_PATH}")
7676
endif()
7777

7878
set(glibc_modulemap_source "glibc.modulemap.gyb")
@@ -94,7 +94,7 @@ foreach(sdk ${SWIFT_SDKS})
9494

9595
# If this SDK is a target for a non-native host, create a native modulemap
9696
# without a sysroot prefix. This is the one we'll install instead.
97-
if(NOT "${SWIFT_SDK_${sdk}_PATH}" STREQUAL "/")
97+
if(NOT "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}" STREQUAL "/")
9898

9999
set(glibc_sysroot_relative_modulemap_out "${module_dir}/sysroot-relative-modulemaps/glibc.modulemap")
100100
handle_gyb_source_single(glibc_modulemap_native_target

0 commit comments

Comments
 (0)