From c7931e05dbb624852ea109bae20347e615d14f41 Mon Sep 17 00:00:00 2001 From: Bryan Chan Date: Wed, 13 Aug 2025 04:17:36 +0800 Subject: [PATCH 1/2] [llvm-build] Allow llvm_prebuilts_for_ark_aot.sh to use current source tree Add an option to the script so that it will build libLLVM-15.so for the ArkTS AOT compiler using the currently checked-out source tree, instead of trying to clone third_party_llvm-project again. Also change the script to assume that the correct arkcompiler_runtime_core branch has already been checked out if $ARKCOMPILER_DIR already exists, instead of failing with a git clone error. Signed-off-by: Bryan Chan --- llvm-build/llvm_prebuilts_for_ark_aot.sh | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/llvm-build/llvm_prebuilts_for_ark_aot.sh b/llvm-build/llvm_prebuilts_for_ark_aot.sh index 6133d70c0d26..f793d917bea6 100644 --- a/llvm-build/llvm_prebuilts_for_ark_aot.sh +++ b/llvm-build/llvm_prebuilts_for_ark_aot.sh @@ -1,6 +1,13 @@ #!/usr/bin/env bash # NOTE: it is expected, that OHOS SDK is present on the build machine and git is installed +# Example: +# +# bash llvm-build/llvm_prebuilts_for_ark_aot.sh \ +# --build-dir=$PWD/../arkaotbuild \ +# --sdk-native=$HOME/prebuilts/ohos-sdk/linux/20/native \ +# --use-current-llvm-project + set -eu function usage() { @@ -11,6 +18,7 @@ cat << EOF --runtime-core-repo= --llvm-project-branch= --llvm-project-repo= + --use-current-llvm-project EOF } @@ -20,6 +28,7 @@ runtime_core_branch="OpenHarmony_feature_20241108" runtime_core_repo="https://gitee.com/openharmony/arkcompiler_runtime_core" llvm_project_branch="2024_1127_llvm_ark_aot" llvm_repo="https://gitee.com/openharmony/third_party_llvm-project" +skip_cloning=0 while (( ${#} > 0 )); do opt="${1}" @@ -37,6 +46,8 @@ while (( ${#} > 0 )); do llvm_project_branch="${opt#"--llvm-project-branch="}";; --llvm-project-repo=*) llvm_repo="${opt#"--llvm-project-repo="}";; + --use-current-llvm-project) + skip_cloning=1;; *) usage exit 1 @@ -52,15 +63,21 @@ fi # download arkcompiler sources # for prebuilts script and build_llvm.sh ARKCOMPILER_DIR="${build_dir}/arkcompiler_runtime_core" -git clone --depth 1 -b "${runtime_core_branch}" "${runtime_core_repo}" "${ARKCOMPILER_DIR}" +if [[ ! -e "${ARKCOMPILER_DIR}" ]]; then + git clone --depth 1 -b "${runtime_core_branch}" "${runtime_core_repo}" "${ARKCOMPILER_DIR}" +fi # Install prebuilts # requires root !!! bash ${ARKCOMPILER_DIR}/static_core/scripts/install-deps-ubuntu --install=dev --install=arm-all # download llvm sources -LLVM_DIR="${build_dir}/llvm-project" -git clone --depth 1 -b "${llvm_project_branch}" "${llvm_repo}" "${LLVM_DIR}" +if [[ $skip_cloning == 0 ]]; then + LLVM_DIR="${build_dir}/llvm-project" + git clone --depth 1 -b "${llvm_project_branch}" "${llvm_repo}" "${LLVM_DIR}" +else + LLVM_DIR="$(realpath $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/../ )" +fi ### Required variables export BUILD_DIR=${build_dir}/build @@ -91,8 +108,8 @@ export OHOS_PREBUILTS="${build_dir}" # paths used in build_llvm.sh ohos_prebuilts_bin="${OHOS_PREBUILTS}/clang/ohos/linux-x86_64/llvm" mkdir -p "${ohos_prebuilts_bin}" -ln -s "${OHOS_SDK}/llvm/bin" "${ohos_prebuilts_bin}/bin" -ln -s "${OHOS_SDK}/llvm/lib" "${ohos_prebuilts_bin}/lib" +ln -sf "${OHOS_SDK}/llvm/bin" "${ohos_prebuilts_bin}/" +ln -sf "${OHOS_SDK}/llvm/lib" "${ohos_prebuilts_bin}/" ### Build tools export CC="${OHOS_SDK}/llvm/bin/clang" -- Gitee From d015158fcf53ec6f7c447f66282db117b715ea25 Mon Sep 17 00:00:00 2001 From: Bryan Chan Date: Thu, 21 Aug 2025 19:33:15 +0800 Subject: [PATCH 2/2] [llvm-build] Allow llvm_prebuilts_for_ark_aot.sh to use another Clang When building libLLVM-15.so for the ArkTS AOT compiler for HarmonyOS, it is necesary to use the same version of Clang as the one used to build libllvmbackend.z.so, to ensure that the resulting binaries use the same C++ ABI (and therefore can be linked together correctly). This patch adds an option to the build script to specify the location of an alternative compiler. Signed-off-by: Bryan Chan --- llvm-build/llvm_prebuilts_for_ark_aot.sh | 34 ++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/llvm-build/llvm_prebuilts_for_ark_aot.sh b/llvm-build/llvm_prebuilts_for_ark_aot.sh index f793d917bea6..800809ca040d 100644 --- a/llvm-build/llvm_prebuilts_for_ark_aot.sh +++ b/llvm-build/llvm_prebuilts_for_ark_aot.sh @@ -6,18 +6,22 @@ # bash llvm-build/llvm_prebuilts_for_ark_aot.sh \ # --build-dir=$PWD/../arkaotbuild \ # --sdk-native=$HOME/prebuilts/ohos-sdk/linux/20/native \ +# --clang-toolchain=$HOME/prebuilts/clang/ohos/linux-x86_64/llvm \ # --use-current-llvm-project set -eu function usage() { cat << EOF - ${0} --build-dir= --sdk-native= [other] - other opts might be: + ${0} --build-dir= --sdk-native= + + Other options: + --runtime-core-branch= --runtime-core-repo= --llvm-project-branch= --llvm-project-repo= + --clang-toolchain= --use-current-llvm-project EOF } @@ -46,6 +50,8 @@ while (( ${#} > 0 )); do llvm_project_branch="${opt#"--llvm-project-branch="}";; --llvm-project-repo=*) llvm_repo="${opt#"--llvm-project-repo="}";; + --clang-toolchain=*) + clang_toolchain="${opt#"--clang-toolchain="}";; --use-current-llvm-project) skip_cloning=1;; *) @@ -108,13 +114,25 @@ export OHOS_PREBUILTS="${build_dir}" # paths used in build_llvm.sh ohos_prebuilts_bin="${OHOS_PREBUILTS}/clang/ohos/linux-x86_64/llvm" mkdir -p "${ohos_prebuilts_bin}" -ln -sf "${OHOS_SDK}/llvm/bin" "${ohos_prebuilts_bin}/" -ln -sf "${OHOS_SDK}/llvm/lib" "${ohos_prebuilts_bin}/" -### Build tools -export CC="${OHOS_SDK}/llvm/bin/clang" -export CXX="${OHOS_SDK}/llvm/bin/clang++" -export STRIP="${OHOS_SDK}/llvm/bin/llvm-strip" +# If an alternative Clang toolchain is provided, use it instead of the one +# shipped with the SDK. To ensure C++ ABI compatibility, the same toolchain +# must be used to build libLLVM and libllvmbackend. +if [[ -n "${clang_toolchain}" ]]; then + ln -sf "${clang_toolchain}/bin" "${ohos_prebuilts_bin}/" + ln -sf "${clang_toolchain}/lib" "${ohos_prebuilts_bin}/" + ### Build tools + export CC="${clang_toolchain}/bin/clang" + export CXX="${clang_toolchain}/bin/clang++" + export STRIP="${clang_toolchain}/bin/llvm-strip" +else + ln -sf "${OHOS_SDK}/llvm/bin" "${ohos_prebuilts_bin}/" + ln -sf "${OHOS_SDK}/llvm/lib" "${ohos_prebuilts_bin}/" + ### Build tools + export CC="${OHOS_SDK}/llvm/bin/clang" + export CXX="${OHOS_SDK}/llvm/bin/clang++" + export STRIP="${OHOS_SDK}/llvm/bin/llvm-strip" +fi export OPTIMIZE_DEBUG=false bash -x "${ARKCOMPILER_DIR}/static_core/scripts/llvm/build_llvm.sh" -- Gitee