Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 1 | #!/bin/bash |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 2 | ############################################################################### |
| 3 | # |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 4 | # This build script is for running the QEMU build in a container |
| 5 | # |
| 6 | # It expects to be run in with the qemu source present in the directory called |
| 7 | # '$WORKSPACE/qemu', where WORKSPACE is an environment variable. |
| 8 | # |
| 9 | # In Jenkins configure the git SCM 'Additional Behaviours', 'check-out to a sub |
| 10 | # directory' called 'qemu'. |
| 11 | # |
| 12 | # When building locally set WORKSPACE to be the directory above the qemu |
| 13 | # checkout: |
| 14 | # git clone https://github.com/qemu/qemu |
| 15 | # WORKSPACE=$PWD/qemu ~/openbmc-build-scripts/qemu-build.sh |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 16 | # |
| 17 | ############################################################################### |
| 18 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 19 | # Script Variables: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 20 | # http_proxy The HTTP address of the proxy server to connect to. |
| 21 | # Default: "", proxy is not setup if this is not set |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 22 | # WORKSPACE Path of the workspace directory where the build will |
| 23 | # occur, and output artifacts will be produced. |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 24 | # DOCKER_REG: <optional, the URL of a docker registry to utilize |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 25 | # instead of our default (public.ecr.aws/ubuntu) |
| 26 | # (ex. docker.io) |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 27 | # |
| 28 | ############################################################################### |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 29 | # Trace bash processing |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 30 | #set -x |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 31 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 32 | # Script Variables: |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 33 | http_proxy=${http_proxy:-} |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 34 | |
| 35 | if [ -z ${WORKSPACE+x} ]; then |
| 36 | echo "Please set WORKSPACE variable" |
| 37 | exit 1 |
| 38 | fi |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 39 | |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 40 | docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"} |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 41 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 42 | # Docker Image Build Variables: |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 43 | img_name=qemu-build |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 44 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 45 | # Timestamp for job |
| 46 | echo "Build started, $(date)" |
| 47 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 48 | # Setup Proxy |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 49 | if [[ -n "${http_proxy}" ]]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 50 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 51 | fi |
| 52 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 53 | # Create the docker run script |
| 54 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 55 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 56 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 57 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 58 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 59 | #!/bin/bash |
| 60 | |
| 61 | set -x |
| 62 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame] | 63 | # Go into the build directory |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 64 | cd ${WORKSPACE}/qemu |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 65 | |
| 66 | gcc --version |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 67 | git submodule update --init dtc |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 68 | # disable anything that requires us to pull in X |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 69 | ./configure \ |
| 70 | --target-list=arm-softmmu \ |
| 71 | --disable-spice \ |
| 72 | --disable-docs \ |
| 73 | --disable-gtk \ |
| 74 | --disable-smartcard \ |
| 75 | --disable-usb-redir \ |
| 76 | --disable-libusb \ |
| 77 | --disable-sdl \ |
| 78 | --disable-gnutls \ |
| 79 | --disable-vte \ |
| 80 | --disable-vnc \ |
Andrew Geissler | 4a01582 | 2022-12-19 15:39:54 -0600 | [diff] [blame] | 81 | --disable-werror |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 82 | make clean |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 83 | make -j4 |
| 84 | |
| 85 | EOF_SCRIPT |
| 86 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 87 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 88 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 89 | # Configure docker build |
Andrew Jeffery | a311abc | 2021-01-15 14:22:34 +1030 | [diff] [blame] | 90 | |
| 91 | # !!! |
| 92 | # Keep the base docker image in sync with the image under which we run the |
| 93 | # resulting qemu binary. |
| 94 | # !!! |
| 95 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 96 | Dockerfile=$(cat << EOF |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 97 | FROM ${docker_reg}/ubuntu:jammy |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 98 | |
| 99 | ${PROXY} |
| 100 | |
| 101 | ENV DEBIAN_FRONTEND noninteractive |
| 102 | RUN apt-get update && apt-get install -yy --no-install-recommends \ |
| 103 | bison \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 104 | bzip2 \ |
Joel Stanley | a3f390e | 2019-01-16 00:24:25 +1100 | [diff] [blame] | 105 | ca-certificates \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 106 | flex \ |
| 107 | gcc \ |
| 108 | git \ |
| 109 | libc6-dev \ |
| 110 | libfdt-dev \ |
| 111 | libglib2.0-dev \ |
| 112 | libpixman-1-dev \ |
Andrew Geissler | 4a01582 | 2022-12-19 15:39:54 -0600 | [diff] [blame] | 113 | libslirp-dev \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 114 | make \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 115 | ninja-build \ |
Andrew Jeffery | decca83 | 2024-09-05 18:02:10 +0200 | [diff] [blame] | 116 | python3-tomli \ |
Andrew Geissler | 4b4c8ec | 2023-09-25 07:09:38 -0500 | [diff] [blame] | 117 | python3-venv \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 118 | python3-yaml \ |
| 119 | iputils-ping |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 120 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 121 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 122 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 123 | USER ${USER} |
| 124 | ENV HOME ${HOME} |
| 125 | EOF |
| 126 | ) |
| 127 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 128 | if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 129 | echo "Failed to build docker container." |
| 130 | exit 1 |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 131 | fi |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 132 | |
| 133 | docker run \ |
| 134 | --rm=true \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 135 | -e WORKSPACE="${WORKSPACE}" \ |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 136 | -w "${HOME}" \ |
| 137 | --user="${USER}" \ |
| 138 | -v "${HOME}":"${HOME}" \ |
| 139 | -t ${img_name} \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 140 | "${WORKSPACE}"/build.sh |