From cf8cf03ad5d3a0d79f31d3ad892187505df86503 Mon Sep 17 00:00:00 2001 From: zhengweiwei Date: Fri, 24 Mar 2023 14:48:51 +0800 Subject: [PATCH] Use python static lib by default Description: add build script for static python lib and enable static link python of lldb build by default Issue: I6EQVA Test: local compilation test Signed-off-by: zhengweiwei Change-Id: Id367589df7dd27e47432b7a59bc926c94c949c9f --- llvm-build/build.py | 22 ++++++++++++++++++++++ python_build.sh | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 python_build.sh diff --git a/llvm-build/build.py b/llvm-build/build.py index 33b914b484b5..692b05eb0b7c 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -275,6 +275,20 @@ class BuildUtils(object): self.check_create_dir(out_path) self.check_call([cmake_bin_path] + flags, cwd=out_path, env=env) + + def python_build(self): + cur_dir = os.getcwd() + while cur_dir != '/': + third_party_python = os.path.join(cur_dir, 'third_party', 'python') + if os.path.exists(third_party_python): + generated_path = os.path.join(third_party_python, 'build') + python_script_path = os.path.join(cur_dir, 'toolchain/llvm-project/python_build.sh') + cmakelists_path = os.path.join(cur_dir, 'toolchain/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt') + args = ['sh', python_script_path, third_party_python, generated_path, cmakelists_path] + self.check_call(args) + return True, generated_path + cur_dir = os.path.dirname(cur_dir) + return False, '' @staticmethod def logger(): @@ -376,6 +390,14 @@ class BuildUtils(object): defines['CMAKE_OSX_DEPLOYMENT_TARGET'] = mac_min_version defines['LLDB_INCLUDE_TESTS'] = 'OFF' defines['LIBCXX_INCLUDE_TESTS'] = 'OFF' + is_python_exist, python_path = self.python_build() + if is_python_exist: + defines['LLDB_PYTHON_EXE_RELATIVE_PATH'] = python_path + defines['LLDB_PYTHON_RELATIVE_PATH'] = python_path + else: + raise Exception( + "Unable to find third_party/python folder." + ) defines['COMPILER_RT_BUILD_XRAY'] = 'OFF' return defines diff --git a/python_build.sh b/python_build.sh new file mode 100644 index 000000000000..ccd810becd66 --- /dev/null +++ b/python_build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +CONFIGURE_PATH=$1 +EPREFIX=$2 +CMAKELISTS_PATH=$3 +if [ -f "${EPREFIX}/libpython3.10.a" ]; +then + : +else + mkdir -p ${EPREFIX} + cd $EPREFIX + sed -i '' "s/^[^#]*_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl*/#&/g" $CONFIGURE_PATH/Modules/Setup + + $CONFIGURE_PATH/configure --prefix=$EPREFIX \ + --bindir=$EPREFIX/bin \ + --libdir=$EPREFIX/lib \ + --includedir=$EPREFIX/include \ + --datarootdir=$EPREFIX/share + + make + + make install + + sed -i '' "s#\${Python3_LIBRARIES}#\"$EPREFIX/libpython3.10.a\"#" $CMAKELISTS_PATH +fi -- Gitee