From a28dd4e512abc6af4d4d4d07d1039a8dbc72e533 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:05:24 +0800 Subject: [PATCH 01/11] ci: clean more space --- .github/workflows/build.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 872a7b4..ba1f5fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,12 +15,15 @@ jobs: - name: Checkout Repo uses: actions/checkout@main - name: Free additional disk space - run: | - echo "Free additional disk space on host" - sudo apt purge -yq $(dpkg -l | grep '^ii' | awk '{ print $2 }' | grep -P '(cabal-|dotnet-|ghc-|libmono|php|aspnetcore)') \ - mono-runtime-common monodoc-manual ruby - sudo apt autoremove -yq - sudo rm -rf /opt/hostedtoolcache /usr/local /usr/share/dotnet /usr/share/swift + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + android: false + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true - name: Build Toolchain run: bash build.sh - name: Waiting for debugger From 30164ab163f83301bcd7be93517407877ffbe82c Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:05:42 +0800 Subject: [PATCH 02/11] Bump to r27 --- .github/workflows/build.yml | 2 +- D142965.patch | 29 ----------- additional-patch.json | 30 ------------ build-flang.sh | 37 +++++++------- Build-flang.patch => build-mlir.patch | 0 build.sh | 24 +++++----- ...fest_10552028.xml => manifest_12027248.xml | 48 +++++++++---------- 7 files changed, 58 insertions(+), 112 deletions(-) delete mode 100644 D142965.patch delete mode 100644 additional-patch.json rename Build-flang.patch => build-mlir.patch (100%) rename manifest_10552028.xml => manifest_12027248.xml (58%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba1f5fa..1f267c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: - name: Install dependicies run: | sudo apt update - sudo apt install -yq cmake ninja-build + sudo apt install -yq cmake ninja-build libzstd-dev - name: Fetch archives uses: actions/download-artifact@v2 with: diff --git a/D142965.patch b/D142965.patch deleted file mode 100644 index ba858d9..0000000 --- a/D142965.patch +++ /dev/null @@ -1,29 +0,0 @@ -From f95bdff17b3ed73f7f50479aaab3dfedfe73c9d1 Mon Sep 17 00:00:00 2001 -From: Shao-Ce SUN -Date: Wed, 1 Feb 2023 00:24:43 +0800 -Subject: [PATCH] [flang] Suppress a warning in D118631 [-Wunused-result] - -Reviewed By: klausler - -Differential Revision: https://reviews.llvm.org/D142965 ---- - flang/lib/Semantics/mod-file.cpp | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp -index 5a4aeef806f0445..22633054f0ca7f4 100644 ---- a/flang/lib/Semantics/mod-file.cpp -+++ b/flang/lib/Semantics/mod-file.cpp -@@ -963,8 +963,10 @@ Scope *ModFileReader::Read(const SourceName &name, - // directory lists, the intrinsic module directory takes precedence. - options.searchDirectories = context_.searchDirectories(); - for (const auto &dir : context_.intrinsicModuleDirectories()) { -- std::remove(options.searchDirectories.begin(), -- options.searchDirectories.end(), dir); -+ options.searchDirectories.erase( -+ std::remove(options.searchDirectories.begin(), -+ options.searchDirectories.end(), dir), -+ options.searchDirectories.end()); - } - options.searchDirectories.insert(options.searchDirectories.begin(), "."s); - } diff --git a/additional-patch.json b/additional-patch.json deleted file mode 100644 index b090235..0000000 --- a/additional-patch.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "metadata": { - "info": [], - "title": "Undef Macros" - }, - "platforms": [ - "android" - ], - "rel_patch_path": "flang-undef-macros.patch", - "version_range": { - "from": 370808, - "until": null - } - }, - { - "metadata": { - "info": [], - "title": "Upstream D142965" - }, - "platforms": [ - "android" - ], - "rel_patch_path": "D142965.patch", - "version_range": { - "from": 413129, - "until": null - } - } -] \ No newline at end of file diff --git a/build-flang.sh b/build-flang.sh index c5c092b..23c7e66 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -7,8 +7,12 @@ set -e -o pipefail -u : ${ANDROID_NDK:=~/lib/android-ndk-r26b} : ${FLANG_MAKE_PROCESSES:=1} +patch -p1 -d $(pwd)/out/llvm-project < flang-undef-macros.patch + +ANDROID_TRIPLE="$BUILD_ARCH_OR_TYPE-linux-android" CC_HOST_PLATFORM=$BUILD_ARCH_OR_TYPE-linux-android$DEFAULT_ANDROID_API_LEVEL if [ $BUILD_ARCH_OR_TYPE = arm ]; then + ANDROID_TRIPLE="armv7a-linux-androideabi" CC_HOST_PLATFORM=armv7a-linux-androideabi$DEFAULT_ANDROID_API_LEVEL elif [ $BUILD_ARCH_OR_TYPE = host ]; then CC_HOST_PLATFORM=x86_64-linux-gnu @@ -46,14 +50,15 @@ _EXTRA_CONFIGURE_ARGS=" -DLLVM_HOST_TRIPLE=${CC_HOST_PLATFORM/-/-unknown-} " -_CONFIGURE_ARGS="\ --DCMAKE_C_COMPILER=$(pwd)/out/stage2-install/bin/clang --DCMAKE_CXX_COMPILER=$(pwd)/out/stage2-install/bin/clang++ --DCMAKE_LINKER=$(pwd)/out/stage2-install/bin/ld.lld --DCMAKE_CXX_FLAGS=-stdlib=libc++ --DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ --DCMAKE_INSTALL_RPATH=\\\${ORIGIN}/../lib/x86_64-unknown-linux-gnu:\\\${ORIGIN}/../lib -" +_HOST_RPATH='$ORIGIN:$ORIGIN/../lib/x86_64-unknown-linux-gnu:$ORIGIN/../lib' + +_CONFIGURE_ARGS=() +_CONFIGURE_ARGS+=("-DCMAKE_C_COMPILER=$(pwd)/out/stage2-install/bin/clang") +_CONFIGURE_ARGS+=("-DCMAKE_CXX_COMPILER=$(pwd)/out/stage2-install/bin/clang++") +_CONFIGURE_ARGS+=("-DCMAKE_LINKER=$(pwd)/out/stage2-install/bin/ld.lld") +_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") +_CONFIGURE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") +_CONFIGURE_ARGS+=("-DCMAKE_INSTALL_RPATH=$_HOST_RPATH") _BUILD_TARGET="" if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then @@ -61,21 +66,21 @@ if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then export NDK_STANDALONE_TOOLCHAIN_DIR="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64" CMAKE_PROC=$BUILD_ARCH_OR_TYPE test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' - _CONFIGURE_ARGS="-DCMAKE_SYSTEM_NAME=Android" - _CONFIGURE_ARGS+=" -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC" - _CONFIGURE_ARGS+=" -DCMAKE_SYSTEM_VERSION=$DEFAULT_ANDROID_API_LEVEL" - _CONFIGURE_ARGS+=" -DCMAKE_ANDROID_NDK=$ANDROID_NDK" - _CONFIGURE_ARGS+=" -DCMAKE_SKIP_INSTALL_RPATH=ON" + _CONFIGURE_ARGS=("-DCMAKE_SYSTEM_NAME=Android") + _CONFIGURE_ARGS+=("-DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC") + _CONFIGURE_ARGS+=("-DCMAKE_SYSTEM_VERSION=$DEFAULT_ANDROID_API_LEVEL") + _CONFIGURE_ARGS+=("-DCMAKE_ANDROID_NDK=$ANDROID_NDK") + _CONFIGURE_ARGS+=("-DCMAKE_SKIP_INSTALL_RPATH=ON") + echo "" > $NDK_STANDALONE_TOOLCHAIN_DIR/sysroot/usr/include/zstd.h + echo "!" > $NDK_STANDALONE_TOOLCHAIN_DIR/sysroot/usr/lib/$ANDROID_TRIPLE/libzstd.a _BUILD_TARGET="Fortran_main FortranRuntime FortranDecimal" -else - export LD_LIBRARY_PATH="$(pwd)/out/stage2-install/lib:${LD_LIBRARY_PATH:-}" fi mkdir -p build-$BUILD_ARCH_OR_TYPE-install mkdir -p build-$BUILD_ARCH_OR_TYPE pushd build-$BUILD_ARCH_OR_TYPE -cmake -G Ninja $_CONFIGURE_ARGS \ +cmake -G Ninja "${_CONFIGURE_ARGS[@]}" \ -DCMAKE_INSTALL_PREFIX=$(pwd)/../build-$BUILD_ARCH_OR_TYPE-install \ -DDOXYGEN_EXECUTABLE= \ -DBUILD_TESTING=OFF \ diff --git a/Build-flang.patch b/build-mlir.patch similarity index 100% rename from Build-flang.patch rename to build-mlir.patch diff --git a/build.sh b/build.sh index ab14c50..2ecf5d2 100644 --- a/build.sh +++ b/build.sh @@ -2,6 +2,7 @@ set -e -o pipefail -u +# Fetch source mkdir -p ~/bin export PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo @@ -11,24 +12,23 @@ git config --global user.email "you@example.com" git config --global color.ui false mkdir -p llvm-toolchain && cd llvm-toolchain repo init -u https://android.googlesource.com/platform/manifest -# Modified the manifest xml, to ensure not contain darwin prebuilt -# XXX: Windows prebuilt? -sed -E 's/(^.*?(darwin).*$)//g' ../manifest_10552028.xml > .repo/manifests/test.xml +# Modified the manifest xml, to ensure only contain linux component +sed -E 's/(^.*?(darwin|mingw|windows).*$)//g' ../manifest_12027248.xml > .repo/manifests/test.xml repo init -m test.xml repo sync -c -# Add patch for flang -jq --argjson a "$(cat toolchain/llvm_android/patches/PATCHES.json)" \ - --argjson b "$(cat ../additional-patch.json)" -n '$a + $b' \ - > toolchain/llvm_android/patches/PATCHES.json -cp ../flang-undef-macros.patch toolchain/llvm_android/patches/ -cp ../D142965.patch toolchain/llvm_android/patches/ +# Remove duplicated repo cache +# rm -rf .repo -patch -p1 < ../Build-flang.patch +# Remove older version prebuilts +rm -rf $(find prebuilts/clang/host/linux-x86/clang* -maxdepth 0 | grep -v "clang-r522817" | grep -v "clang-stable") -# Build again +# Patch to build mlir +patch -p1 < ../build-mlir.patch + +# Build pushd toolchain/llvm_android -python build.py --no-build lldb,windows --no-musl --single-stage --skip-tests +python build.py --no-build lldb,windows --no-musl --bootstrap-use-prebuilt --skip-tests --skip-runtimes popd tar -cjf package-install.tar.bz2 out/install diff --git a/manifest_10552028.xml b/manifest_12027248.xml similarity index 58% rename from manifest_10552028.xml rename to manifest_12027248.xml index 0114ce2..e7b1149 100644 --- a/manifest_10552028.xml +++ b/manifest_12027248.xml @@ -5,67 +5,67 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + From 7cfbfe9775e7c0672919ae488ef41da7a0739207 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:49:39 +0800 Subject: [PATCH 03/11] add back LD_LIBRARY_PATH --- build-flang.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-flang.sh b/build-flang.sh index 23c7e66..dcad1dc 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -74,6 +74,8 @@ if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then echo "" > $NDK_STANDALONE_TOOLCHAIN_DIR/sysroot/usr/include/zstd.h echo "!" > $NDK_STANDALONE_TOOLCHAIN_DIR/sysroot/usr/lib/$ANDROID_TRIPLE/libzstd.a _BUILD_TARGET="Fortran_main FortranRuntime FortranDecimal" +else + export LD_LIBRARY_PATH="$(pwd)/out/stage2-install/lib:${LD_LIBRARY_PATH:-}" fi mkdir -p build-$BUILD_ARCH_OR_TYPE-install From e1094fde0b3368fb53e99d097ff4b398b4efc552 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:40:24 +0800 Subject: [PATCH 04/11] test --- build-flang.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build-flang.sh b/build-flang.sh index dcad1dc..151245a 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -4,7 +4,7 @@ set -e -o pipefail -u : ${BUILD_ARCH_OR_TYPE:=host} : ${DEFAULT_ANDROID_API_LEVEL:=21} -: ${ANDROID_NDK:=~/lib/android-ndk-r26b} +: ${ANDROID_NDK:=~/lib/android-ndk-r27} : ${FLANG_MAKE_PROCESSES:=1} patch -p1 -d $(pwd)/out/llvm-project < flang-undef-macros.patch @@ -66,8 +66,9 @@ if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then export NDK_STANDALONE_TOOLCHAIN_DIR="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64" CMAKE_PROC=$BUILD_ARCH_OR_TYPE test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' + test $CMAKE_PROC == "aarch64" && CMAKE_PROC='arm64-v8a' _CONFIGURE_ARGS=("-DCMAKE_SYSTEM_NAME=Android") - _CONFIGURE_ARGS+=("-DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC") + _CONFIGURE_ARGS+=("-CMAKE_ANDROID_ARCH_ABI=$CMAKE_PROC") _CONFIGURE_ARGS+=("-DCMAKE_SYSTEM_VERSION=$DEFAULT_ANDROID_API_LEVEL") _CONFIGURE_ARGS+=("-DCMAKE_ANDROID_NDK=$ANDROID_NDK") _CONFIGURE_ARGS+=("-DCMAKE_SKIP_INSTALL_RPATH=ON") From 6fa1fc13839d6da2e839bd39a97069d85c1f973f Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:32:49 +0800 Subject: [PATCH 05/11] Update build-flang.sh --- build-flang.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-flang.sh b/build-flang.sh index 151245a..25e89da 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -56,7 +56,7 @@ _CONFIGURE_ARGS=() _CONFIGURE_ARGS+=("-DCMAKE_C_COMPILER=$(pwd)/out/stage2-install/bin/clang") _CONFIGURE_ARGS+=("-DCMAKE_CXX_COMPILER=$(pwd)/out/stage2-install/bin/clang++") _CONFIGURE_ARGS+=("-DCMAKE_LINKER=$(pwd)/out/stage2-install/bin/ld.lld") -_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") +_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH -Wno-deprecated-copy") _CONFIGURE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") _CONFIGURE_ARGS+=("-DCMAKE_INSTALL_RPATH=$_HOST_RPATH") From 76068c249276ee713253e20a6e50ea4ca43e7001 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:33:12 +0800 Subject: [PATCH 06/11] Update build-flang.sh --- build-flang.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-flang.sh b/build-flang.sh index 25e89da..34fd898 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -68,7 +68,7 @@ if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' test $CMAKE_PROC == "aarch64" && CMAKE_PROC='arm64-v8a' _CONFIGURE_ARGS=("-DCMAKE_SYSTEM_NAME=Android") - _CONFIGURE_ARGS+=("-CMAKE_ANDROID_ARCH_ABI=$CMAKE_PROC") + _CONFIGURE_ARGS+=("-DCMAKE_ANDROID_ARCH_ABI=$CMAKE_PROC") _CONFIGURE_ARGS+=("-DCMAKE_SYSTEM_VERSION=$DEFAULT_ANDROID_API_LEVEL") _CONFIGURE_ARGS+=("-DCMAKE_ANDROID_NDK=$ANDROID_NDK") _CONFIGURE_ARGS+=("-DCMAKE_SKIP_INSTALL_RPATH=ON") From ca5753f74442ac48fc7abb65ea303a1ceed9be51 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:32:00 +0800 Subject: [PATCH 07/11] Update build-flang.sh --- build-flang.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-flang.sh b/build-flang.sh index 34fd898..d25c980 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -37,7 +37,7 @@ _EXTRA_CONFIGURE_ARGS=" -DLLVM_ENABLE_FFI=ON -DFLANG_DEFAULT_LINKER=lld -DMLIR_INSTALL_AGGREGATE_OBJECTS=OFF --DFLANG_ENABLE_WERROR=On +-DFLANG_ENABLE_WERROR=OFF -DFLANG_INCLUDE_TESTS=OFF -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_LIT_ARGS=-v @@ -56,7 +56,7 @@ _CONFIGURE_ARGS=() _CONFIGURE_ARGS+=("-DCMAKE_C_COMPILER=$(pwd)/out/stage2-install/bin/clang") _CONFIGURE_ARGS+=("-DCMAKE_CXX_COMPILER=$(pwd)/out/stage2-install/bin/clang++") _CONFIGURE_ARGS+=("-DCMAKE_LINKER=$(pwd)/out/stage2-install/bin/ld.lld") -_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH -Wno-deprecated-copy") +_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") _CONFIGURE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") _CONFIGURE_ARGS+=("-DCMAKE_INSTALL_RPATH=$_HOST_RPATH") From e95e2804db6d621b93c34071339ccd01580ec99b Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:05:35 +0800 Subject: [PATCH 08/11] test --- .gitignore | 1 + build-flang.sh | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 1af678a..0357f37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Build files llvm-toolchain* +output/ diff --git a/build-flang.sh b/build-flang.sh index d25c980..9fdc96b 100644 --- a/build-flang.sh +++ b/build-flang.sh @@ -50,15 +50,13 @@ _EXTRA_CONFIGURE_ARGS=" -DLLVM_HOST_TRIPLE=${CC_HOST_PLATFORM/-/-unknown-} " -_HOST_RPATH='$ORIGIN:$ORIGIN/../lib/x86_64-unknown-linux-gnu:$ORIGIN/../lib' - _CONFIGURE_ARGS=() _CONFIGURE_ARGS+=("-DCMAKE_C_COMPILER=$(pwd)/out/stage2-install/bin/clang") _CONFIGURE_ARGS+=("-DCMAKE_CXX_COMPILER=$(pwd)/out/stage2-install/bin/clang++") _CONFIGURE_ARGS+=("-DCMAKE_LINKER=$(pwd)/out/stage2-install/bin/ld.lld") -_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") -_CONFIGURE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -Wl,-rpath=$_HOST_RPATH") -_CONFIGURE_ARGS+=("-DCMAKE_INSTALL_RPATH=$_HOST_RPATH") +_CONFIGURE_ARGS+=("-DCMAKE_CXX_FLAGS=-stdlib=libc++ -Wno-deprecated-copy") +_CONFIGURE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++") +_CONFIGURE_ARGS+=("-DCMAKE_INSTALL_RPATH=\$ORIGIN:\$ORIGIN/../lib/x86_64-unknown-linux-gnu:\$ORIGIN/../lib") _BUILD_TARGET="" if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then @@ -76,7 +74,7 @@ if [ "$BUILD_ARCH_OR_TYPE" != "host" ]; then echo "!" > $NDK_STANDALONE_TOOLCHAIN_DIR/sysroot/usr/lib/$ANDROID_TRIPLE/libzstd.a _BUILD_TARGET="Fortran_main FortranRuntime FortranDecimal" else - export LD_LIBRARY_PATH="$(pwd)/out/stage2-install/lib:${LD_LIBRARY_PATH:-}" + export LD_LIBRARY_PATH="$(pwd)/out/stage2-install/lib:$(pwd)/out/stage2-install/lib/x86_64-unknown-linux-gnu:${LD_LIBRARY_PATH:-}" fi mkdir -p build-$BUILD_ARCH_OR_TYPE-install From 06ae9bd7006da4b567f5a7a4e8b660378a5cbb27 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:28:50 +0800 Subject: [PATCH 09/11] test --- build.sh | 3 +- ship-libclang.patch | 125 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 ship-libclang.patch diff --git a/build.sh b/build.sh index 2ecf5d2..d3b0e79 100644 --- a/build.sh +++ b/build.sh @@ -25,10 +25,11 @@ rm -rf $(find prebuilts/clang/host/linux-x86/clang* -maxdepth 0 | grep -v "clang # Patch to build mlir patch -p1 < ../build-mlir.patch +patch -p1 < ../ship-libclang.patch # Build pushd toolchain/llvm_android -python build.py --no-build lldb,windows --no-musl --bootstrap-use-prebuilt --skip-tests --skip-runtimes +python build.py --no-build lldb,windows --no-musl --bootstrap-use-prebuilt --skip-tests --skip-runtimes --dev-package popd tar -cjf package-install.tar.bz2 out/install diff --git a/ship-libclang.patch b/ship-libclang.patch new file mode 100644 index 0000000..86f6a42 --- /dev/null +++ b/ship-libclang.patch @@ -0,0 +1,125 @@ +From 041739666e25237193307daa8c1083f45bbd6cd6 Mon Sep 17 00:00:00 2001 +From: Chris Wailes +Date: Tue, 06 Aug 2024 13:06:15 -0700 +Subject: [PATCH] Update script for building a prebuilt compatible with the Rust toolchain + +This CL modifies do_build.py script to: +1. Copy the FileCheck utility into the final package +2. Copy the libzstd.a library into the final package +3. Add a flag to skip pruning of "unnecessary" binaries + +Test: ./build.py --no-prune-binaries +Test: cd ~/projects/android/main-plus-rust/toolchain/android_rust +Test: ./tools/build.py --llvm-linkage static --unified-prebuilt ../../../llvm-toolchain/out/install/linux-x86/clang-dev +Change-Id: I524b9034a77f09b697dd381a6b85f7dd4805e9a4 +--- + +diff --git a/do_build.py b/do_build.py +index bb9a63a..0ab77b8 100755 +--- a/toolchain/llvm_android/do_build.py ++++ b/toolchain/llvm_android/do_build.py +@@ -374,7 +374,7 @@ + + def package_toolchain(toolchain_builder: LLVMBuilder, + necessary_bin_files: Optional[Set[str]]=None, +- strip=True, with_runtimes=True, create_tar=True, llvm_next=False): ++ strip=True, with_runtimes=True, create_tar=True, llvm_next=False, dev_package=False): + build_dir = toolchain_builder.install_dir + host_config = toolchain_builder.config_list[0] + host = host_config.target_os +@@ -493,7 +493,8 @@ + for binary in bin_dir.iterdir(): + if binary.is_file(): + if binary.name not in necessary_bin_files: +- binary.unlink() ++ if not dev_package: ++ binary.unlink() + elif binary.is_symlink(): + continue + elif strip and binary.name not in script_bins: +@@ -511,6 +512,11 @@ + if not (bin_dir / necessary_bin_file).is_file(): + raise RuntimeError(f'Did not find {necessary_bin_file} in {bin_dir}') + ++ if host.is_linux and dev_package: ++ # Copy FileCheck into the install directory. This is needed to build the ++ # Rust toolchain. ++ shutil.copy2(toolchain_builder.output_dir / 'bin' / 'FileCheck', bin_dir) ++ + necessary_lib_files = set() + if with_runtimes: + if not (host.is_windows and win_sdk.is_enabled()): +@@ -548,7 +554,8 @@ + is_darwin_lib=True) + + # Remove unnecessary static libraries. +- remove_static_libraries(lib_dir, necessary_lib_files) ++ if not dev_package: ++ remove_static_libraries(lib_dir, necessary_lib_files) + + if host.is_linux: + install_wrappers(install_dir, llvm_next) +@@ -585,6 +592,12 @@ + else: + verify_file_exists(lib_dir, necessary_lib_file) + ++ # Copy in the libzstd.a library. This is needed to compile the Rust ++ # toolchain. ++ if dev_package and toolchain_builder.libzstd is not None: ++ for lib in toolchain_builder.libzstd.link_libraries: ++ shutil.copy2(lib, lib_dir) ++ + # Next, we copy over stdatomic.h and bits/stdatomic.h from bionic. + libc_include_path = paths.ANDROID_DIR / 'bionic' / 'libc' / 'include' + header_path = lib_dir / 'clang' / version.major_version() / 'include' +@@ -872,8 +885,7 @@ + bootstrap_group.add_argument( + '--bootstrap-use', + default='', +- help='Use the given bootstrap compiler.' +- ) ++ help='Use the given bootstrap compiler.') + bootstrap_group.add_argument( + '--bootstrap-use-prebuilt', + action='store_true', +@@ -919,13 +931,16 @@ + "--git_am", + action="store_true", + default=False, +- help="If set, use 'git am' to patch instead of GNU 'patch'. ", +- ) ++ help="If set, use 'git am' to patch instead of GNU 'patch'. ",) + + parser.add_argument( + '--windows-sdk', +- help='Path to a Windows SDK. If set, it will be used instead of MinGW.' +- ) ++ help='Path to a Windows SDK. If set, it will be used instead of MinGW.') ++ ++ parser.add_argument( ++ "--dev-package", ++ action="store_true", ++ help="Skip pruning non-allowlisted binaries and install additional files in the final prebuilt archive") + + musl_group = parser.add_mutually_exclusive_group() + musl_group.add_argument( +@@ -1184,7 +1199,8 @@ + strip=do_strip_host_package, + with_runtimes=do_runtimes, + create_tar=args.create_tar, +- llvm_next=args.build_llvm_next) ++ llvm_next=args.build_llvm_next, ++ dev_package=args.dev_package) + + if do_package and need_windows: + package_toolchain( +@@ -1192,7 +1208,8 @@ + necessary_bin_files=win_lldb_bins, + strip=do_strip, + with_runtimes=do_runtimes, +- create_tar=args.create_tar) ++ create_tar=args.create_tar, ++ dev_package=args.dev_package) + + if build_errors: + logger().info(toolchain_errors.combine_toolchain_errors(build_errors)) From cc926b34e0e514f6ca0b68531819ea487762ec73 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 14 Aug 2024 23:25:41 +0800 Subject: [PATCH 10/11] test --- build.sh | 1 - ship-libclang.patch | 125 -------------------------------------------- 2 files changed, 126 deletions(-) delete mode 100644 ship-libclang.patch diff --git a/build.sh b/build.sh index d3b0e79..cbc2832 100644 --- a/build.sh +++ b/build.sh @@ -25,7 +25,6 @@ rm -rf $(find prebuilts/clang/host/linux-x86/clang* -maxdepth 0 | grep -v "clang # Patch to build mlir patch -p1 < ../build-mlir.patch -patch -p1 < ../ship-libclang.patch # Build pushd toolchain/llvm_android diff --git a/ship-libclang.patch b/ship-libclang.patch deleted file mode 100644 index 86f6a42..0000000 --- a/ship-libclang.patch +++ /dev/null @@ -1,125 +0,0 @@ -From 041739666e25237193307daa8c1083f45bbd6cd6 Mon Sep 17 00:00:00 2001 -From: Chris Wailes -Date: Tue, 06 Aug 2024 13:06:15 -0700 -Subject: [PATCH] Update script for building a prebuilt compatible with the Rust toolchain - -This CL modifies do_build.py script to: -1. Copy the FileCheck utility into the final package -2. Copy the libzstd.a library into the final package -3. Add a flag to skip pruning of "unnecessary" binaries - -Test: ./build.py --no-prune-binaries -Test: cd ~/projects/android/main-plus-rust/toolchain/android_rust -Test: ./tools/build.py --llvm-linkage static --unified-prebuilt ../../../llvm-toolchain/out/install/linux-x86/clang-dev -Change-Id: I524b9034a77f09b697dd381a6b85f7dd4805e9a4 ---- - -diff --git a/do_build.py b/do_build.py -index bb9a63a..0ab77b8 100755 ---- a/toolchain/llvm_android/do_build.py -+++ b/toolchain/llvm_android/do_build.py -@@ -374,7 +374,7 @@ - - def package_toolchain(toolchain_builder: LLVMBuilder, - necessary_bin_files: Optional[Set[str]]=None, -- strip=True, with_runtimes=True, create_tar=True, llvm_next=False): -+ strip=True, with_runtimes=True, create_tar=True, llvm_next=False, dev_package=False): - build_dir = toolchain_builder.install_dir - host_config = toolchain_builder.config_list[0] - host = host_config.target_os -@@ -493,7 +493,8 @@ - for binary in bin_dir.iterdir(): - if binary.is_file(): - if binary.name not in necessary_bin_files: -- binary.unlink() -+ if not dev_package: -+ binary.unlink() - elif binary.is_symlink(): - continue - elif strip and binary.name not in script_bins: -@@ -511,6 +512,11 @@ - if not (bin_dir / necessary_bin_file).is_file(): - raise RuntimeError(f'Did not find {necessary_bin_file} in {bin_dir}') - -+ if host.is_linux and dev_package: -+ # Copy FileCheck into the install directory. This is needed to build the -+ # Rust toolchain. -+ shutil.copy2(toolchain_builder.output_dir / 'bin' / 'FileCheck', bin_dir) -+ - necessary_lib_files = set() - if with_runtimes: - if not (host.is_windows and win_sdk.is_enabled()): -@@ -548,7 +554,8 @@ - is_darwin_lib=True) - - # Remove unnecessary static libraries. -- remove_static_libraries(lib_dir, necessary_lib_files) -+ if not dev_package: -+ remove_static_libraries(lib_dir, necessary_lib_files) - - if host.is_linux: - install_wrappers(install_dir, llvm_next) -@@ -585,6 +592,12 @@ - else: - verify_file_exists(lib_dir, necessary_lib_file) - -+ # Copy in the libzstd.a library. This is needed to compile the Rust -+ # toolchain. -+ if dev_package and toolchain_builder.libzstd is not None: -+ for lib in toolchain_builder.libzstd.link_libraries: -+ shutil.copy2(lib, lib_dir) -+ - # Next, we copy over stdatomic.h and bits/stdatomic.h from bionic. - libc_include_path = paths.ANDROID_DIR / 'bionic' / 'libc' / 'include' - header_path = lib_dir / 'clang' / version.major_version() / 'include' -@@ -872,8 +885,7 @@ - bootstrap_group.add_argument( - '--bootstrap-use', - default='', -- help='Use the given bootstrap compiler.' -- ) -+ help='Use the given bootstrap compiler.') - bootstrap_group.add_argument( - '--bootstrap-use-prebuilt', - action='store_true', -@@ -919,13 +931,16 @@ - "--git_am", - action="store_true", - default=False, -- help="If set, use 'git am' to patch instead of GNU 'patch'. ", -- ) -+ help="If set, use 'git am' to patch instead of GNU 'patch'. ",) - - parser.add_argument( - '--windows-sdk', -- help='Path to a Windows SDK. If set, it will be used instead of MinGW.' -- ) -+ help='Path to a Windows SDK. If set, it will be used instead of MinGW.') -+ -+ parser.add_argument( -+ "--dev-package", -+ action="store_true", -+ help="Skip pruning non-allowlisted binaries and install additional files in the final prebuilt archive") - - musl_group = parser.add_mutually_exclusive_group() - musl_group.add_argument( -@@ -1184,7 +1199,8 @@ - strip=do_strip_host_package, - with_runtimes=do_runtimes, - create_tar=args.create_tar, -- llvm_next=args.build_llvm_next) -+ llvm_next=args.build_llvm_next, -+ dev_package=args.dev_package) - - if do_package and need_windows: - package_toolchain( -@@ -1192,7 +1208,8 @@ - necessary_bin_files=win_lldb_bins, - strip=do_strip, - with_runtimes=do_runtimes, -- create_tar=args.create_tar) -+ create_tar=args.create_tar, -+ dev_package=args.dev_package) - - if build_errors: - logger().info(toolchain_errors.combine_toolchain_errors(build_errors)) From 701b4b03a4402b8be4f6899c3d93502b4676aff0 Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:21:17 +0800 Subject: [PATCH 11/11] Update build.sh --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index cbc2832..2ecf5d2 100644 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ patch -p1 < ../build-mlir.patch # Build pushd toolchain/llvm_android -python build.py --no-build lldb,windows --no-musl --bootstrap-use-prebuilt --skip-tests --skip-runtimes --dev-package +python build.py --no-build lldb,windows --no-musl --bootstrap-use-prebuilt --skip-tests --skip-runtimes popd tar -cjf package-install.tar.bz2 out/install