Skip to content

Commit

Permalink
[libc++] Fix compiler-rt build by copying libc++ headers to <build>/i…
Browse files Browse the repository at this point in the history
…nclude

This commit should really be named "Workaround external projects depending
on libc++ build system implementation details". It seems that the compiler-rt
build (and perhaps other projects) is relying on the fact that we copy libc++
and libc++abi headers to `<build-root>/include/c++/v1`. This was changed
by 5d79664, which moved the headers to `<build-root>/projects/libcxx/include/c++/v1`
and broke the compiler-rt build.

I'm committing this workaround to fix the compiler-rt build, but we should
remove reliance on implementation details like that. The correct way to
setup the compiler-rt build would be to "link" against the `cxx-headers`
target in CMake, or to run `install-cxx-headers` using an appropriate
installation prefix, and then manually add a `-I` path to that location.
  • Loading branch information
ldionne committed Oct 21, 2020
1 parent ac2cf07 commit 69c2087
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ set(CMAKE_MODULE_PATH
set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
set(LIBCXX_GENERATED_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++/v1")

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD)
project(libcxx CXX C)
Expand Down Expand Up @@ -398,21 +397,23 @@ endif ()
# Configure System
#===============================================================================

# TODO: Other projects rely on the location where we generate the libc++ headers
# internally. We should get rid of these dependencies.
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
if(LIBCXX_LIBDIR_SUBDIR)
string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
endif()
elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX})
else()
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
set(LIBCXX_HEADER_DIR ${CMAKE_BINARY_DIR})
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX})
endif()

Expand Down
6 changes: 4 additions & 2 deletions libcxx/cmake/Modules/HandleLibCXXABI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs)
COMMENT "Copying C++ ABI header ${fpath}...")
list(APPEND abilib_headers "${dst}")

if (LIBCXX_HEADER_DIR)
set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
if (LIBCXX_GENERATED_INCLUDE_DIR) # always true
# TODO: libc++ shouldn't be responsible for copying the libc++abi
# headers into the right location.
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/include/c++/v1/${dstdir}/${fpath}")
add_custom_command(OUTPUT ${dst}
DEPENDS ${src}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ if(LIBCXX_INSTALL_SUPPORT_HEADERS)
)
endif()

if(LIBCXX_HEADER_DIR)
if (LIBCXX_GENERATED_INCLUDE_DIR) # Always true
configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site" @ONLY)

set(_all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site")
Expand Down
2 changes: 1 addition & 1 deletion libcxxabi/test/libcxxabi/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def configure_compile_flags(self):
def configure_compile_flags_header_includes(self):
cxx_headers = self.get_lit_conf(
'cxx_headers',
os.path.join(self.libcxx_obj_root, 'include', 'c++', 'v1'))
os.path.join(self.project_obj_root, 'include', 'c++', 'v1'))
if cxx_headers == '':
self.lit_config.note('using the systems c++ headers')
else:
Expand Down

0 comments on commit 69c2087

Please sign in to comment.