Skip to content

Commit 5befdc3

Browse files
committed
Merge pull request #1703 from apple/revert-1679-target-specific-glibc
Revert "[Glibc] Configure modulemap for target, not host"
2 parents d367088 + f2154ee commit 5befdc3

File tree

4 files changed

+43
-91
lines changed

4 files changed

+43
-91
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
319319
// Enable modules.
320320
"-fmodules",
321321

322-
// Enable implicit module maps (this option is implied by "-fmodules").
322+
// Enable implicit module maps
323323
"-fimplicit-module-maps",
324324

325325
// Don't emit LLVM IR.
@@ -382,35 +382,6 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
382382
// Just use the most feature-rich C language mode.
383383
"-x", "c", "-std=gnu11",
384384
});
385-
386-
// The module map used for Glibc depends on the target we're compiling for,
387-
// and is not included in the resource directory with the other implicit
388-
// module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
389-
SmallString<128> GlibcModuleMapPath;
390-
if (!importerOpts.OverrideResourceDir.empty()) {
391-
GlibcModuleMapPath = importerOpts.OverrideResourceDir;
392-
} else if (!searchPathOpts.RuntimeResourcePath.empty()) {
393-
GlibcModuleMapPath = searchPathOpts.RuntimeResourcePath;
394-
}
395-
396-
// Running without a resource directory is not a supported configuration.
397-
assert(!GlibcModuleMapPath.empty());
398-
399-
llvm::sys::path::append(
400-
GlibcModuleMapPath,
401-
swift::getPlatformNameForTriple(triple), triple.getArchName(),
402-
"glibc.modulemap");
403-
404-
// Only specify the module map if that file actually exists.
405-
// It may not--for example in the case that
406-
// `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using
407-
// a Swift compiler not built for Linux targets.
408-
if (llvm::sys::fs::exists(GlibcModuleMapPath)) {
409-
invocationArgStrs.push_back(
410-
(Twine("-fmodule-map-file=") + GlibcModuleMapPath).str());
411-
} else {
412-
// FIXME: Emit a warning of some kind.
413-
}
414385
}
415386

