[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / libcxx / utils / ci / build-picolibc.sh
blob521c1bef9fc7ed557c391d3fdcab78a595fc3745
1 #!/usr/bin/env bash
2 # ===----------------------------------------------------------------------===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # ===----------------------------------------------------------------------===##
11 # This script builds picolibc (https://github.com/picolibc/picolibc) from
12 # source to facilitate building libc++ against it.
15 set -e
17 PROGNAME="$(basename "${0}")"
19 function error() { printf "error: %s\n" "$*" >&2; exit 1; }
21 function usage() {
22 cat <<EOF
23 Usage:
24 ${PROGNAME} [options]
26 [-h|--help] Display this help and exit.
28 --build-dir <DIR> Path to the directory to use for building.
30 --install-dir <DIR> Path to the directory to install the library to.
31 EOF
34 while [[ $# -gt 0 ]]; do
35 case ${1} in
36 -h|--help)
37 usage
38 exit 0
40 --build-dir)
41 build_dir="${2}"
42 shift; shift
44 --install-dir)
45 install_dir="${2}"
46 shift; shift
48 --target)
49 target="${2}"
50 shift; shift
53 error "Unknown argument '${1}'"
55 esac
56 done
58 for arg in build_dir install_dir target; do
59 if [ -z ${!arg+x} ]; then
60 error "Missing required argument '--${arg//_/-}'"
61 elif [ "${!arg}" == "" ]; then
62 error "Argument to --${arg//_/-} must not be empty"
64 done
67 echo "--- Downloading picolibc"
68 picolibc_source_dir="${build_dir}/picolibc-source"
69 picolibc_build_dir="${build_dir}/picolibc-build"
70 mkdir -p "${picolibc_source_dir}"
71 mkdir -p "${picolibc_build_dir}"
72 # Download a known good version of picolibc.
73 picolibc_commit="48fbc2009c6473293d03d5ec6f190565c6223a5c"
74 curl -L "https://github.com/picolibc/picolibc/archive/${picolibc_commit}.zip" --output "${picolibc_source_dir}/picolibc.zip"
75 unzip -q "${picolibc_source_dir}/picolibc.zip" -d "${picolibc_source_dir}"
76 mv "${picolibc_source_dir}/picolibc-${picolibc_commit}"/* "${picolibc_source_dir}"
77 rm -rf "${picolibc_source_dir}/picolibc-${picolibc_commit}"
79 cat <<EOF > "${picolibc_build_dir}/meson-cross-build.txt"
80 [binaries]
81 c = ['${CC:-cc}', '--target=${target}', '-mfloat-abi=soft', '-nostdlib']
82 ar = 'llvm-ar'
83 as = 'llvm-as'
84 ld = 'lld'
85 strip = 'llvm-strip'
86 [host_machine]
87 system = 'none'
88 cpu_family = 'arm'
89 cpu = 'arm'
90 endian = 'little'
91 [properties]
92 skip_sanity_check = true
93 EOF
95 venv_dir="${build_dir}/meson-venv"
96 python3 -m venv "${venv_dir}"
97 # Install the version of meson that was the latest at the time this script was written.
98 "${venv_dir}/bin/pip" install "meson==1.1.1"
100 "${venv_dir}/bin/meson" setup \
101 -Dincludedir=include -Dlibdir=lib -Dspecsdir=none -Dmultilib=false -Dpicoexit=false \
102 --prefix "${install_dir}" \
103 --cross-file "${picolibc_build_dir}/meson-cross-build.txt" \
104 "${picolibc_build_dir}" \
105 "${picolibc_source_dir}"
107 "${venv_dir}/bin/meson" install -C "${picolibc_build_dir}"