2 # ignore-tidy-linelength
7 binutils_version=2.25.1
9 triple=$arch-unknown-freebsd12
10 sysroot=/usr/local/$triple
15 echo ERROR: An error was encountered with the build.
20 bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
21 local ping_loop_pid=$!
22 "$@" &> /tmp/build.log
28 # First up, build binutils
31 curl https://ftp.gnu.org/gnu/binutils/binutils-${binutils_version}.tar.bz2 | tar xjf -
34 hide_output ../binutils-${binutils_version}/configure \
35 --target="$triple" --with-sysroot="$sysroot"
36 hide_output make -j"$(getconf _NPROCESSORS_ONLN)"
37 hide_output make install
41 # Next, download the FreeBSD libraries and header files
44 (x86_64) freebsd_arch=amd64 ;;
45 (i686) freebsd_arch=i386 ;;
52 # Try to unpack only the libraries the build needs, to save space.
53 for lib in c cxxrt gcc_s m thr util; do
54 files_to_extract=("${files_to_extract[@]}" "./lib/lib${lib}.*" "./usr/lib/lib${lib}.*")
56 for lib in c++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared procstat devstat kvm memstat; do
57 files_to_extract=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*")
60 # Originally downloaded from:
61 # URL=https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz
62 URL=https://ci-mirrors.rust-lang.org/rustc/2022-05-06-freebsd-${freebsd_version}-${freebsd_arch}-base.txz
63 curl "$URL" | tar xJf - -C "$sysroot" --wildcards "${files_to_extract[@]}"
65 # Clang can do cross-builds out of the box, if we give it the right
66 # flags. (The local binutils seem to work, but they set the ELF
67 # header "OS/ABI" (EI_OSABI) field to SysV rather than FreeBSD, so
68 # there might be other problems.)
70 # The --target option is last because the cross-build of LLVM uses
71 # --target without an OS version ("-freebsd" vs. "-freebsd12"). This
72 # makes Clang default to libstdc++ (which no longer exists), and also
73 # controls other features, like GNU-style symbol table hashing and
74 # anything predicated on the version number in the __FreeBSD__
76 for tool in clang clang++; do
77 tool_path=/usr/local/bin/${triple}-${tool}
78 cat > "$tool_path" <<EOF
80 exec $tool --sysroot=$sysroot --prefix=${sysroot}/bin "\$@" --target=$triple