From 7402da7f9c390234f01c448d7f31b205607079c8 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Wed, 9 Oct 2024 15:37:26 +0800 Subject: [PATCH] [R&D][Build] Python configuration modification in llvm toolchain Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/IAS2LL?from=project-issue Test: python3 toolchain/llvm-project/llvm-build/build.py --build-python python3 toolchain/llvm-project/llvm-build/build-ohos-aarch64.py --build-python Signed-off-by: xwx1135370 --- lldb/source/API/CMakeLists.txt | 5 +++++ lldb/tools/lldb-test/CMakeLists.txt | 5 +++++ llvm-build/build.py | 23 ++++++++++++----------- llvm-build/cross_toolchain_builder.py | 7 ++++--- llvm-build/python_builder.py | 6 ------ llvm/cmake/modules/AddLLVM.cmake | 2 +- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index 894ef6335ada..0f39894cb1fb 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -133,6 +133,11 @@ endif() if(Python3_RPATH) set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}") set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}") + # OHOS_LOCAL begin + if(OHOS) + set_property(TARGET liblldb APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath,\'${Python3_RPATH}\'") + endif() + # OHOS_LOCAL end endif() diff --git a/lldb/tools/lldb-test/CMakeLists.txt b/lldb/tools/lldb-test/CMakeLists.txt index 120e3aaa9d20..319349f29910 100644 --- a/lldb/tools/lldb-test/CMakeLists.txt +++ b/lldb/tools/lldb-test/CMakeLists.txt @@ -26,6 +26,11 @@ add_lldb_tool(lldb-test if(Python3_RPATH) set_property(TARGET lldb-test APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}") set_property(TARGET lldb-test APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}") + # OHOS_LOCAL begin + if(OHOS) + set_property(TARGET lldb-test APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath,\'${Python3_RPATH}\'") + endif() + # OHOS_LOCAL end endif() target_include_directories(lldb-test PRIVATE ${LLDB_SOURCE_DIR}/source) diff --git a/llvm-build/build.py b/llvm-build/build.py index 0f2231b8915c..48f2cc866912 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -628,9 +628,11 @@ class BuildUtils(object): defines['LIBCXX_INCLUDE_TESTS'] = 'OFF' defines['Python3_LIBRARIES'] = os.path.join(self.get_python_dir(), 'lib', 'libpython%s.dylib' % self.build_config.LLDB_PY_VERSION) + defines['Python3_RPATH'] = os.path.join('@loader_path', '..', 'python3', 'lib') else: defines['Python3_LIBRARIES'] = os.path.join(self.get_python_dir(), 'lib', 'libpython%s.so' % self.build_config.LLDB_PY_VERSION) + defines['Python3_RPATH'] = os.path.join('$ORIGIN', '..', 'python3', 'lib') defines['COMPILER_RT_BUILD_XRAY'] = 'OFF' defines['LIBUNWIND_USE_FRAME_HEADER_CACHE'] = 'ON' @@ -1097,10 +1099,10 @@ class LlvmCore(BuildUtils): raise Exception('Invalid Python information, please check if the Python tool is valid') windows_defines['LLDB_RELOCATABLE_PYTHON'] = 'OFF' windows_defines['LLDB_ENABLE_PYTHON'] = 'ON' - windows_defines['LLDB_PYTHON_HOME'] = 'python' + windows_defines['LLDB_PYTHON_HOME'] = os.path.join('..', self.build_config.LLDB_PYTHON) windows_defines['LLDB_PYTHON_RELATIVE_PATH'] = \ 'bin/python/lib/python%s' % (self.build_config.LLDB_PY_VERSION) - windows_defines['LLDB_PYTHON_EXE_RELATIVE_PATH'] = 'bin/python' + windows_defines['LLDB_PYTHON_EXE_RELATIVE_PATH'] = os.path.join('bin', self.build_config.LLDB_PYTHON) windows_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.pys' windows_defines['Python3_INCLUDE_DIRS'] = os.path.join(py_inc_dir, 'python%s' % self.build_config.LLDB_PY_VERSION) @@ -2390,13 +2392,8 @@ class LlvmPackage(BuildUtils): self.merge_tree(py_lib_path, os.path.join(bin_root, 'python', 'lib', py_version)) - def copy_python_to_host(self, install_dir): - if(self.host_is_linux()): - need_file = 'libpython' + self.build_config.LLDB_PY_VERSION + '.so.1.0' - if(self.host_is_darwin()): - need_file = 'libpython' + self.build_config.LLDB_PY_VERSION + '.dylib' - shutil.copyfile(os.path.join(self.get_python_dir(), "lib", need_file), os.path.join(install_dir, 'lib', need_file)) - self.check_copy_tree(self.get_python_dir(), os.path.join(install_dir, self.build_config.LLDB_PYTHON)) + def copy_python_to_host(self, python_dir, install_dir): + self.check_copy_tree(python_dir, os.path.join(install_dir, self.build_config.LLDB_PYTHON)) def windows_lib_files_operation(self, lib_files, lib_dir, install_dir): @@ -2973,8 +2970,9 @@ def main(): build_config.build_only_llvm, build_config.xunit_xml_output, build_config.build_xvm) - llvm_package.copy_python_to_host(llvm_make) - llvm_package.copy_python_to_host(llvm_install) + python_dir = llvm_core.get_python_dir() + llvm_package.copy_python_to_host(python_dir, llvm_make) + llvm_package.copy_python_to_host(python_dir, llvm_install) llvm_core.set_clang_version(llvm_path) @@ -3061,6 +3059,9 @@ def main(): windows_python_builder.build() windows_python_builder.prepare_for_package() llvm_core.set_mingw_python_dir(windows_python_builder.install_dir) + mingw_python_dir = llvm_core.get_mingw_python_dir() + llvm_package.copy_python_to_host(mingw_python_dir, build_utils.merge_out_path('windows-x86_64')) + llvm_package.copy_python_to_host(mingw_python_dir, windows64_install) if build_config.enable_lzma_7zip: build_utils.logger().info('build windows lzma') diff --git a/llvm-build/cross_toolchain_builder.py b/llvm-build/cross_toolchain_builder.py index bb1ae402910c..95524ca5cd2f 100644 --- a/llvm-build/cross_toolchain_builder.py +++ b/llvm-build/cross_toolchain_builder.py @@ -75,7 +75,6 @@ class CrossToolchainBuilder: ldflags.extend([ "--rtlib=compiler-rt", "-lunwind", - "-Wl,-rpath,'$ORIGIN/../lib'", ]) return ldflags @@ -185,7 +184,7 @@ class CrossToolchainBuilder: lldb_defines["LLDB_PYTHON_RELATIVE_PATH"] = "bin/python/lib/python%s" % ( self._build_config.LLDB_PY_VERSION ) - lldb_defines["LLDB_PYTHON_EXE_RELATIVE_PATH"] = "bin/python" + lldb_defines["LLDB_PYTHON_EXE_RELATIVE_PATH"] = "bin/python3" lldb_defines["LLDB_PYTHON_EXT_SUFFIX"] = ".so" lldb_defines["Python3_INCLUDE_DIRS"] = os.path.join( @@ -198,6 +197,7 @@ class CrossToolchainBuilder: "lib", "libpython%s.so" % self._build_config.LLDB_PY_VERSION, ) + lldb_defines['Python3_RPATH'] = os.path.join('$ORIGIN', '..', 'python3', 'lib') lldb_defines["LLDB_ENABLE_LZMA"] = "OFF" # Debug & Tuning @@ -232,7 +232,8 @@ class CrossToolchainBuilder: ) if self._build_config.build_python: - self._python_builder.copy_python_to_host(self._llvm_install) + self._llvm_package.copy_python_to_host(self._python_builder._install_dir, self._llvm_path) + self._llvm_package.copy_python_to_host(self._python_builder._install_dir, self._llvm_install) if self._install_python_from_prebuilts: libpython = f'libpython{self._build_config.LLDB_PY_VERSION}.so.1.0' diff --git a/llvm-build/python_builder.py b/llvm-build/python_builder.py index 92190baac7b8..1438f2db5b3a 100755 --- a/llvm-build/python_builder.py +++ b/llvm-build/python_builder.py @@ -348,12 +348,6 @@ class OHOSPythonBuilder(PythonBuilder): cmd = [str(self._source_dir / 'configure')] + config_flags subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) - def copy_python_to_host(self, install_dir): - libpython = f'libpython{self.build_utils.build_config.LLDB_PY_VERSION}.so.1.0' - - shutil.copyfile(os.path.join(self._install_dir, "lib", libpython), os.path.join(install_dir, 'lib', libpython)) - self.build_utils.check_copy_tree(self._install_dir, os.path.join(install_dir, self.build_utils.build_config.LLDB_PYTHON)) - def prepare_for_package(self) -> None: self._remove_exclude() if self.build_utils.build_config.strip: diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 9202c141af8b..4b500be484e8 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -2290,7 +2290,7 @@ function(llvm_setup_rpath name) LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ") endif() # OHOS_LOCAL begin - if(${CMAKE_SYSTEM_NAME} MATCHES "OHOS") + if(${CMAKE_SYSTEM_NAME} MATCHES "OHOS" OR OHOS) # Target property INSTALL_RPATH is not supported on OHOS. set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath,\'${_install_rpath}\' ") endif() -- Gitee