]> git.proxmox.com Git - rustc.git/blob - src/ci/docker/scripts/freebsd-toolchain.sh
New upstream version 1.41.1+dfsg1
[rustc.git] / src / ci / docker / scripts / freebsd-toolchain.sh
1 #!/bin/bash
2 # ignore-tidy-linelength
3
4 set -eux
5
6 arch=$1
7 binutils_version=2.25.1
8 freebsd_version=10.3
9 triple=$arch-unknown-freebsd10
10 sysroot=/usr/local/$triple
11
12 hide_output() {
13 set +x
14 local on_err="
15 echo ERROR: An error was encountered with the build.
16 cat /tmp/build.log
17 exit 1
18 "
19 trap "$on_err" ERR
20 bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
21 local ping_loop_pid=$!
22 $@ &> /tmp/build.log
23 trap - ERR
24 kill $ping_loop_pid
25 set -x
26 }
27
28 # First up, build binutils
29 mkdir binutils
30 cd binutils
31 curl https://ftp.gnu.org/gnu/binutils/binutils-${binutils_version}.tar.bz2 | tar xjf -
32 mkdir binutils-build
33 cd binutils-build
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
38 cd ../..
39 rm -rf binutils
40
41 # Next, download the FreeBSD libraries and header files
42 mkdir -p "$sysroot"
43 case $arch in
44 (x86_64) freebsd_arch=amd64 ;;
45 (i686) freebsd_arch=i386 ;;
46 esac
47
48 files_to_extract=(
49 "./usr/include"
50 "./usr/lib/*crt*.o"
51 )
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}.*")
55 done
56 for lib in c++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared; do
57 files_to_extract=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*")
58 done
59
60 # Originally downloaded from:
61 # https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz
62 URL=https://ci-mirrors.rust-lang.org/rustc/2019-04-04-freebsd-${freebsd_arch}-${freebsd_version}-RELEASE-base.txz
63 curl "$URL" | tar xJf - -C "$sysroot" --wildcards "${files_to_extract[@]}"
64
65 # Fix up absolute symlinks from the system image. This can be removed
66 # for FreeBSD 11. (If there's an easy way to make them relative
67 # symlinks instead, feel free to change this.)
68 set +x
69 find "$sysroot" -type l | while read symlink_path; do
70 symlink_target=$(readlink "$symlink_path")
71 case $symlink_target in
72 (/*)
73 echo "Fixing symlink ${symlink_path} -> ${sysroot}${symlink_target}" >&2
74 ln -nfs "${sysroot}${symlink_target}" "${symlink_path}" ;;
75 esac
76 done
77 set -x
78
79 # Clang can do cross-builds out of the box, if we give it the right
80 # flags. (The local binutils seem to work, but they set the ELF
81 # header "OS/ABI" (EI_OSABI) field to SysV rather than FreeBSD, so
82 # there might be other problems.)
83 #
84 # The --target option is last because the cross-build of LLVM uses
85 # --target without an OS version ("-freebsd" vs. "-freebsd10"). This
86 # makes Clang default to libstdc++ (which no longer exists), and also
87 # controls other features, like GNU-style symbol table hashing and
88 # anything predicated on the version number in the __FreeBSD__
89 # preprocessor macro.
90 for tool in clang clang++; do
91 tool_path=/usr/local/bin/${triple}-${tool}
92 cat > "$tool_path" <<EOF
93 #!/bin/sh
94 exec $tool --sysroot=$sysroot --prefix=${sysroot}/bin "\$@" --target=$triple
95 EOF
96 chmod +x "$tool_path"
97 done