blob: b0d269809061209937325aa5a0a6f481416984dd [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)")")"
Austin Schuh94dbdf32024-04-11 22:51:09 -070028LLVM_LIBS="$(rlocation clang_amd64_deps)/usr/lib/x86_64-linux-gnu/"
Austin Schuhb02d2332023-09-05 22:18:35 -070029dpkg-deb -x "${ZLIB1G_DEV_AMD64_DEB}" "${ZLIB1G_DEV}"
30TARGET=x86_64-unknown-linux-gnu
31MULTIARCH=x86_64-linux-gnu
Austin Schuh94dbdf32024-04-11 22:51:09 -070032export LD_LIBRARY_PATH="${SYSROOT}/usr/lib:${SYSROOT}/lib:${ZLIB1G_DEV}/usr/lib/${MULTIARCH}:${LLVM_LIBS}"
Austin Schuhb02d2332023-09-05 22:18:35 -070033"${LLVM_TOOLCHAIN}/bin/clang++" \
34 -fcolor-diagnostics \
35 -I"${HALIDE}/include" \
36 -nostdinc \
Austin Schuh0bd410a2023-11-05 12:38:12 -080037 -isystem"${SYSROOT}/usr/include/c++/12" \
38 -isystem"${SYSROOT}/usr/include/${MULTIARCH}/c++/12" \
Austin Schuhb02d2332023-09-05 22:18:35 -070039 -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}"