Austin Schuh | b02d233 | 2023-09-05 22:18:35 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # We need to build code linked against Halide. This means we need to use a |
| 3 | # compatible ABI. This means we need to use libstdc++, not libc++ like our main |
| 4 | # toolchains are set up for. |
| 5 | # |
| 6 | # Rebuilding Halide itself is only moderately annoying. However, it needs to |
| 7 | # link against LLVM, which is a much bigger pain to rebuild with libc++. |
| 8 | # |
| 9 | # To deal with this problem, this script runs clang hermetically on the |
| 10 | # appropriate sources. |
| 11 | # --- begin runfiles.bash initialization v2 --- |
| 12 | # Copy-pasted from the Bazel Bash runfiles library v2. |
| 13 | set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash |
| 14 | source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ |
| 15 | source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ |
| 16 | source "$0.runfiles/$f" 2>/dev/null || \ |
| 17 | source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 18 | source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 19 | { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e |
| 20 | # --- end runfiles.bash initialization v2 --- |
| 21 | BINARY="$1" |
| 22 | SOURCE="$2" |
| 23 | HALIDE="$(rlocation halide_k8)" |
| 24 | SYSROOT="$(rlocation amd64_debian_sysroot)" |
| 25 | ZLIB1G_DEV_AMD64_DEB="$(rlocation deb_zlib1g_dev_1_2_11_dfsg_2_amd64_deb_repo/file/zlib1g-dev_1.2.11.dfsg-2_amd64.deb)" |
| 26 | ZLIB1G_DEV="$(mktemp -d)" |
| 27 | LLVM_TOOLCHAIN="$(dirname "$(dirname "$(rlocation llvm_k8/bin/clang)")")" |
Austin Schuh | 94dbdf3 | 2024-04-11 22:51:09 -0700 | [diff] [blame^] | 28 | LLVM_LIBS="$(rlocation clang_amd64_deps)/usr/lib/x86_64-linux-gnu/" |
Austin Schuh | b02d233 | 2023-09-05 22:18:35 -0700 | [diff] [blame] | 29 | dpkg-deb -x "${ZLIB1G_DEV_AMD64_DEB}" "${ZLIB1G_DEV}" |
| 30 | TARGET=x86_64-unknown-linux-gnu |
| 31 | MULTIARCH=x86_64-linux-gnu |
Austin Schuh | 94dbdf3 | 2024-04-11 22:51:09 -0700 | [diff] [blame^] | 32 | export LD_LIBRARY_PATH="${SYSROOT}/usr/lib:${SYSROOT}/lib:${ZLIB1G_DEV}/usr/lib/${MULTIARCH}:${LLVM_LIBS}" |
Austin Schuh | b02d233 | 2023-09-05 22:18:35 -0700 | [diff] [blame] | 33 | "${LLVM_TOOLCHAIN}/bin/clang++" \ |
| 34 | -fcolor-diagnostics \ |
| 35 | -I"${HALIDE}/include" \ |
| 36 | -nostdinc \ |
Austin Schuh | 0bd410a | 2023-11-05 12:38:12 -0800 | [diff] [blame] | 37 | -isystem"${SYSROOT}/usr/include/c++/12" \ |
| 38 | -isystem"${SYSROOT}/usr/include/${MULTIARCH}/c++/12" \ |
Austin Schuh | b02d233 | 2023-09-05 22:18:35 -0700 | [diff] [blame] | 39 | -isystem"${SYSROOT}/usr/include/c++/7/backward" \ |
| 40 | -isystem"${LLVM_TOOLCHAIN}/lib/clang/17/include" \ |
| 41 | -isystem"${SYSROOT}/usr/include/${MULTIARCH}" \ |
| 42 | -isystem"${SYSROOT}/usr/include" \ |
| 43 | -isystem"${SYSROOT}/include" \ |
| 44 | "--sysroot=${SYSROOT}" \ |
| 45 | -resource-dir "${LLVM_TOOLCHAIN}/lib/clang/17" \ |
| 46 | -target "${TARGET}" \ |
| 47 | -fuse-ld=lld \ |
| 48 | -L"${LLVM_TOOLCHAIN}/lib" \ |
| 49 | -L"${SYSROOT}/usr/lib" \ |
| 50 | -L"${SYSROOT}/usr/lib/gcc/${MULTIARCH}/7" \ |
| 51 | -L"${ZLIB1G_DEV}/usr/lib/${MULTIARCH}" \ |
| 52 | "${HALIDE}/lib/libHalide.a" \ |
| 53 | -lstdc++ -lpthread -ldl -lm -lz \ |
| 54 | -std=gnu++20 \ |
| 55 | "${SOURCE}" \ |
| 56 | "${HALIDE}/share/Halide/tools/GenGen.cpp" \ |
| 57 | -ggdb3 \ |
| 58 | -o "${BINARY}" |