mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[Glibc] Configure modulemap for target, not host"
This commit is contained in:
@@ -319,7 +319,7 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
|
|||||||
// Enable modules.
|
// Enable modules.
|
||||||
"-fmodules",
|
"-fmodules",
|
||||||
|
|
||||||
// Enable implicit module maps (this option is implied by "-fmodules").
|
// Enable implicit module maps
|
||||||
"-fimplicit-module-maps",
|
"-fimplicit-module-maps",
|
||||||
|
|
||||||
// Don't emit LLVM IR.
|
// Don't emit LLVM IR.
|
||||||
@@ -382,35 +382,6 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
|
|||||||
// Just use the most feature-rich C language mode.
|
// Just use the most feature-rich C language mode.
|
||||||
"-x", "c", "-std=gnu11",
|
"-x", "c", "-std=gnu11",
|
||||||
});
|
});
|
||||||
|
|
||||||
// The module map used for Glibc depends on the target we're compiling for,
|
|
||||||
// and is not included in the resource directory with the other implicit
|
|
||||||
// module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
|
|
||||||
SmallString<128> GlibcModuleMapPath;
|
|
||||||
if (!importerOpts.OverrideResourceDir.empty()) {
|
|
||||||
GlibcModuleMapPath = importerOpts.OverrideResourceDir;
|
|
||||||
} else if (!searchPathOpts.RuntimeResourcePath.empty()) {
|
|
||||||
GlibcModuleMapPath = searchPathOpts.RuntimeResourcePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Running without a resource directory is not a supported configuration.
|
|
||||||
assert(!GlibcModuleMapPath.empty());
|
|
||||||
|
|
||||||
llvm::sys::path::append(
|
|
||||||
GlibcModuleMapPath,
|
|
||||||
swift::getPlatformNameForTriple(triple), triple.getArchName(),
|
|
||||||
"glibc.modulemap");
|
|
||||||
|
|
||||||
// Only specify the module map if that file actually exists.
|
|
||||||
// It may not--for example in the case that
|
|
||||||
// `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using
|
|
||||||
// a Swift compiler not built for Linux targets.
|
|
||||||
if (llvm::sys::fs::exists(GlibcModuleMapPath)) {
|
|
||||||
invocationArgStrs.push_back(
|
|
||||||
(Twine("-fmodule-map-file=") + GlibcModuleMapPath).str());
|
|
||||||
} else {
|
|
||||||
// FIXME: Emit a warning of some kind.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triple.isOSDarwin()) {
|
if (triple.isOSDarwin()) {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ if(SWIFT_BUILD_STDLIB)
|
|||||||
add_subdirectory(stubs)
|
add_subdirectory(stubs)
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(SwiftOnoneSupport)
|
add_subdirectory(SwiftOnoneSupport)
|
||||||
add_subdirectory(Glibc)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||||
@@ -39,3 +38,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|||||||
add_subdirectory(SDK)
|
add_subdirectory(SDK)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||||
|
add_subdirectory(Glibc)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -3,56 +3,44 @@ set(sources
|
|||||||
Misc.c
|
Misc.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# When cross-compiling the stdlib on Unix platforms, we'll need a separate
|
set(output_dir "${SWIFTLIB_DIR}/glibc")
|
||||||
# glibc for each target.
|
|
||||||
foreach(SDK ${SWIFT_SDKS})
|
|
||||||
foreach(arch ${SWIFT_SDK_${SDK}_ARCHITECTURES})
|
|
||||||
set(output_dir "${SWIFTLIB_DIR}/${SWIFT_SDK_${SDK}_LIB_SUBDIR}/${arch}")
|
|
||||||
|
|
||||||
# Determine the location of glibc based on the target.
|
# Set correct paths to glibc headers
|
||||||
set(GLIBC_INCLUDE_PATH "/usr/include")
|
set(GLIBC_INCLUDE_PATH "/usr/include")
|
||||||
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
|
if(CMAKE_LIBRARY_ARCHITECTURE)
|
||||||
if(("${SDK}" STREQUAL "LINUX" OR "${SDK}" STREQUAL "FREEBSD") AND CMAKE_LIBRARY_ARCHITECTURE)
|
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
|
||||||
# FIXME: Some distributions install headers in
|
else()
|
||||||
# "/usr/include/x86_64-linux-gnu/sys/...". Here we use the host
|
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
|
||||||
# machine's path, regardless of the SDK target we're building for.
|
endif()
|
||||||
# This will break if cross-compiling from a distro that uses the
|
if (NOT EXISTS "${GLIBC_ARCH_INCLUDE_PATH}/sys")
|
||||||
# architecture as part of the path to a distro that does not.
|
message(FATAL_ERROR "Glibc headers were not found.")
|
||||||
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
# Configure the modulemap based on the target. Each platform needs to
|
# Generate module.map
|
||||||
# reference different headers, based on what's available in their glibc.
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
set(modulemap_path "${CMAKE_CURRENT_BINARY_DIR}/${SWIFT_SDK_${SDK}_LIB_SUBDIR}/${arch}/module.map")
|
configure_file(module.map.in "${CMAKE_CURRENT_BINARY_DIR}/module.map" @ONLY)
|
||||||
if("${SDK}" STREQUAL "FREEBSD")
|
endif()
|
||||||
configure_file(module.freebsd.map.in "${modulemap_path}" @ONLY)
|
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||||
else()
|
configure_file(module.freebsd.map.in "${CMAKE_CURRENT_BINARY_DIR}/module.map" @ONLY)
|
||||||
configure_file(module.map.in "${modulemap_path}" @ONLY)
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${arch}")
|
add_custom_command_target(unused_var
|
||||||
add_custom_command_target(unused_var
|
COMMAND
|
||||||
COMMAND
|
"${CMAKE_COMMAND}" "-E" "make_directory" "${output_dir}"
|
||||||
"${CMAKE_COMMAND}" "-E" "make_directory" "${output_dir}"
|
COMMAND
|
||||||
COMMAND
|
"${CMAKE_COMMAND}" "-E" "copy_if_different"
|
||||||
"${CMAKE_COMMAND}" "-E" "copy_if_different"
|
"${CMAKE_CURRENT_BINARY_DIR}/module.map"
|
||||||
"${modulemap_path}"
|
"${output_dir}/module.map"
|
||||||
"${output_dir}/glibc.modulemap"
|
CUSTOM_TARGET_NAME "copy_glibc_module"
|
||||||
CUSTOM_TARGET_NAME "copy_glibc_module${VARIANT_SUFFIX}"
|
OUTPUT "${output_dir}/module.map" "${output_dir}"
|
||||||
OUTPUT "${output_dir}/glibc.modulemap" "${output_dir}"
|
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/module.map"
|
||||||
DEPENDS "${modulemap_path}"
|
COMMENT "Copying Glibc module to ${output_dir}")
|
||||||
COMMENT "Copying Glibc module to ${output_dir}")
|
|
||||||
|
|
||||||
swift_install_in_component(stdlib
|
swift_install_in_component(stdlib
|
||||||
FILES "${output_dir}/glibc.modulemap"
|
FILES "${output_dir}/module.map"
|
||||||
DESTINATION "${output_dir}")
|
DESTINATION "lib/swift/glibc")
|
||||||
|
|
||||||
if("${SDK}" STREQUAL "LINUX" OR "${SDK}" STREQUAL "${FREEBSD}")
|
add_swift_library(swiftGlibc IS_SDK_OVERLAY
|
||||||
add_swift_library(swiftGlibc IS_SDK_OVERLAY
|
${sources}
|
||||||
${sources}
|
FILE_DEPENDS copy_glibc_module "${output_dir}"
|
||||||
FILE_DEPENDS "copy_glibc_module${VARIANT_SUFFIX}" "${output_dir}"
|
INSTALL_IN_COMPONENT stdlib-experimental)
|
||||||
TARGET_SDKS "${SDK}"
|
|
||||||
INSTALL_IN_COMPONENT stdlib-experimental)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endforeach()
|
|
||||||
|
|||||||
@@ -153,20 +153,10 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the bitstream in a module object file. To use the ClangImporter to
|
// Wrap the bitstream in an object file.
|
||||||
// create the module loader, we need to properly set the runtime library path.
|
|
||||||
SearchPathOptions SearchPathOpts;
|
|
||||||
// FIXME: This logic has been duplicated from
|
|
||||||
// CompilerInvocation::setMainExecutablePath. ModuleWrapInvocation
|
|
||||||
// should share its implementation.
|
|
||||||
SmallString<128> RuntimeResourcePath(MainExecutablePath);
|
|
||||||
llvm::sys::path::remove_filename(RuntimeResourcePath); // Remove /swift
|
|
||||||
llvm::sys::path::remove_filename(RuntimeResourcePath); // Remove /bin
|
|
||||||
llvm::sys::path::append(RuntimeResourcePath, "lib", "swift");
|
|
||||||
SearchPathOpts.RuntimeResourcePath = RuntimeResourcePath.str();
|
|
||||||
|
|
||||||
SourceManager SrcMgr;
|
SourceManager SrcMgr;
|
||||||
LangOptions LangOpts;
|
LangOptions LangOpts;
|
||||||
|
SearchPathOptions SearchPathOpts;
|
||||||
LangOpts.Target = Invocation.getTargetTriple();
|
LangOpts.Target = Invocation.getTargetTriple();
|
||||||
ASTContext ASTCtx(LangOpts, SearchPathOpts, SrcMgr, Instance.getDiags());
|
ASTContext ASTCtx(LangOpts, SearchPathOpts, SrcMgr, Instance.getDiags());
|
||||||
ClangImporterOptions ClangImporterOpts;
|
ClangImporterOptions ClangImporterOpts;
|
||||||
|
|||||||
Reference in New Issue
Block a user