]> git.proxmox.com Git - rustc.git/blame - src/ci/docker/scripts/freebsd-toolchain.sh
New upstream version 1.63.0+dfsg1
[rustc.git] / src / ci / docker / scripts / freebsd-toolchain.sh
CommitLineData
ff7c6d11 1#!/bin/bash
9fa01778
XL
2# ignore-tidy-linelength
3
ff7c6d11
XL
4set -eux
5
6arch=$1
7binutils_version=2.25.1
923072b8
FG
8freebsd_version=12.3
9triple=$arch-unknown-freebsd12
ff7c6d11
XL
10sysroot=/usr/local/$triple
11
12hide_output() {
13 set +x
14 local on_err="
15echo ERROR: An error was encountered with the build.
16cat /tmp/build.log
17exit 1
18"
19 trap "$on_err" ERR
20 bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
21 local ping_loop_pid=$!
29967ef6 22 "$@" &> /tmp/build.log
ff7c6d11
XL
23 trap - ERR
24 kill $ping_loop_pid
25 set -x
26}
27
28# First up, build binutils
29mkdir binutils
30cd binutils
31curl https://ftp.gnu.org/gnu/binutils/binutils-${binutils_version}.tar.bz2 | tar xjf -
32mkdir binutils-build
33cd binutils-build
34hide_output ../binutils-${binutils_version}/configure \
35 --target="$triple" --with-sysroot="$sysroot"
36hide_output make -j"$(getconf _NPROCESSORS_ONLN)"
37hide_output make install
38cd ../..
39rm -rf binutils
40
41# Next, download the FreeBSD libraries and header files
42mkdir -p "$sysroot"
43case $arch in
44 (x86_64) freebsd_arch=amd64 ;;
45 (i686) freebsd_arch=i386 ;;
46esac
47
48files_to_extract=(
49"./usr/include"
50"./usr/lib/*crt*.o"
51)
52# Try to unpack only the libraries the build needs, to save space.
53for lib in c cxxrt gcc_s m thr util; do
54 files_to_extract=("${files_to_extract[@]}" "./lib/lib${lib}.*" "./usr/lib/lib${lib}.*")
55done
a2a8927a 56for lib in c++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared procstat devstat kvm; do
ff7c6d11
XL
57 files_to_extract=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*")
58done
59
9fa01778 60# Originally downloaded from:
3dfed10e 61# URL=https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz
923072b8 62URL=https://ci-mirrors.rust-lang.org/rustc/2022-05-06-freebsd-${freebsd_version}-${freebsd_arch}-base.txz
ff7c6d11
XL
63curl "$URL" | tar xJf - -C "$sysroot" --wildcards "${files_to_extract[@]}"
64
ff7c6d11
XL
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.)
69#
70# The --target option is last because the cross-build of LLVM uses
923072b8 71# --target without an OS version ("-freebsd" vs. "-freebsd12"). This
ff7c6d11
XL
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__
75# preprocessor macro.
76for tool in clang clang++; do
77 tool_path=/usr/local/bin/${triple}-${tool}
78 cat > "$tool_path" <<EOF
79#!/bin/sh
80exec $tool --sysroot=$sysroot --prefix=${sysroot}/bin "\$@" --target=$triple
81EOF
82 chmod +x "$tool_path"
83done