416387
if (triple.isOSDarwin()) {

stdlib/public/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ if(SWIFT_BUILD_STDLIB)
3131
add_subdirectory(stubs)
3232
add_subdirectory(core)
3333
add_subdirectory(SwiftOnoneSupport)
34-
add_subdirectory(Glibc)
3534
endif()
3635

3736
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
3837
if(SWIFT_BUILD_SDK_OVERLAY)
3938
add_subdirectory(SDK)
4039
endif()
4140
endif()
41+
42+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
43+
add_subdirectory(Glibc)
44+
endif()

stdlib/public/Glibc/CMakeLists.txt

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,44 @@ set(sources
33
Misc.c
44
)
55

6-
# When cross-compiling the stdlib on Unix platforms, we'll need a separate
7-
# glibc for each target.
8-
foreach(SDK ${SWIFT_SDKS})
9-
foreach(arch ${SWIFT_SDK_${SDK}_ARCHITECTURES})
10-
set(output_dir "${SWIFTLIB_DIR}/${SWIFT_SDK_${SDK}_LIB_SUBDIR}/${arch}")
6+
set(output_dir "${SWIFTLIB_DIR}/glibc")
117

12-
# Determine the location of glibc based on the target.
13-
set(GLIBC_INCLUDE_PATH "/usr/include")
14-
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
15-
if(("${SDK}" STREQUAL "LINUX" OR "${SDK}" STREQUAL "FREEBSD") AND CMAKE_LIBRARY_ARCHITECTURE)
16-
# FIXME: Some distributions install headers in
17-
# "/usr/include/x86_64-linux-gnu/sys/...". Here we use the host
18-
# machine's path, regardless of the SDK target we're building for.
19-
# This will break if cross-compiling from a distro that uses the
20-
# architecture as part of the path to a distro that does not.
21-
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
22-
endif()
8+
# Set correct paths to glibc headers
9+
set(GLIBC_INCLUDE_PATH "/usr/include")
10+
if(CMAKE_LIBRARY_ARCHITECTURE)
11+
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
12+
else()
13+
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
14+
endif()
15+
if (NOT EXISTS "${GLIBC_ARCH_INCLUDE_PATH}/sys")
16+
message(FATAL_ERROR "Glibc headers were not found.")
17+
endif()
2318

24-
# Configure the modulemap based on the target. Each platform needs to
25-
# reference different headers, based on what's available in their glibc.
26-
set(modulemap_path "${CMAKE_CURRENT_BINARY_DIR}/${SWIFT_SDK_${SDK}_LIB_SUBDIR}/${arch}/module.map")
27-
if("${SDK}" STREQUAL "FREEBSD")
28-
configure_file(module.freebsd.map.in "${modulemap_path}" @ONLY)
29-
else()
30-
configure_file(module.map.in "${modulemap_path}" @ONLY)
31-
endif()
19+
# Generate module.map
20+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
21+
configure_file(module.map.in "${CMAKE_CURRENT_BINARY_DIR}/module.map" @ONLY)
22+
endif()
23+
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
24+
configure_file(module.freebsd.map.in "${CMAKE_CURRENT_BINARY_DIR}/module.map" @ONLY)
25+
endif()
3226

33-
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${arch}")
34-
add_custom_command_target(unused_var
35-
COMMAND
36-
"${CMAKE_COMMAND}" "-E" "make_directory" "${output_dir}"
37-
COMMAND
38-
"${CMAKE_COMMAND}" "-E" "copy_if_different"
39-
"${modulemap_path}"
40-
"${output_dir}/glibc.modulemap"
41-
CUSTOM_TARGET_NAME "copy_glibc_module${VARIANT_SUFFIX}"
42-
OUTPUT "${output_dir}/glibc.modulemap" "${output_dir}"
43-
DEPENDS "${modulemap_path}"
44-
COMMENT "Copying Glibc module to ${output_dir}")
27+
add_custom_command_target(unused_var
28+
COMMAND
29+
"${CMAKE_COMMAND}" "-E" "make_directory" "${output_dir}"
30+
COMMAND
31+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
32+
"${CMAKE_CURRENT_BINARY_DIR}/module.map"
33+
"${output_dir}/module.map"
34+
CUSTOM_TARGET_NAME "copy_glibc_module"
35+
OUTPUT "${output_dir}/module.map" "${output_dir}"
36+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/module.map"
37+
COMMENT "Copying Glibc module to ${output_dir}")
4538

46-
swift_install_in_component(stdlib
47-
FILES "${output_dir}/glibc.modulemap"
48-
DESTINATION "${output_dir}")
39+
swift_install_in_component(stdlib
40+
FILES "${output_dir}/module.map"
41+
DESTINATION "lib/swift/glibc")
4942

50-
if("${SDK}" STREQUAL "LINUX" OR "${SDK}" STREQUAL "${FREEBSD}")
51-
add_swift_library(swiftGlibc IS_SDK_OVERLAY
52-
${sources}
53-
FILE_DEPENDS "copy_glibc_module${VARIANT_SUFFIX}" "${output_dir}"
54-
TARGET_SDKS "${SDK}"
55-
INSTALL_IN_COMPONENT stdlib-experimental)
56-
endif()
57-
endforeach()
58-
endforeach()
43+
add_swift_library(swiftGlibc IS_SDK_OVERLAY
44+
${sources}
45+
FILE_DEPENDS copy_glibc_module "${output_dir}"
46+
INSTALL_IN_COMPONENT stdlib-experimental)

tools/driver/modulewrap_main.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,10 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
153153
return 1;
154154
}
155155

156-
// Wrap the bitstream in a module object file. To use the ClangImporter to
157-
// create the module loader, we need to properly set the runtime library path.
158-
SearchPathOptions SearchPathOpts;
159-
// FIXME: This logic has been duplicated from
160-
// CompilerInvocation::setMainExecutablePath. ModuleWrapInvocation
161-
// should share its implementation.
162-
SmallString<128> RuntimeResourcePath(MainExecutablePath);
163-
llvm::sys::path::remove_filename(RuntimeResourcePath); // Remove /swift
164-
llvm::sys::path::remove_filename(RuntimeResourcePath); // Remove /bin
165-
llvm::sys::path::append(RuntimeResourcePath, "lib", "swift");
166-
SearchPathOpts.RuntimeResourcePath = RuntimeResourcePath.str();
167-
156+
// Wrap the bitstream in an object file.
168157
SourceManager SrcMgr;
169158
LangOptions LangOpts;
159+
SearchPathOptions SearchPathOpts;
170160
LangOpts.Target = Invocation.getTargetTriple();
171161
ASTContext ASTCtx(LangOpts, SearchPathOpts, SrcMgr, Instance.getDiags());
172162
ClangImporterOptions ClangImporterOpts;

0 commit comments

Comments
 (0)