From 336ede3eb421622db465cd9c0eeb1b4722d4f360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodri=CC=81guez=20Troitin=CC=83o?= Date: Thu, 20 Sep 2018 14:03:49 -0700 Subject: [PATCH] Unix toolchains will not try to use fat binaries. Unix (other than Darwin) and Windows do not support fat binaries. However, the build system was trying to "lipo" several architectures into one file even for those targets (only Windows was exercising that part of the code, it seems). This patch removes the copy for a bogus empty target, and modifies the Unix toolchain to look into the architecture subdirectory, instead of trying to use the platform directory. The Windows toolchain already checked the architecture directory, and not the platform one. This should allow building two Linux or Android SDKs for different architures side by side. Some tests are modified to handle the new structure. The tests are hardcoded to use x86_64 because their targets were originally x86_64. --- cmake/modules/AddSwift.cmake | 264 ++++++++++-------- lib/Driver/UnixToolChains.cpp | 11 +- lib/Frontend/CompilerInvocation.cpp | 11 +- test/CMakeLists.txt | 13 +- test/Driver/environment.swift | 4 +- test/Driver/options-interpreter.swift | 12 +- .../interpret-with-dependencies-linux.swift | 6 +- 7 files changed, 190 insertions(+), 131 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index dc5970be3e0c1..5efee032c2521 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -76,6 +76,18 @@ function(is_darwin_based_sdk sdk_name out_var) endif() endfunction() +function(_compute_library_dependency_targets input_list sdk arch result_var_name) + # On Darwin, don't add the ${arch} to the suffix. We want to link against fat + # libraries. + if(sdk IN_LIST SWIFT_APPLE_PLATFORMS) + set(suffix "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}") + else() + set(suffix "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}") + endif() + _list_add_string_suffix("${input_list}" "${suffix}" result) + set("${result_var_name}" "${result}" PARENT_SCOPE) +endfunction() + # Usage: # _add_variant_c_compile_link_flags( # SDK sdk @@ -530,6 +542,8 @@ function(_add_swift_lipo_target) "" # multi-value args ${ARGN}) + set(IS_DARWIN ${LIPO_SDK} IN_LIST SWIFT_APPLE_PLATFORMS) + precondition(IS_DARWIN MESSAGE "It's not possible to build a universal binary for a non-MachO target") precondition(LIPO_SDK MESSAGE "sdk is required") precondition(LIPO_TARGET MESSAGE "target is required") precondition(LIPO_OUTPUT MESSAGE "output is required") @@ -543,25 +557,16 @@ function(_add_swift_lipo_target) list(APPEND source_binaries $) endforeach() - if(${LIPO_SDK} IN_LIST SWIFT_APPLE_PLATFORMS) - if(LIPO_CODESIGN) - set(codesign_command COMMAND "codesign" "-f" "-s" "-" "${LIPO_OUTPUT}") - endif() - # Use lipo to create the final binary. - add_custom_command_target(unused_var - COMMAND "${SWIFT_LIPO}" "-create" "-output" "${LIPO_OUTPUT}" ${source_binaries} - ${codesign_command} - CUSTOM_TARGET_NAME "${LIPO_TARGET}" - OUTPUT "${LIPO_OUTPUT}" - DEPENDS ${source_targets}) - else() - # We don't know how to create fat binaries for other platforms. - add_custom_command_target(unused_var - COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${source_binaries}" "${LIPO_OUTPUT}" - CUSTOM_TARGET_NAME "${LIPO_TARGET}" - OUTPUT "${LIPO_OUTPUT}" - DEPENDS ${source_targets}) + if(LIPO_CODESIGN) + set(codesign_command COMMAND "codesign" "-f" "-s" "-" "${LIPO_OUTPUT}") endif() + # Use lipo to create the final binary. + add_custom_command_target(unused_var + COMMAND "${SWIFT_LIPO}" "-create" "-output" "${LIPO_OUTPUT}" ${source_binaries} + ${codesign_command} + CUSTOM_TARGET_NAME "${LIPO_TARGET}" + OUTPUT "${LIPO_OUTPUT}" + DEPENDS ${source_targets}) endfunction() function(swift_target_link_search_directories target directories) @@ -1701,6 +1706,12 @@ function(add_swift_target_library name) list_intersect( "${SWIFTLIB_TARGET_SDKS}" "${SWIFT_SDKS}" SWIFTLIB_TARGET_SDKS) + if(SWIFTLIB_SHARED) + set(resource_list "INSTALLABLE_SHARED_TARGETS") + else() + set(resource_list "INSTALLABLE_STATIC_TARGETS") + endif() + foreach(sdk ${SWIFTLIB_TARGET_SDKS}) if(NOT SWIFT_SDK_${sdk}_ARCHITECTURES) # SWIFT_SDK_${sdk}_ARCHITECTURES is empty, so just continue @@ -1708,6 +1719,9 @@ function(add_swift_target_library name) endif() set(THIN_INPUT_TARGETS) + set(INSTALLABLE_SHARED_TARGETS) + set(INSTALLABLE_STATIC_TARGETS) + set(STDLIB_DEPENDENCIES) # Collect architecture agnostic SDK module dependencies set(swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS}) @@ -1748,7 +1762,7 @@ function(add_swift_target_library name) ${SWIFTLIB_FRAMEWORK_DEPENDS_IOS_TVOS}) endif() - # Collect architecutre agnostic compiler flags + # Collect architecture agnostic compiler flags set(swiftlib_swift_compile_flags_all ${SWIFTLIB_SWIFT_COMPILE_FLAGS}) if(${sdk} STREQUAL OSX) list(APPEND swiftlib_swift_compile_flags_all @@ -1908,47 +1922,52 @@ function(add_swift_target_library name) ) if(NOT SWIFTLIB_OBJECT_LIBRARY) - # Add dependencies on the (not-yet-created) custom lipo target. - foreach(DEP ${SWIFTLIB_LINK_LIBRARIES}) - if (NOT "${DEP}" STREQUAL "icucore") - add_dependencies(${VARIANT_NAME} - "${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}") + if(SWIFTLIB_LINK_LIBRARIES) + set(unsuffixed_dependencies ${SWIFTLIB_LINK_LIBRARIES}) + list(FILTER unsuffixed_dependencies EXCLUDE REGEX "^icucore$") + _compute_library_dependency_targets("${unsuffixed_dependencies}" ${sdk} ${arch} shared_dependencies) + add_dependencies(${VARIANT_NAME} ${shared_dependencies}) + + if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC) + _list_add_string_suffix(shared_dependencies "-static" static_dependencies) + add_dependencies("${VARIANT_NAME}-static" ${static_dependencies}) endif() - endforeach() - - if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC) - # Add dependencies on the (not-yet-created) custom lipo target. - foreach(DEP ${SWIFTLIB_LINK_LIBRARIES}) - if (NOT "${DEP}" STREQUAL "icucore") - add_dependencies("${VARIANT_NAME}-static" - "${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static") - endif() - endforeach() endif() # Note this thin library. list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME}) + + # For non-Darwin SDKs, we install each of the architectures + if(NOT ${sdk} IN_LIST SWIFT_APPLE_PLATFORMS) + list(APPEND "${resource_list}" "${VARIANT_NAME}") + list(APPEND STDLIB_DEPENDENCIES ${VARIANT_NAME}) + set_target_properties(${VARIANT_NAME} + PROPERTIES + SWIFTLIB_INSTALL_FILES $ + SWIFTLIB_INSTALL_DESTINATION "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" + SWIFTLIB_INSTALL_EXPORT_TARGETS "${VARIANT_NAME}") + + if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC) + list(APPEND INSTALLABLE_STATIC_TARGETS "${VARIANT_NAME}-static") + list(APPEND STDLIB_DEPENDENCIES "${VARIANT_NAME}-static") + set_target_properties("${VARIANT_NAME}-static" + PROPERTIES + SWIFTLIB_INSTALL_FILES $ + SWIFTLIB_INSTALL_DESTINATION "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}") + endif() + endif() endif() endforeach() - if(NOT SWIFTLIB_OBJECT_LIBRARY) + # Only Darwin supports universal binaries. + if(NOT SWIFTLIB_OBJECT_LIBRARY AND ${sdk} IN_LIST SWIFT_APPLE_PLATFORMS) # Determine the name of the universal library. if(SWIFTLIB_SHARED) - if("${sdk}" STREQUAL "WINDOWS") - set(UNIVERSAL_LIBRARY_NAME - "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${name}.dll") - else() - set(UNIVERSAL_LIBRARY_NAME - "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") - endif() + set(UNIVERSAL_LIBRARY_NAME + "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") else() - if("${sdk}" STREQUAL "WINDOWS") - set(UNIVERSAL_LIBRARY_NAME - "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${name}.lib") - else() - set(UNIVERSAL_LIBRARY_NAME - "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() + set(UNIVERSAL_LIBRARY_NAME + "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() set(lipo_target "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}") @@ -1975,42 +1994,14 @@ function(add_swift_target_library name) set(resource_dir_sdk_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}") precondition(resource_dir_sdk_subdir) - if(SWIFTLIB_SHARED) - set(resource_dir "swift") - set(file_permissions - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE) - else() - set(resource_dir "swift_static") - set(file_permissions - OWNER_READ OWNER_WRITE - GROUP_READ - WORLD_READ) - endif() - - swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" - FILES "${UNIVERSAL_LIBRARY_NAME}" - DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}" - PERMISSIONS ${file_permissions}) - if(sdk STREQUAL WINDOWS) - foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES}) - if(TARGET ${name}-windows-${arch}_IMPLIB) - get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION) - swift_install_in_component(${SWIFTLIB_INSTALL_IN_COMPONENT} - FILES ${import_library} - DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}" - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) - endif() - endforeach() - endif() - - swift_is_installing_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" is_installing) - if(NOT is_installing) - set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${VARIANT_NAME}) - else() - set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${VARIANT_NAME}) - endif() + list(APPEND "${resource_list}" ${lipo_target}) + list(APPEND STDLIB_DEPENDENCIES ${lipo_target}) + # NOTE: for lipo targets, the exported target is the last ${VARIANT_NAME}, for some reason. + set_target_properties(${lipo_target} + PROPERTIES + SWIFTLIB_INSTALL_FILES "${UNIVERSAL_LIBRARY_NAME}" + SWIFTLIB_INSTALL_DESTINATION "${resource_dir_sdk_subdir}" + SWIFTLIB_INSTALL_EXPORT_TARGETS "${VARIANT_NAME}") # If we built static variants of the library, create a lipo target for # them. @@ -2032,17 +2023,19 @@ function(add_swift_target_library name) OUTPUT "${UNIVERSAL_LIBRARY_NAME}" ${THIN_INPUT_TARGETS_STATIC}) - swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" - FILES "${UNIVERSAL_LIBRARY_NAME}" - DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}" - PERMISSIONS - OWNER_READ OWNER_WRITE - GROUP_READ - WORLD_READ) + + list(APPEND INSTALLABLE_STATIC_TARGETS ${lipo_target_static}) + list(APPEND STDLIB_DEPENDENCIES ${lipo_target_static}) + set_target_properties(${lipo_target_static} + PROPERTIES + SWIFTLIB_INSTALL_FILES "${UNIVERSAL_LIBRARY_NAME}" + SWIFTLIB_INSTALL_DESTINATION "${resource_dir_sdk_subdir}") endif() + endif() - # Add Swift standard library targets as dependencies to the top-level - # convenience target. + # Add Swift standard library targets as dependencies to the top-level + # convenience target. + if(NOT SWIFTLIB_OBJECT_LIBRARY) set(FILTERED_UNITTESTS swiftStdlibCollectionUnittest swiftStdlibUnicodeUnittest) @@ -2052,12 +2045,52 @@ function(add_swift_target_library name) if(TARGET "swift-stdlib${VARIANT_SUFFIX}" AND TARGET "swift-test-stdlib${VARIANT_SUFFIX}") add_dependencies("swift-stdlib${VARIANT_SUFFIX}" - ${lipo_target} - ${lipo_target_static}) + ${STDLIB_DEPENDENCIES}) if(NOT "${name}" IN_LIST FILTERED_UNITTESTS) add_dependencies("swift-test-stdlib${VARIANT_SUFFIX}" - ${lipo_target} - ${lipo_target_static}) + ${STDLIB_DEPENDENCIES}) + endif() + endif() + endforeach() + endif() + + if(NOT SWIFTLIB_OBJECT_LIBRARY) + set(SHARED_TARGET_PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + set(STATIC_TARGET_PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ) + + foreach(target ${INSTALLABLE_SHARED_TARGETS}) + get_target_property(target_files "${target}" SWIFTLIB_INSTALL_FILES) + get_target_property(target_destination "${target}" SWIFTLIB_INSTALL_DESTINATION) + swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" + FILES ${target_files} + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${target_destination}" + PERMISSIONS ${SHARED_TARGET_PERMISSIONS}) + endforeach() + foreach(target ${INSTALLABLE_STATIC_TARGETS}) + get_target_property(target_files "${target}" SWIFTLIB_INSTALL_FILES) + get_target_property(target_destination "${target}" SWIFTLIB_INSTALL_DESTINATION) + swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" + FILES ${target_files} + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${target_destination}" + PERMISSIONS ${STATIC_TARGET_PERMISSIONS}) + endforeach() + + swift_is_installing_component("${SWIFTLIB_INSTALL_IN_COMPONENT}" is_installing) + foreach(target IN LISTS INSTALLABLE_SHARED_TARGETS INSTALLABLE_STATIC_TARGETS) + get_target_property(target_exports "${target}" SWIFTLIB_INSTALL_EXPORT_TARGETS) + + # Some static targets are not exported. + if(target_exports) + if(NOT is_installing) + set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${target_exports}) + else() + set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${target_exports}) endif() endif() endforeach() @@ -2104,8 +2137,13 @@ function(_add_swift_executable_single name) set(link_flags) # Prepare linker search directories. - set(library_search_directories - "${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}") + if(SWIFTEXE_SINGLE_SDK IN_LIST SWIFT_APPLE_PLATFORMS) + set(library_search_directories + "${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}") + else() + set(library_search_directories + "${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}/${SWIFTEXE_SINGLE_ARCHITECTURE}") + endif() # Add variant-specific flags. _add_variant_c_compile_flags( @@ -2127,20 +2165,20 @@ function(_add_swift_executable_single name) RESULT_VAR_NAME link_flags LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories) + if(SWIFTEXE_SINGLE_DISABLE_ASLR) + list(APPEND link_flags "-Wl,-no_pie") + endif() + if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS) list(APPEND link_flags "-Xlinker" "-rpath" "-Xlinker" "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}") endif() - # Find the names of dependency library targets. - # - # We don't add the ${ARCH} to the target suffix because we want to link - # against fat libraries. - _list_add_string_suffix( - "${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES}" - "-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}" - SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS) + _compute_library_dependency_targets("${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES}" + "${SWIFTEXE_SINGLE_SDK}" + "${SWIFTEXE_SINGLE_ARCHITECTURE}" + SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS) handle_swift_sources( dependency_target @@ -2245,12 +2283,10 @@ function(add_swift_target_executable name) add_dependencies("swift-test-stdlib${VARIANT_SUFFIX}" ${VARIANT_NAME}) endif() - # Don't add the ${arch} to the suffix. We want to link against fat - # libraries. - _list_add_string_suffix( - "${SWIFTEXE_TARGET_DEPENDS}" - "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}" - SWIFTEXE_TARGET_DEPENDS_with_suffix) + _compute_library_dependency_targets("${SWIFTEXE_TARGET_DEPENDS}" + "${sdk}" + "${arch}" + SWIFTEXE_TARGET_DEPENDS_with_suffix) _add_swift_executable_single( ${VARIANT_NAME} ${SWIFTEXE_TARGET_SOURCES} diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 77aa04336e4cc..cbc4c9ccfd9d1 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -74,6 +74,8 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job, SmallString<128> runtimeLibraryPath; getRuntimeLibraryPath(runtimeLibraryPath, context.Args, /*Shared=*/true); + llvm::sys::path::append(runtimeLibraryPath, + swift::getMajorArchitectureName(getTriple())); addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "LD_LIBRARY_PATH", ":", options::OPT_L, context.Args, @@ -209,9 +211,13 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, SmallString<128> SharedRuntimeLibPath; getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, /*Shared=*/true); + llvm::sys::path::append(SharedRuntimeLibPath, + swift::getMajorArchitectureName(getTriple())); SmallString<128> StaticRuntimeLibPath; getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, /*Shared=*/false); + llvm::sys::path::append(StaticRuntimeLibPath, + swift::getMajorArchitectureName(getTriple())); // Add the runtime library link path, which is platform-specific and found // relative to the compiler. @@ -225,8 +231,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, } SmallString<128> swiftrtPath = SharedRuntimeLibPath; - llvm::sys::path::append(swiftrtPath, - swift::getMajorArchitectureName(getTriple())); llvm::sys::path::append(swiftrtPath, "swiftrt.o"); Arguments.push_back(context.Args.MakeArgString(swiftrtPath)); @@ -263,6 +267,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath)); SmallString<128> linkFilePath = StaticRuntimeLibPath; + llvm::sys::path::remove_filename(linkFilePath); // remove arch name llvm::sys::path::append(linkFilePath, "static-executable-args.lnk"); auto linkFile = linkFilePath.str(); @@ -276,6 +281,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath)); SmallString<128> linkFilePath = StaticRuntimeLibPath; + llvm::sys::path::remove_filename(linkFilePath); // remove arch name llvm::sys::path::append(linkFilePath, "static-stdlib-args.lnk"); auto linkFile = linkFilePath.str(); if (llvm::sys::fs::is_regular_file(linkFile)) { @@ -313,6 +319,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, if (context.Args.hasArg(options::OPT_profile_generate)) { SmallString<128> LibProfile(SharedRuntimeLibPath); + llvm::sys::path::remove_filename(LibProfile); // remove arch name llvm::sys::path::remove_filename(LibProfile); // remove platform name llvm::sys::path::append(LibProfile, "clang", "lib"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index fc21d7b25f65b..d64b0e1b01d44 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -47,10 +47,19 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts, llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath); llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple)); - SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + // Darwin platforms use the platform name as runtime library path. + if (Triple.isOSDarwin()) { + SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + } llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple)); SearchPathOpts.RuntimeLibraryImportPath = LibPath.str(); + + // Non-Darwin platforms use the platform name and the architecture as runtime + // library path. + if (!Triple.isOSDarwin()) { + SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + } } void CompilerInvocation::setRuntimeResourcePath(StringRef Path) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d4350d03b14e6..7dacfdd3a80b8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -204,9 +204,16 @@ foreach(SDK ${SWIFT_SDKS}) list(APPEND test_dependencies "touch-covering-tests") endif() + # In Darwin, we depend on the fat targets. + if(sdk IN_LIST SWIFT_APPLE_PLATFORMS) + set(validation_test_dependencies_suffix "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}") + else() + set(validation_test_dependencies_suffix "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}") + endif() + set(validation_test_dependencies - "swiftStdlibCollectionUnittest-${SWIFT_SDK_${SDK}_LIB_SUBDIR}" - "swiftStdlibUnicodeUnittest-${SWIFT_SDK_${SDK}_LIB_SUBDIR}") + "swiftStdlibCollectionUnittest${validation_test_dependencies_suffix}" + "swiftStdlibUnicodeUnittest${validation_test_dependencies_suffix}") set(command_upload_stdlib) set(command_upload_swift_reflection_test) @@ -234,7 +241,7 @@ foreach(SDK ${SWIFT_SDKS}) --ndk "${SWIFT_ANDROID_NDK_PATH}" --destination "${SWIFT_ANDROID_DEPLOY_DEVICE_PATH}" # Build products like libswiftCore.so. - "${SWIFTLIB_DIR}/android" + "${SWIFTLIB_DIR}/android/${ARCH}" # These two directories may contain the same libraries, # but upload both to device just in case. Duplicates will be # overwritten, and uploading doesn't take very long anyway. diff --git a/test/Driver/environment.swift b/test/Driver/environment.swift index 90a6cbde4899f..26c3313b45ad3 100644 --- a/test/Driver/environment.swift +++ b/test/Driver/environment.swift @@ -3,5 +3,5 @@ // RUN: %swift_driver -target x86_64-unknown-gnu-linux -L/foo/ -driver-use-frontend-path %S/Inputs/print-var.sh %s LD_LIBRARY_PATH | %FileCheck -check-prefix=CHECK${LD_LIBRARY_PATH+_LAX} %s -// CHECK: {{^/foo/:[^:]+/lib/swift/linux$}} -// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux}} +// CHECK: {{^/foo/:[^:]+/lib/swift/linux/x86_64$}} +// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux/x86_64}} diff --git a/test/Driver/options-interpreter.swift b/test/Driver/options-interpreter.swift index 3a7bd0e94eb3b..baf98e7b3854f 100644 --- a/test/Driver/options-interpreter.swift +++ b/test/Driver/options-interpreter.swift @@ -18,8 +18,8 @@ // CHECK-RESOURCE-DIR-ONLY: # DYLD_LIBRARY_PATH=/RSRC/macosx{{$}} // RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -resource-dir /RSRC/ %s | %FileCheck -check-prefix=CHECK-RESOURCE-DIR-ONLY-LINUX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux{{$}} -// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux{{$|:}} +// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$}} +// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$|:}} // RUN: %swift_driver -### -target x86_64-apple-macosx10.9 -L/foo/ %s | %FileCheck -check-prefix=CHECK-L %s // CHECK-L: # DYLD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/macosx$}} @@ -59,9 +59,9 @@ // CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx($| )}} // RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -L/foo/ %s | %FileCheck -check-prefix=CHECK-L-LINUX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux$}} -// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux($|:)}} +// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64$}} +// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64($|:)}} // RUN: env LD_LIBRARY_PATH=/abc/ %swift_driver_plain -### -target x86_64-unknown-linux-gnu -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-LINUX-COMPLEX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/$}} -// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/($|:)}} +// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/$}} +// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/($|:)}} diff --git a/validation-test/execution/interpret-with-dependencies-linux.swift b/validation-test/execution/interpret-with-dependencies-linux.swift index 809d9b154b124..33f0ee783127d 100644 --- a/validation-test/execution/interpret-with-dependencies-linux.swift +++ b/validation-test/execution/interpret-with-dependencies-linux.swift @@ -8,9 +8,9 @@ // CHECK: {{okay}} // Now test a dependency on a library in the compiler's resource directory. -// RUN: %empty-directory(%t/rsrc/%target-sdk-name) -// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/ -// RUN: ln -s %platform-module-dir/../* %t/rsrc/%target-sdk-name/ +// RUN: %empty-directory(%t/rsrc/%target-sdk-name/%target-cpu) +// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/%target-cpu +// RUN: ln -s %platform-module-dir/* %t/rsrc/%target-sdk-name/%target-cpu // RUN: ln -s %platform-module-dir/../../shims %t/rsrc/ // RUN: %empty-directory(%t/other) // RUN: ln -s %t/libfoo.so %t/other