Skip to content

Commit

Permalink
[ClangImporter] Drop the version from Clang's resource directory.
Browse files Browse the repository at this point in the history
Background: Clang has a set of base headers distributed with the compiler
that contain things like vector operations, stddef.h, and tgmath.h.
Swift also needs these headers in order to import C and Objective-C (not
really a surprise), so we symlink to them from lib/swift/clang/. When we
build installable packages, we actually copy them in.

Now the tricky part. Clang's headers are actually at a path like
"include/clang/3.6.0/include/tgmath.h". That "3.6.0" is the Clang version,
which allows multiple Clangs to be installed on a single system. Swift
currently links to the top-level directory, but of course it's only
guaranteed to work with a specific version of the Clang headers. So the
version number here is always the version of Clang we use to build Swift.

Rather than leave the (relatively meaningless) version number here, just
make the symlink point at the "3.6.0" directory rather than the "clang"
directory. This means Swift doesn't have to think about the version number
here at all.

rdar://problem/23223066
  • Loading branch information
jrose-apple committed Nov 13, 2015
1 parent 58cfa27 commit e6bdcbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ addCommonInvocationArguments(std::vector<std::string> &invocationArgStrs,
// assuming that the Clang resource directory is located next to it is that
// Swift, when installed separately, should not need to install files in
// directories that are not "owned" by it.
llvm::sys::path::append(resourceDir, "clang", CLANG_VERSION_STRING);
llvm::sys::path::append(resourceDir, "clang");

// Set the Clang resource directory to the path we computed.
invocationArgStrs.push_back("-resource-dir");
Expand Down
10 changes: 7 additions & 3 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ add_custom_command_target(unused_var
COMMENT "Copying SwiftShims module to ${output_dir}")

# Symlink in the Clang headers.
# First extract the "version" used for Clang's resource directory.
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
${LLVM_PACKAGE_VERSION})
set(clang_headers_locations
"${LLVM_LIBRARY_DIR}/clang"
"${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION}"

# FIXME: if we want to support separate Clang builds and mix different
# build configurations of Clang and Swift, this line should be adjusted.
"${SWIFT_PATH_TO_CLANG_BUILD}/${CMAKE_CFG_INTDIR}/lib/clang")
"${SWIFT_PATH_TO_CLANG_BUILD}/${CMAKE_CFG_INTDIR}/lib/clang/${CLANG_VERSION}")

set(clang_headers_location)
foreach(loc ${clang_headers_locations})
if("${clang_headers_location}" STREQUAL "" AND EXISTS "${loc}")
if(EXISTS "${loc}")
set(clang_headers_location "${loc}")
break()
endif()
endforeach()
if("${clang_headers_location}" STREQUAL "")
Expand Down

0 comments on commit e6bdcbc

Please sign in to comment.