blob: 8af4ee200efd93aa6b27d901d93ce53033bd64ad [file] [log] [blame]
Joel Stanley0b851182016-06-21 23:51:19 +09301#!/bin/bash
Alanny Lopezcce369b2017-06-20 09:52:50 -05002###############################################################################
3#
Joel Stanleyb23c4cc2018-10-31 18:47:25 +10304# 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
James Athappillya0cb5982025-09-29 22:18:25 -070015# WORKSPACE=$PWD ~/openbmc-build-scripts/qemu-build.sh
Alanny Lopezcce369b2017-06-20 09:52:50 -050016#
17###############################################################################
18#
Alanny Lopeze08e8702018-02-24 18:07:13 -060019# Script Variables:
Alanny Lopeze08e8702018-02-24 18:07:13 -060020# http_proxy The HTTP address of the proxy server to connect to.
21# Default: "", proxy is not setup if this is not set
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103022# WORKSPACE Path of the workspace directory where the build will
23# occur, and output artifacts will be produced.
Andrew Geisslerb80ea072024-10-07 15:43:34 -040024# DOCKER_REG: <optional, the URL of a docker registry to utilize
Andrew Geisslerfb45daa2024-10-09 12:26:56 -040025# instead of our default (public.ecr.aws/ubuntu)
26# (ex. docker.io)
Alanny Lopezcce369b2017-06-20 09:52:50 -050027#
28###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093029# Trace bash processing
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103030#set -x
Joel Stanley0b851182016-06-21 23:51:19 +093031
Alanny Lopez46967702018-02-25 00:29:14 -060032# Script Variables:
Joel Stanley0b851182016-06-21 23:51:19 +093033http_proxy=${http_proxy:-}
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103034
35if [ -z ${WORKSPACE+x} ]; then
36 echo "Please set WORKSPACE variable"
37 exit 1
38fi
Alanny Lopez46967702018-02-25 00:29:14 -060039
Andrew Geisslerfb45daa2024-10-09 12:26:56 -040040docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"}
Andrew Geisslerb80ea072024-10-07 15:43:34 -040041
Alanny Lopez46967702018-02-25 00:29:14 -060042# Docker Image Build Variables:
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103043img_name=qemu-build
Alanny Lopez46967702018-02-25 00:29:14 -060044
Joel Stanley0b851182016-06-21 23:51:19 +093045# Timestamp for job
46echo "Build started, $(date)"
47
Alanny Lopez41e2ada2017-06-15 13:54:43 -050048# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093049if [[ -n "${http_proxy}" ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -060050 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
Joel Stanley0b851182016-06-21 23:51:19 +093051fi
52
Joel Stanley0b851182016-06-21 23:51:19 +093053# Create the docker run script
54export PROXY_HOST=${http_proxy/#http*:\/\/}
55export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
56export PROXY_PORT=${http_proxy/#http*:\/\/*:}
57
Joel Stanley0b851182016-06-21 23:51:19 +093058cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
59#!/bin/bash
60
61set -x
62
Alanny Lopeza61e99a2017-06-27 14:20:48 -050063# Go into the build directory
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103064cd ${WORKSPACE}/qemu
Joel Stanley0b851182016-06-21 23:51:19 +093065
66gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050067git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093068# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050069./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 Geissler4a015822022-12-19 15:39:54 -060081 --disable-werror
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103082make clean
Joel Stanley0b851182016-06-21 23:51:19 +093083make -j4
84
85EOF_SCRIPT
86
Patrick Williams384d7412020-11-06 16:15:41 -060087chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0b851182016-06-21 23:51:19 +093088
Alanny Lopez41e2ada2017-06-15 13:54:43 -050089# Configure docker build
Andrew Jefferya311abc2021-01-15 14:22:34 +103090
91# !!!
92# Keep the base docker image in sync with the image under which we run the
93# resulting qemu binary.
94# !!!
95
Alanny Lopez41e2ada2017-06-15 13:54:43 -050096Dockerfile=$(cat << EOF
Andrew Geisslerb80ea072024-10-07 15:43:34 -040097FROM ${docker_reg}/ubuntu:jammy
Alanny Lopez41e2ada2017-06-15 13:54:43 -050098
99${PROXY}
100
101ENV DEBIAN_FRONTEND noninteractive
102RUN apt-get update && apt-get install -yy --no-install-recommends \
103 bison \
Andrew Jeffery41826802021-01-15 14:23:35 +1030104 bzip2 \
Joel Stanleya3f390e2019-01-16 00:24:25 +1100105 ca-certificates \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500106 flex \
107 gcc \
108 git \
109 libc6-dev \
110 libfdt-dev \
111 libglib2.0-dev \
112 libpixman-1-dev \
Andrew Geissler4a015822022-12-19 15:39:54 -0600113 libslirp-dev \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500114 make \
Andrew Jeffery41826802021-01-15 14:23:35 +1030115 ninja-build \
Andrew Jefferydecca832024-09-05 18:02:10 +0200116 python3-tomli \
Andrew Geissler4b4c8ec2023-09-25 07:09:38 -0500117 python3-venv \
Saqib Khan5158a322017-10-23 11:31:24 -0500118 python3-yaml \
119 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500120EOF
121)
122
Patrick Williams384d7412020-11-06 16:15:41 -0600123if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600124 echo "Failed to build docker container."
125 exit 1
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500126fi
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030127
128docker run \
James Athappillya0cb5982025-09-29 22:18:25 -0700129 --userns host \
130 --user "$UID:${GROUPS[0]}" \
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030131 --rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600132 -e WORKSPACE="${WORKSPACE}" \
James Athappillya0cb5982025-09-29 22:18:25 -0700133 -v "${WORKSPACE}":"${WORKSPACE}" \
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030134 -t ${img_name} \
Patrick Williams384d7412020-11-06 16:15:41 -0600135 "${WORKSPACE}"/build.sh