blob: d6e5d419e0e39bce72cf9edab1723ae47dc7029a [file] [log] [blame]
Austin Schuhb02d2332023-09-05 22:18:35 -07001#!/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.
13set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
14source "${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 ---
21BINARY="$1"
22SOURCE="$2"
23HALIDE="$(rlocation halide_k8)"
24SYSROOT="$(rlocation amd64_debian_sysroot)"
25ZLIB1G_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)"
26ZLIB1G_DEV="$(mktemp -d)"
27LLVM_TOOLCHAIN="$(dirname "$(dirname "$(rlocation llvm_k8/bin/clang)")")"
28dpkg-deb -x "${ZLIB1G_DEV_AMD64_DEB}" "${ZLIB1G_DEV}"
29TARGET=x86_64-unknown-linux-gnu
30MULTIARCH=x86_64-linux-gnu
31export LD_LIBRARY_PATH="${SYSROOT}/usr/lib:${SYSROOT}/lib:${ZLIB1G_DEV}/usr/lib/${MULTIARCH}"
32"${LLVM_TOOLCHAIN}/bin/clang++" \
33 -fcolor-diagnostics \
34 -I"${HALIDE}/include" \
35 -nostdinc \
Austin Schuh0bd410a2023-11-05 12:38:12 -080036 -isystem"${SYSROOT}/usr/include/c++/12" \
37 -isystem"${SYSROOT}/usr/include/${MULTIARCH}/c++/12" \
Austin Schuhb02d2332023-09-05 22:18:35 -070038 -isystem"${SYSROOT}/usr/include/c++/7/backward" \
39 -isystem"${LLVM_TOOLCHAIN}/lib/clang/17/include" \
40 -isystem"${SYSROOT}/usr/include/${MULTIARCH}" \
41 -isystem"${SYSROOT}/usr/include" \
42 -isystem"${SYSROOT}/include" \
43 "--sysroot=${SYSROOT}" \
44 -resource-dir "${LLVM_TOOLCHAIN}/lib/clang/17" \
45 -target "${TARGET}" \
46 -fuse-ld=lld \
47 -L"${LLVM_TOOLCHAIN}/lib" \
48 -L"${SYSROOT}/usr/lib" \
49 -L"${SYSROOT}/usr/lib/gcc/${MULTIARCH}/7" \
50 -L"${ZLIB1G_DEV}/usr/lib/${MULTIARCH}" \
51 "${HALIDE}/lib/libHalide.a" \
52 -lstdc++ -lpthread -ldl -lm -lz \
53 -std=gnu++20 \
54 "${SOURCE}" \
55 "${HALIDE}/share/Halide/tools/GenGen.cpp" \
56 -ggdb3 \
57 -o "${BINARY}"