Skip to content

Commit 43feb9c

Browse files
authored
On Apple platforms, use swiftmodule directories for the stdlib (swiftlang#21797)
This changes the Swift resource directory from looking like lib/ swift/ macosx/ libswiftCore.dylib libswiftDarwin.dylib x86_64/ Swift.swiftmodule Swift.swiftdoc Darwin.swiftmodule Darwin.swiftdoc to lib/ swift/ macosx/ libswiftCore.dylib libswiftDarwin.dylib Swift.swiftmodule/ x86_64.swiftmodule x86_64.swiftdoc Darwin.swiftmodule/ x86_64.swiftmodule x86_64.swiftdoc matching the layout we use for multi-architecture swiftmodules everywhere else (particularly frameworks). There's no change in this commit to how Linux swiftmodules are packaged. There's been past interest in going the /opposite/ direction for Linux, since there's not standard support for fat (multi-architecture) .so libraries. Moving the .so search path /down/ to an architecture-specific directory on Linux would allow the same resource directory to be used for both host-compiling and cross-compiling. rdar://problem/43545560
1 parent f879607 commit 43feb9c

33 files changed

+235
-118
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ endfunction()
3030
# Compute the library subdirectory to use for the given sdk and
3131
# architecture, placing the result in 'result_var_name'.
3232
function(compute_library_subdir result_var_name sdk arch)
33-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
33+
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
34+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
35+
else()
36+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
37+
endif()
3438
endfunction()
3539

3640
function(_compute_lto_flag option out_var)
@@ -1156,6 +1160,8 @@ function(_add_swift_library_single target name)
11561160
# Don't set PROPERTY COMPILE_FLAGS or LINK_FLAGS directly.
11571161
set(c_compile_flags ${SWIFTLIB_SINGLE_C_COMPILE_FLAGS})
11581162
set(link_flags ${SWIFTLIB_SINGLE_LINK_FLAGS})
1163+
1164+
set(library_search_subdir "${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
11591165
set(library_search_directories
11601166
"${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
11611167
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
@@ -1300,6 +1306,7 @@ function(_add_swift_library_single target name)
13001306
if(target_static)
13011307
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
13021308
COMPILE_FLAGS " ${c_compile_flags}")
1309+
# FIXME: The fallback paths here are going to be dynamic libraries.
13031310
set(library_search_directories
13041311
"${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
13051312
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"

cmake/modules/SwiftSource.cmake

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ function(handle_swift_sources
6161
endif()
6262

6363
if(swift_sources)
64-
compute_library_subdir(SWIFTSOURCES_LIBRARY_SUBDIR
65-
"${SWIFTSOURCES_SDK}" "${SWIFTSOURCES_ARCHITECTURE}")
66-
set(objsubdir "/${SWIFTSOURCES_LIBRARY_SUBDIR}")
64+
set(objsubdir "/${SWIFTSOURCES_SDK}/${SWIFTSOURCES_ARCHITECTURE}")
6765

6866
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${objsubdir}")
6967

@@ -255,6 +253,8 @@ function(_compile_swift_files
255253
"-nostdimport" "-parse-stdlib" "-module-name" "Swift")
256254
list(APPEND swift_flags "-Xfrontend" "-group-info-path"
257255
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
256+
else()
257+
list(APPEND swift_flags "-module-name" "${SWIFTFILE_MODULE_NAME}")
258258
endif()
259259

260260
# Force swift 5 mode for Standard Library.
@@ -313,19 +313,32 @@ function(_compile_swift_files
313313
list(APPEND swift_flags "-parse-as-library")
314314

315315
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
316+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
317+
set(specific_module_dir "${module_base}.swiftmodule")
318+
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
319+
endif()
316320
set(module_file "${module_base}.swiftmodule")
321+
set(module_doc_file "${module_base}.swiftdoc")
322+
323+
# FIXME: These don't really belong inside the swiftmodule, but there's not
324+
# an obvious alternate place to put them.
317325
set(sib_file "${module_base}.Onone.sib")
318326
set(sibopt_file "${module_base}.O.sib")
319327
set(sibgen_file "${module_base}.sibgen")
320-
set(module_doc_file "${module_base}.swiftdoc")
321328

322329
if(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES)
323330
set(interface_file "${module_base}.swiftinterface")
324-
list(APPEND swift_flags "-emit-parseable-module-interface")
331+
list(APPEND swift_flags
332+
"-emit-parseable-module-interface-path" "${interface_file}")
325333
endif()
326334

327-
list(APPEND command_create_dirs
328-
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
335+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
336+
list(APPEND command_create_dirs
337+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${specific_module_dir}")
338+
else()
339+
list(APPEND command_create_dirs
340+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
341+
endif()
329342

330343
# If we have extra regexp flags, check if we match any of the regexps. If so
331344
# add the relevant flags to our swift_flags.
@@ -349,10 +362,15 @@ function(_compile_swift_files
349362
set(optional_arg "OPTIONAL")
350363
endif()
351364

352-
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
353-
FILES ${module_outputs}
354-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
355-
"${optional_arg}")
365+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
366+
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
367+
DIRECTORY "${specific_module_dir}"
368+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
369+
else()
370+
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
371+
FILES ${module_outputs}
372+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
373+
endif()
356374

357375
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
358376
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts,
4949
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
5050
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
5151

52-
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
52+
if (!Triple.isOSDarwin())
53+
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
5354
SearchPathOpts.RuntimeLibraryImportPath = LibPath.str();
5455
}
5556

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,21 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
301301

302302
// Search the runtime import path.
303303
isFramework = false;
304-
return !findModuleFilesInDirectory(
305-
moduleID, Ctx.SearchPathOpts.RuntimeLibraryImportPath,
306-
moduleFilename.str(), moduleDocFilename.str(), moduleBuffer,
307-
moduleDocBuffer);
304+
currPath = Ctx.SearchPathOpts.RuntimeLibraryImportPath;
305+
if (Ctx.LangOpts.Target.isOSDarwin()) {
306+
// Apple platforms always use architecture-specific files within a
307+
// .swiftmodule directory for the stdlib.
308+
llvm::sys::path::append(currPath, moduleFilename.str());
309+
return !findModuleFilesInDirectory(moduleID, currPath,
310+
archFileNames.first,
311+
archFileNames.second,
312+
moduleBuffer, moduleDocBuffer);
313+
}
314+
// Non-Apple platforms always use single-architecture swiftmodules.
315+
return !findModuleFilesInDirectory(moduleID, currPath,
316+
moduleFilename.str(),
317+
moduleDocFilename.str(),
318+
moduleBuffer, moduleDocBuffer);
308319
}
309320

310321
static std::pair<StringRef, clang::VersionTuple>

test/DebugInfo/Imports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// CHECK-DAG: ![[FOOMODULE:[0-9]+]] = !DIModule({{.*}}, name: "Foo", includePath: "{{.*}}test{{.*}}DebugInfo{{.*}}"
99
// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE:[0-9]+]], entity: ![[FOOMODULE]]
1010
// CHECK-DAG: ![[THISFILE]] = !DIFile(filename: "{{.*}}test{{/|\\5C}}DebugInfo{{/|\\5C}}Imports.swift",
11-
// CHECK-DAG: ![[SWIFTFILE:[0-9]+]] = !DIFile(filename: "{{.*}}Swift.swiftmodule"
11+
// CHECK-DAG: ![[SWIFTFILE:[0-9]+]] = !DIFile(filename: "{{.*}}Swift.swiftmodule{{(/.+[.]swiftmodule)?}}"
1212
// CHECK-DAG: ![[SWIFTMODULE:[0-9]+]] = !DIModule({{.*}}, name: "Swift"
1313
// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE]], entity: ![[SWIFTMODULE]]
1414
// CHECK-DAG: ![[BASICMODULE:[0-9]+]] = !DIModule({{.*}}, name: "basic"

test/DebugInfo/variables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ print(", \(glob_b)", terminator: "")
4141
print(", \(glob_s)", terminator: "")
4242
var unused: Int32 = -1
4343

44-
// CHECK-DAG: ![[RT:[0-9]+]] ={{.*}}"{{.*}}Swift.swiftmodule"
44+
// CHECK-DAG: ![[RT:[0-9]+]] ={{.*}}"{{.*}}Swift.swiftmodule{{(/.+[.]swiftmodule)?}}"
4545

4646

4747
// Stack variables.

test/Driver/loaded_module_trace.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// CHECK: "name":"loaded_module_trace"
1010
// CHECK: "arch":"{{[^"]*}}"
1111
// CHECK: "swiftmodules":[
12-
// CHECK: "{{[^"]*(/|\\\\)}}Module2.swiftmodule"
13-
// CHECK: "{{[^"]*(/|\\\\)}}Swift.swiftmodule"
14-
// CHECK: "{{[^"]*(/|\\\\)}}SwiftOnoneSupport.swiftmodule"
12+
// CHECK: "{{[^"]*\\[/\\]}}Module2.swiftmodule"
13+
// CHECK: "{{[^"]*\\[/\\]}}Swift.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}"
14+
// CHECK: "{{[^"]*\\[/\\]}}SwiftOnoneSupport.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}"
1515
// CHECK: ]
1616
// CHECK: }
1717

test/Driver/loaded_module_trace_env.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK: "name":"loaded_module_trace_env"
77
// CHECK: "arch":"{{[^"]*}}"
88
// CHECK: "swiftmodules":[
9-
// CHECK: "{{[^"]*(/|\\\\)}}Swift.swiftmodule"
10-
// CHECK: "{{[^"]*(/|\\\\)}}SwiftOnoneSupport.swiftmodule"
9+
// CHECK: "{{[^"]*\\[/\\]}}Swift.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}"
10+
// CHECK: "{{[^"]*\\[/\\]}}SwiftOnoneSupport.swiftmodule{{(\\[/\\][^"]+[.]swiftmodule)?}}"
1111
// CHECK: ]
1212
// CHECK: }

test/Driver/loaded_module_trace_foundation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// CHECK: "name":"loaded_module_trace_foundation"
77
// CHECK: "arch":"{{[^"]*}}"
88
// CHECK: "swiftmodules":[
9-
// CHECK: "{{[^"]*}}/ObjectiveC.swiftmodule"
10-
// CHECK: "{{[^"]*}}/Dispatch.swiftmodule"
11-
// CHECK: "{{[^"]*}}/Darwin.swiftmodule"
12-
// CHECK: "{{[^"]*}}/Foundation.swiftmodule"
13-
// CHECK: "{{[^"]*}}/Swift.swiftmodule"
14-
// CHECK: "{{[^"]*}}/SwiftOnoneSupport.swiftmodule"
9+
// CHECK: "{{[^"]*}}/ObjectiveC.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
10+
// CHECK: "{{[^"]*}}/Dispatch.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
11+
// CHECK: "{{[^"]*}}/Darwin.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
12+
// CHECK: "{{[^"]*}}/Foundation.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
13+
// CHECK: "{{[^"]*}}/Swift.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
14+
// CHECK: "{{[^"]*}}/SwiftOnoneSupport.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
1515
// CHECK: ]
1616
// CHECK: }
1717

test/Driver/loaded_module_trace_header.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// CHECK: "name":"loaded_module_trace_header"
99
// CHECK: "arch":"{{[^"]*}}"
1010
// CHECK: "swiftmodules":[
11-
// CHECK: "{{[^"]*}}/ObjectiveC.swiftmodule"
12-
// CHECK: "{{[^"]*}}/Dispatch.swiftmodule"
13-
// CHECK: "{{[^"]*}}/Darwin.swiftmodule"
14-
// CHECK: "{{[^"]*}}/Foundation.swiftmodule"
15-
// CHECK: "{{[^"]*}}/Swift.swiftmodule"
16-
// CHECK: "{{[^"]*}}/SwiftOnoneSupport.swiftmodule"
11+
// CHECK: "{{[^"]*}}/ObjectiveC.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
12+
// CHECK: "{{[^"]*}}/Dispatch.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
13+
// CHECK: "{{[^"]*}}/Darwin.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
14+
// CHECK: "{{[^"]*}}/Foundation.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
15+
// CHECK: "{{[^"]*}}/Swift.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
16+
// CHECK: "{{[^"]*}}/SwiftOnoneSupport.swiftmodule{{(\\/[^"]+[.]swiftmodule)?}}"
1717
// CHECK: ]
1818
// CHECK: }

0 commit comments

Comments
 (0)