From 355c3ebd4fd20812c3c8adcb996d31c9f93a9518 Mon Sep 17 00:00:00 2001 From: Lyupa Anastasia Date: Mon, 3 Apr 2023 12:59:28 +0300 Subject: [PATCH] [BUILD][OHOS] Update libcxx include paths Install libcxx includes to include/libcxx-ohos/include/c++/v1. Update lib path in libcxx-ndk to be the same as in system build. Change libcxx target include dir to put __config_site next to __config. Update driver to add libcxx-ohos include path. Remove libcxx_ndk_install_tmp. Fix isystem path in fuzzer lib. Signed-off-by: Lyupa Anastasia --- clang/lib/Driver/ToolChains/OHOS.cpp | 11 +++++++++++ compiler-rt/lib/fuzzer/CMakeLists.txt | 6 +++--- llvm-build/build.py | 22 +++++++++++----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index f946f295147b..e12b34f15dc3 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -259,6 +259,17 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, addSystemInclude(DriverArgs, CC1Args, makePath({IncPath, "c++", "v1"})); addSystemInclude(DriverArgs, CC1Args, IncTargetPath); } + + // OHOS_LOCAL begin + + std::string IncOHOSPath = + makePath({IncPath, "libcxx-ohos", "include", "c++", "v1"}); + if (getVFS().exists(IncOHOSPath)) { + addSystemInclude(DriverArgs, CC1Args, IncOHOSPath); + } + + // OHOS_LOCAL end + break; } diff --git a/compiler-rt/lib/fuzzer/CMakeLists.txt b/compiler-rt/lib/fuzzer/CMakeLists.txt index a0532c838c27..7e2ac3a502bb 100644 --- a/compiler-rt/lib/fuzzer/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/CMakeLists.txt @@ -165,11 +165,11 @@ if(OS_NAME MATCHES "Linux|Fuchsia" AND -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF -DLIBCXX_ABI_NAMESPACE=__Fuzzer -DLIBCXX_ENABLE_EXCEPTIONS=OFF) - target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1) + target_compile_options(RTfuzzer.${arch} PRIVATE -isystem "${LIBCXX_${arch}_PREFIX}/include/c++/v1") # OHOS_LOCAL add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build) - target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1) + target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem "${LIBCXX_${arch}_PREFIX}/include/c++/v1") # OHOS_LOCAL add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build) - target_compile_options(RTfuzzer_interceptors.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1) + target_compile_options(RTfuzzer_interceptors.${arch} PRIVATE -isystem "${LIBCXX_${arch}_PREFIX}/include/c++/v1") # OHOS_LOCAL add_dependencies(RTfuzzer_interceptors.${arch} libcxx_fuzzer_${arch}-build) partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch}) partially_link_libcxx(fuzzer_interceptors ${LIBCXX_${arch}_PREFIX} ${arch}) diff --git a/llvm-build/build.py b/llvm-build/build.py index 33bdc09e8326..1ecf6ec561ff 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -900,10 +900,9 @@ class LlvmLibs(BuildUtils): self.build_runtimes(llvm_install, "libunwind;libcxxabi;libcxx", ldflags, cflags, llvm_triple, arch, multilib_suffix, defines) libcxx_ndk_install = self.merge_out_path('libcxx-ndk') - libcxx_ndk_install_tmp = self.merge_out_path('libcxx-ndk-tmp') self.check_create_dir(libcxx_ndk_install) - self.build_runtimes(libcxx_ndk_install_tmp, "libunwind;libcxxabi;libcxx", ldflags, cflags, llvm_triple, - arch, multilib_suffix, defines, libcxx_ndk_install) + self.build_runtimes(libcxx_ndk_install, "libunwind;libcxxabi;libcxx", ldflags, cflags, llvm_triple, + arch, multilib_suffix, defines, True) self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, first_time=False) @@ -930,13 +929,15 @@ class LlvmLibs(BuildUtils): arch, multilib_suffix, defines, - libcxx_ndk_install=None): + is_libcxx_ndk_install=False): self.logger().info('Building runtimes(%s) for %s', rt_list, arch) - ndk_suffix = '-ndk' if libcxx_ndk_install else '' + ndk_suffix = '-ndk' if is_libcxx_ndk_install else '' out_path = self.merge_out_path('lib', rt_list.replace(';', '-') + ndk_suffix + '-' + str(llvm_triple)) + libcxx_install_include_path = self.merge_out_path(llvm_install, 'include', 'libcxx-ohos', 'include', 'c++', 'v1') + rt_cflags = list(cflags) rt_cflags.append('-fstack-protector-strong') @@ -958,6 +959,8 @@ class LlvmLibs(BuildUtils): rt_defines['LIBCXX_USE_COMPILER_RT'] = 'ON' rt_defines['LIBCXX_ENABLE_ABI_LINKER_SCRIPT'] = 'OFF' rt_defines['LIBCXX_ENABLE_STATIC_ABI_LIBRARY'] = 'ON' + rt_defines['LIBCXX_INSTALL_INCLUDE_DIR'] = libcxx_install_include_path + rt_defines['LIBCXX_INSTALL_INCLUDE_TARGET_DIR'] = libcxx_install_include_path rt_defines['CMAKE_ASM_FLAGS'] = ' '.join(rt_cflags) rt_defines['CMAKE_C_FLAGS'] = ' '.join(rt_cflags) rt_defines['CMAKE_CXX_FLAGS'] = ' '.join(rt_cflags) @@ -967,12 +970,11 @@ class LlvmLibs(BuildUtils): rt_defines['CMAKE_CROSSCOMPILING'] = 'True' rt_defines['CMAKE_TRY_COMPILE_TARGET_TYPE'] = 'STATIC_LIBRARY' - if libcxx_ndk_install: + if is_libcxx_ndk_install: rt_defines['LIBCXX_ABI_NAMESPACE'] = '__n1' rt_defines['LIBCXX_OUTPUT_NAME'] = 'c++_shared' rt_defines['LIBCXX_OUTPUT_STATIC_NAME'] = 'c++_static' - rt_defines['LIBCXX_INSTALL_INCLUDE_DIR'] = self.merge_out_path(libcxx_ndk_install, 'include', 'libcxx-ohos', 'include', 'c++', 'v1') - rt_defines['LIBCXX_INSTALL_LIBRARY_DIR'] = self.merge_out_path(libcxx_ndk_install, 'lib', llvm_triple, 'c++', multilib_suffix) + rt_defines['LIBCXXABI_INSTALL_INCLUDE_DIR'] = libcxx_install_include_path rt_defines['LIBCXXABI_INSTALL_LIBRARY'] = 'OFF' rt_defines['LIBUNWIND_INSTALL_LIBRARY'] = 'OFF' else: @@ -1448,13 +1450,12 @@ class LlvmPackage(BuildUtils): def package_libcxx(self): libcxx_ndk_install=self.merge_out_path('libcxx-ndk') - libcxx_ndk_install_tmp=self.merge_out_path('libcxx-ndk-tmp') libcxx_ndk_install_include=self.merge_out_path(libcxx_ndk_install, 'include', 'libcxx-ohos', 'include', 'c++', 'v1') hosts_list=['linux-x86_64', 'darwin-x86_64', 'windows-x86_64', 'darwin-arm64'] if os.path.exists(libcxx_ndk_install): for headerfile in os.listdir(libcxx_ndk_install_include): - if not headerfile =='__config': + if headerfile not in ['__config', '__config_site']: if os.path.isdir(os.path.join(libcxx_ndk_install_include, headerfile)): shutil.rmtree(os.path.join(libcxx_ndk_install_include, headerfile)) else: @@ -1468,7 +1469,6 @@ class LlvmPackage(BuildUtils): args = ['tar', '-chjC', self.build_config.OUT_PATH, '-f', package_path, 'libcxx-ndk'] self.check_call(args) self.check_rm_tree(libcxx_ndk_install) - self.check_rm_tree(libcxx_ndk_install_tmp) @staticmethod def merge_tree(src_dir, dst_dir): -- Gitee